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 org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.Mock;
14 import org.mockito.MockitoAnnotations;
15 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.Filter;
18 import org.osgi.framework.ServiceReference;
20 import static org.junit.Assert.assertNotNull;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Mockito.*;
24 public class NetconfOperationServiceFactoryTrackerTest {
27 private Filter filter;
29 private BundleContext context;
31 private NetconfOperationServiceFactoryListener listener;
33 private NetconfOperationServiceFactory factory;
35 private ServiceReference reference;
37 private NetconfOperationServiceFactoryTracker tracker;
40 public void setUp() throws Exception {
41 MockitoAnnotations.initMocks(this);
42 doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
43 doReturn(filter).when(context).createFilter(anyString());
44 doReturn("").when(reference).toString();
45 doReturn(factory).when(context).getService(any(ServiceReference.class));
46 doReturn("").when(factory).toString();
47 doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
48 tracker = new NetconfOperationServiceFactoryTracker(context, listener);
52 public void testNetconfOperationServiceFactoryTracker() throws Exception {
53 tracker.removedService(null, factory);
54 verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
58 public void testAddingService() throws Exception {
59 assertNotNull(tracker.addingService(reference));
60 verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));