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.impl.osgi;
11 import java.util.Arrays;
12 import java.util.Dictionary;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mock;
16 import org.mockito.MockitoAnnotations;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.Filter;
19 import org.osgi.framework.ServiceListener;
20 import org.osgi.framework.ServiceReference;
21 import org.osgi.framework.ServiceRegistration;
23 import static org.mockito.Matchers.any;
24 import static org.mockito.Mockito.anyString;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
30 public class NetconfImplActivatorTest {
33 private BundleContext bundle;
35 private Filter filter;
37 private ServiceReference<?> reference;
39 private ServiceRegistration<?> registration;
42 public void setUp() throws Exception {
43 MockitoAnnotations.initMocks(this);
44 doReturn(filter).when(bundle).createFilter(anyString());
45 doNothing().when(bundle).addServiceListener(any(ServiceListener.class), anyString());
47 ServiceReference<?>[] refs = new ServiceReference[0];
48 doReturn(refs).when(bundle).getServiceReferences(anyString(), anyString());
49 doReturn(Arrays.asList(refs)).when(bundle).getServiceReferences(any(Class.class), anyString());
50 doReturn("").when(bundle).getProperty(anyString());
51 doReturn(registration).when(bundle).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class));
52 doNothing().when(registration).unregister();
53 doNothing().when(bundle).removeServiceListener(any(ServiceListener.class));
57 public void testStart() throws Exception {
58 NetconfImplActivator activator = new NetconfImplActivator();
59 activator.start(bundle);
60 verify(bundle, times(2)).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class));
61 activator.stop(bundle);