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 static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.anyString;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
18 import java.util.Arrays;
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;
28 public class NetconfMonitoringActivatorTest {
31 BundleContext context;
36 public void setUp() throws Exception {
37 MockitoAnnotations.initMocks(this);
38 doReturn(filter).when(context).createFilter(anyString());
39 doNothing().when(context).addServiceListener(any(ServiceListener.class), anyString());
40 ServiceReference<?>[] refs = new ServiceReference[2];
41 doReturn(Arrays.asList(refs)).when(context).getServiceReferences(any(Class.class), anyString());
42 doReturn(refs).when(context).getServiceReferences(anyString(), anyString());
43 doNothing().when(context).removeServiceListener(any(ServiceListener.class));
47 public void testNetconfMonitoringActivator() throws Exception {
48 NetconfMonitoringActivator activator = new NetconfMonitoringActivator();
49 activator.start(context);
50 verify(context, times(1)).addServiceListener(any(ServiceListener.class), anyString());
52 activator.stop(context);
53 verify(context, times(1)).removeServiceListener(any(ServiceListener.class));