Bug-915: Adding static document generation.
[controller.git] / opendaylight / netconf / netconf-impl / src / test / java / org / opendaylight / controller / netconf / impl / osgi / NetconfImplActivatorTest.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 java.util.Arrays;
12 import java.util.Dictionary;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mock;
16 import org.mockito.MockitoAnnotations;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.Filter;
19 import org.osgi.framework.ServiceListener;
20 import org.osgi.framework.ServiceReference;
21 import org.osgi.framework.ServiceRegistration;
22
23 import static org.mockito.Matchers.any;
24 import static org.mockito.Mockito.anyString;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29
30 public class NetconfImplActivatorTest {
31
32     @Mock
33     private BundleContext bundle;
34     @Mock
35     private Filter filter;
36     @Mock
37     private ServiceReference<?> reference;
38     @Mock
39     private ServiceRegistration<?> registration;
40
41     @Before
42     public void setUp() throws Exception {
43         MockitoAnnotations.initMocks(this);
44         doReturn(filter).when(bundle).createFilter(anyString());
45         doNothing().when(bundle).addServiceListener(any(ServiceListener.class), anyString());
46
47         ServiceReference<?>[] refs = new ServiceReference[0];
48         doReturn(refs).when(bundle).getServiceReferences(anyString(), anyString());
49         doReturn(Arrays.asList(refs)).when(bundle).getServiceReferences(any(Class.class), anyString());
50         doReturn("").when(bundle).getProperty(anyString());
51         doReturn(registration).when(bundle).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class));
52         doNothing().when(registration).unregister();
53         doNothing().when(bundle).removeServiceListener(any(ServiceListener.class));
54     }
55
56     @Test
57     public void testStart() throws Exception {
58         NetconfImplActivator activator = new NetconfImplActivator();
59         activator.start(bundle);
60         verify(bundle, times(2)).registerService(any(Class.class), any(NetconfOperationServiceFactoryListenerImpl.class), any(Dictionary.class));
61         activator.stop(bundle);
62     }
63 }