2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.netconf.monitoring.osgi;
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;
23 import static org.mockito.Matchers.any;
24 import static org.mockito.Matchers.anyCollection;
25 import static org.mockito.Mockito.*;
27 public class NetconfMonitoringServiceTrackerTest {
30 private ServiceReference reference;
32 private BundleContext context;
34 private ServiceRegistration serviceRegistration;
36 private Filter filter;
38 private NetconfMonitoringService monitoringService;
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));
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();