Merge "Fix for Bug 2727 - Upgrade Akka from 2.3.4 to 2.3.9"
[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 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;
18
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.osgi.framework.BundleContext;
26 import org.osgi.framework.Filter;
27 import org.osgi.framework.ServiceReference;
28
29 public class NetconfOperationServiceFactoryTrackerTest {
30
31     @Mock
32     private Filter filter;
33     @Mock
34     private BundleContext context;
35     @Mock
36     private NetconfOperationServiceFactoryListener listener;
37     @Mock
38     private NetconfOperationServiceFactory factory;
39     @Mock
40     private ServiceReference<NetconfOperationServiceFactory> reference;
41
42     private NetconfOperationServiceFactoryTracker tracker;
43
44     @Before
45     public void setUp() throws Exception {
46         MockitoAnnotations.initMocks(this);
47         doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
48         doReturn(filter).when(context).createFilter(anyString());
49         doReturn("").when(reference).toString();
50         doReturn(NetconfConstants.CONFIG_NETCONF_CONNECTOR).when(reference).getProperty(NetconfConstants.SERVICE_NAME);
51         doReturn(factory).when(context).getService(any(ServiceReference.class));
52         doReturn("").when(factory).toString();
53         doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
54         tracker = new NetconfOperationServiceFactoryTracker(context, listener);
55     }
56
57     @Test
58     public void testNetconfOperationServiceFactoryTracker() throws Exception {
59         tracker.removedService(null, factory);
60         verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
61     }
62
63     @Test
64     public void testAddingService() throws Exception {
65         assertNotNull(tracker.addingService(reference));
66         verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class));
67     }
68 }