Merge "BUG 1839 - HTTP delete of non existing data"
[controller.git] / opendaylight / netconf / netconf-monitoring / src / test / java / org / opendaylight / controller / netconf / monitoring / osgi / NetconfMonitoringServiceTrackerTest.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 java.util.Hashtable;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.mockito.Mock;
15 import org.mockito.MockitoAnnotations;
16 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
17 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
18 import org.osgi.framework.BundleContext;
19 import org.osgi.framework.Filter;
20 import org.osgi.framework.ServiceReference;
21 import org.osgi.framework.ServiceRegistration;
22
23 import static org.mockito.Matchers.any;
24 import static org.mockito.Matchers.anyCollection;
25 import static org.mockito.Mockito.*;
26
27 public class NetconfMonitoringServiceTrackerTest {
28
29     @Mock
30     private ServiceReference reference;
31     @Mock
32     private BundleContext context;
33     @Mock
34     private ServiceRegistration serviceRegistration;
35     @Mock
36     private Filter filter;
37     @Mock
38     private NetconfMonitoringService monitoringService;
39
40     @Before
41     public void setUp() throws Exception {
42         MockitoAnnotations.initMocks(this);
43         doReturn(serviceRegistration).when(context).registerService(any(Class.class), any(NetconfOperationServiceFactory.class), any(Hashtable.class));
44         doNothing().when(serviceRegistration).unregister();
45         doReturn(filter).when(context).createFilter(anyString());
46         doReturn("").when(reference).toString();
47         doReturn(monitoringService).when(context).getService(any(ServiceReference.class));
48     }
49
50     @Test
51     public void testAddingService() throws Exception {
52         NetconfMonitoringServiceTracker tracker = new NetconfMonitoringServiceTracker(context);
53         tracker.addingService(reference);
54         verify(context, times(1)).registerService(any(Class.class), any(NetconfOperationServiceFactory.class), any(Hashtable.class));
55         tracker.removedService(reference, null);
56         verify(serviceRegistration, times(1)).unregister();
57     }
58 }