Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / util / OsgiRegistrationUtilTest.java
1 /*
2  * Copyright (c) 2013, 2017 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.config.manager.impl.util;
10
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
15
16 import org.junit.Test;
17 import org.mockito.InOrder;
18 import org.mockito.Mockito;
19 import org.osgi.framework.BundleContext;
20 import org.osgi.framework.ServiceRegistration;
21 import org.osgi.util.tracker.BundleTracker;
22 import org.osgi.util.tracker.ServiceTracker;
23
24 public class OsgiRegistrationUtilTest {
25
26     @Test
27     public void testRegisterService() throws Exception {
28         final BundleContext bundleContext = mock(BundleContext.class);
29         ServiceRegistration<?> registration = mockServiceRegistration();
30         doReturn(registration).when(bundleContext).registerService(String.class, "string", null);
31         ServiceRegistration<?> registration2 = mockServiceRegistration();
32         doReturn(registration2).when(bundleContext).registerService(Object.class, "string", null);
33
34         AutoCloseable aggregatedRegister = OsgiRegistrationUtil.registerService(bundleContext, "string", String.class,
35                 Object.class);
36         aggregatedRegister.close();
37
38         InOrder inOrder = Mockito.inOrder(registration, registration2);
39         inOrder.verify(registration2).unregister();
40         inOrder.verify(registration).unregister();
41     }
42
43     @Test
44     public void testWrap() throws Exception {
45         final ServiceRegistration<?> serviceReg = mockServiceRegistration();
46         OsgiRegistrationUtil.wrap(serviceReg).close();
47         verify(serviceReg).unregister();
48
49         final BundleTracker<?> tracker = mock(BundleTracker.class);
50         doNothing().when(tracker).close();
51         OsgiRegistrationUtil.wrap(tracker).close();
52         verify(tracker).close();
53
54         final ServiceTracker<?, ?> sTracker = mock(ServiceTracker.class);
55         doNothing().when(sTracker).close();
56         OsgiRegistrationUtil.wrap(sTracker).close();
57         verify(sTracker).close();
58     }
59
60     private static ServiceRegistration<?> mockServiceRegistration() {
61         ServiceRegistration<?> mock = mock(ServiceRegistration.class);
62         doNothing().when(mock).unregister();
63         return mock;
64     }
65
66     @Test
67     public void testAggregate() throws Exception {
68     }
69 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.