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 static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.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;
41 public void setUp() throws Exception {
42 MockitoAnnotations.initMocks(this);
43 doReturn(filter).when(bundle).createFilter(anyString());
44 doNothing().when(bundle).addServiceListener(any(ServiceListener.class), anyString());
46 ServiceReference<?>[] refs = {};
47 doReturn(refs).when(bundle).getServiceReferences(anyString(), anyString());
48 doReturn(Arrays.asList(refs)).when(bundle).getServiceReferences(any(Class.class), anyString());
49 doReturn("").when(bundle).getProperty(anyString());
50 doReturn(registration).when(bundle).registerService(any(Class.class), any(AggregatedNetconfOperationServiceFactory.class), any(Dictionary.class));
51 doNothing().when(registration).unregister();
52 doNothing().when(bundle).removeServiceListener(any(ServiceListener.class));
56 public void testStart() throws Exception {
57 NetconfImplActivator activator = new NetconfImplActivator();
58 activator.start(bundle);
59 verify(bundle).registerService(any(Class.class), any(AggregatedNetconfOperationServiceFactory.class), any(Dictionary.class));
60 activator.stop(bundle);