62b81599db10ba7911872e0aeedb4e953cfd5f47
[netconf.git] / netconf / yanglib / src / test / java / org / opendaylight / yanglib / impl / YangLibRestAppTest.java
1 /*
2  * Copyright (c) 2016 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.yanglib.impl;
10
11 import static junit.framework.TestCase.assertTrue;
12 import static org.mockito.BDDMockito.given;
13 import static org.mockito.BDDMockito.then;
14 import static org.mockito.Matchers.any;
15 import static org.mockito.Matchers.eq;
16 import static org.mockito.Mockito.mock;
17 import static org.mockito.Mockito.times;
18
19 import java.util.Set;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.opendaylight.yanglib.api.YangLibRestAppService;
23 import org.osgi.framework.Bundle;
24 import org.osgi.framework.BundleContext;
25 import org.osgi.framework.FrameworkUtil;
26 import org.powermock.api.mockito.PowerMockito;
27 import org.powermock.core.classloader.annotations.PrepareForTest;
28 import org.powermock.modules.junit4.PowerMockRunner;
29
30 @RunWith(PowerMockRunner.class)
31 @PrepareForTest(FrameworkUtil.class)
32 public class YangLibRestAppTest {
33
34     @Test
35     public void testYangLibRestApp() {
36         PowerMockito.mockStatic(FrameworkUtil.class);
37
38         final BundleContext bundleContext = mock(BundleContext.class);
39         final Bundle bundle = mock(Bundle.class);
40
41         given(FrameworkUtil.getBundle(any())).willReturn(bundle);
42         given(bundle.getBundleContext()).willReturn(bundleContext);
43
44         final YangLibRestApp yangLibRestApp = new YangLibRestApp();
45         final Set singleton = yangLibRestApp.getSingletons();
46
47         assertTrue(singleton.contains(yangLibRestApp.getYangLibService()));
48
49         then(bundleContext).should(times(1))
50                 .registerService(eq(YangLibRestAppService.class.getName()), eq(yangLibRestApp), eq(null));
51     }
52 }