Merge "BUG 2676 : Use custom client-dispatcher when configured"
[controller.git] / opendaylight / netconf / netconf-impl / src / test / java / org / opendaylight / controller / netconf / impl / osgi / NetconfOperationServiceFactoryTrackerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.netconf.impl.osgi;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.anyString;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.controller.netconf.api.util.NetconfConstants;
24 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
25 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener;
26 import org.osgi.framework.BundleContext;
27 import org.osgi.framework.Filter;
28 import org.osgi.framework.ServiceReference;
29
30 public class NetconfOperationServiceFactoryTrackerTest {
31
32     @Mock
33     private Filter filter;
34     @Mock
35     private BundleContext context;
36     @Mock
37     private NetconfOperationServiceFactoryListener listener;
38     @Mock
39     private NetconfOperationServiceFactory factory;
40     @Mock
41     private ServiceReference<NetconfOperationServiceFactory> reference;
42
43     private NetconfOperationServiceFactoryTracker tracker;
44
45     @Before
46     public void setUp() throws Exception {
47         MockitoAnnotations.initMocks(this);
48         doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
49         doReturn(filter).when(context).createFilter(anyString());
50         doReturn("").when(reference).toString();
51         doReturn(NetconfConstants.CONFIG_NETCONF_CONNECTOR).when(reference).getProperty(NetconfConstants.SERVICE_NAME);
52         doReturn(factory).when(context).getService(any(ServiceReference.class));
53         doReturn("").when(factory).toString();
54         doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
55         tracker = new NetconfOperationServiceFactoryTracker(context, listener);
56     }
57
58     @Test
59     public void testNetconfOperationServiceFactoryTracker() throws Exception {
60         tracker.removedService(null, factory);
61         verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
62     }
63
64     @Test
65     public void testAddingService() throws Exception {
66         assertNotNull(tracker.addingService(reference));
67         verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
68     }
69 }