Merge "Netconf-cli compilable and included in project"
[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.mapping.api.NetconfOperationServiceFactory;
24 import org.osgi.framework.BundleContext;
25 import org.osgi.framework.Filter;
26 import org.osgi.framework.ServiceReference;
27
28 public class NetconfOperationServiceFactoryTrackerTest {
29
30     @Mock
31     private Filter filter;
32     @Mock
33     private BundleContext context;
34     @Mock
35     private NetconfOperationServiceFactoryListener listener;
36     @Mock
37     private NetconfOperationServiceFactory factory;
38     @Mock
39     private ServiceReference<NetconfOperationServiceFactory> reference;
40
41     private NetconfOperationServiceFactoryTracker tracker;
42
43     @Before
44     public void setUp() throws Exception {
45         MockitoAnnotations.initMocks(this);
46         doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
47         doReturn(filter).when(context).createFilter(anyString());
48         doReturn("").when(reference).toString();
49         doReturn(factory).when(context).getService(any(ServiceReference.class));
50         doReturn("").when(factory).toString();
51         doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
52         tracker = new NetconfOperationServiceFactoryTracker(context, listener);
53     }
54
55     @Test
56     public void testNetconfOperationServiceFactoryTracker() throws Exception {
57         tracker.removedService(null, factory);
58         verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
59     }
60
61     @Test
62     public void testAddingService() throws Exception {
63         assertNotNull(tracker.addingService(reference));
64         verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
65     }
66 }