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.netconf.impl.osgi;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.anyString;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.verify;
17 import java.util.Arrays;
18 import java.util.Dictionary;
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 import org.osgi.framework.ServiceRegistration;
29 public class NetconfImplActivatorTest {
32 private BundleContext bundle;
34 private Filter filter;
36 private ServiceReference<?> reference;
38 private ServiceRegistration<?> registration;
40 private ServiceRegistration<?> monRegistration;
43 public void setUp() throws Exception {
44 MockitoAnnotations.initMocks(this);
45 doReturn(filter).when(bundle).createFilter(anyString());
46 doNothing().when(bundle).addServiceListener(any(ServiceListener.class), any());
48 ServiceReference<?>[] refs = {};
49 doReturn(refs).when(bundle).getServiceReferences(anyString(), any());
50 doReturn(Arrays.asList(refs)).when(bundle).getServiceReferences(any(Class.class), any());
51 doReturn("").when(bundle).getProperty(anyString());
52 doReturn(monRegistration).when(bundle).registerService(any(Class.class),
53 any(NetconfMonitoringServiceImpl.class), any(Dictionary.class));
54 doNothing().when(monRegistration).unregister();
55 doReturn(registration).when(bundle).registerService(any(Class.class),
56 any(AggregatedNetconfOperationServiceFactory.class), any(Dictionary.class));
57 doNothing().when(registration).unregister();
58 doNothing().when(bundle).removeServiceListener(any(ServiceListener.class));
62 public void testStart() throws Exception {
63 NetconfImplActivator activator = new NetconfImplActivator();
64 activator.start(bundle);
65 verify(bundle).registerService(any(Class.class), any(NetconfMonitoringServiceImpl.class),
66 any(Dictionary.class));
67 activator.stop(bundle);