Merge "Cleanup RpcRoutingStrategy definition"
[controller.git] / opendaylight / netconf / netconf-impl / src / test / java / org / opendaylight / controller / netconf / impl / osgi / NetconfOperationServiceFactoryTrackerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.impl.osgi;
10
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;
19
20 import static org.junit.Assert.assertNotNull;
21 import static org.mockito.Matchers.any;
22 import static org.mockito.Mockito.*;
23
24 public class NetconfOperationServiceFactoryTrackerTest {
25
26     @Mock
27     private Filter filter;
28     @Mock
29     private BundleContext context;
30     @Mock
31     private NetconfOperationServiceFactoryListener listener;
32     @Mock
33     private NetconfOperationServiceFactory factory;
34     @Mock
35     private ServiceReference reference;
36
37     private NetconfOperationServiceFactoryTracker tracker;
38
39     @Before
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);
49     }
50
51     @Test
52     public void testNetconfOperationServiceFactoryTracker() throws Exception {
53         tracker.removedService(null, factory);
54         verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
55     }
56
57     @Test
58     public void testAddingService() throws Exception {
59         assertNotNull(tracker.addingService(reference));
60         verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
61     }
62 }