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.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.anyString;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.mockito.Mockito.times;
17 import static org.mockito.Mockito.verify;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.controller.netconf.api.util.NetconfConstants;
24 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
25 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener;
26 import org.osgi.framework.BundleContext;
27 import org.osgi.framework.Filter;
28 import org.osgi.framework.ServiceReference;
30 public class NetconfOperationServiceFactoryTrackerTest {
33 private Filter filter;
35 private BundleContext context;
37 private NetconfOperationServiceFactoryListener listener;
39 private NetconfOperationServiceFactory factory;
41 private ServiceReference<NetconfOperationServiceFactory> reference;
43 private NetconfOperationServiceFactoryTracker tracker;
46 public void setUp() throws Exception {
47 MockitoAnnotations.initMocks(this);
48 doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
49 doReturn(filter).when(context).createFilter(anyString());
50 doReturn("").when(reference).toString();
51 doReturn(NetconfConstants.CONFIG_NETCONF_CONNECTOR).when(reference).getProperty(NetconfConstants.SERVICE_NAME);
52 doReturn(factory).when(context).getService(any(ServiceReference.class));
53 doReturn("").when(factory).toString();
54 doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
55 tracker = new NetconfOperationServiceFactoryTracker(context, listener);
59 public void testNetconfOperationServiceFactoryTracker() throws Exception {
60 tracker.removedService(null, factory);
61 verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
65 public void testAddingService() throws Exception {
66 assertNotNull(tracker.addingService(reference));
67 verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));