Merge "Fix improper cleanup of operational data in sal-netconf-connector's disconnect"
[controller.git] / opendaylight / netconf / netconf-monitoring / src / test / java / org / opendaylight / controller / netconf / monitoring / osgi / NetconfMonitoringActivatorTest.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.monitoring.osgi;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.anyString;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17
18 import java.util.Arrays;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.osgi.framework.BundleContext;
24 import org.osgi.framework.Filter;
25 import org.osgi.framework.ServiceListener;
26 import org.osgi.framework.ServiceReference;
27
28 public class NetconfMonitoringActivatorTest {
29
30     @Mock
31     BundleContext context;
32     @Mock
33     Filter filter;
34
35     @Before
36     public void setUp() throws Exception {
37         MockitoAnnotations.initMocks(this);
38         doReturn(filter).when(context).createFilter(anyString());
39         doNothing().when(context).addServiceListener(any(ServiceListener.class), anyString());
40         ServiceReference<?>[] refs = new ServiceReference[2];
41         doReturn(Arrays.asList(refs)).when(context).getServiceReferences(any(Class.class), anyString());
42         doReturn(refs).when(context).getServiceReferences(anyString(), anyString());
43         doNothing().when(context).removeServiceListener(any(ServiceListener.class));
44     }
45
46     @Test
47     public void testNetconfMonitoringActivator() throws Exception {
48         NetconfMonitoringActivator activator = new NetconfMonitoringActivator();
49         activator.start(context);
50         verify(context, times(1)).addServiceListener(any(ServiceListener.class), anyString());
51
52         activator.stop(context);
53         verify(context, times(1)).removeServiceListener(any(ServiceListener.class));
54     }
55 }