Rework binding component instantiation
[mdsal.git] / dom / mdsal-dom-schema-osgi / src / test / java / org / opendaylight / mdsal / dom / schema / osgi / impl / OSGiModelRuntimeTest.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 package org.opendaylight.mdsal.dom.schema.osgi.impl;
9
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verifyNoMoreInteractions;
14
15 import org.junit.After;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
22 import org.osgi.framework.Bundle;
23 import org.osgi.framework.BundleContext;
24 import org.osgi.service.component.ComponentFactory;
25
26 @RunWith(MockitoJUnitRunner.StrictStubs.class)
27 public class OSGiModelRuntimeTest {
28     @Mock
29     private YangParserFactory parserFactory;
30     @Mock
31     private ComponentFactory contextFactory;
32     @Mock
33     private BundleContext bundleContext;
34
35     private OSGiModelRuntime target;
36
37     @Before
38     public void before() {
39         target = new OSGiModelRuntime();
40         target.parserFactory = parserFactory;
41         target.contextFactory = contextFactory;
42     }
43
44     @After
45     public void after() {
46         verifyNoMoreInteractions(parserFactory);
47         verifyNoMoreInteractions(contextFactory);
48         verifyNoMoreInteractions(bundleContext);
49     }
50
51     @Test
52     public void testActivate() {
53         doReturn(new Bundle[0]).when(bundleContext).getBundles();
54         doNothing().when(bundleContext).addBundleListener(any());
55         target.activate(bundleContext);
56     }
57
58     @Test
59     public void testDeactivate() {
60         testActivate();
61         doNothing().when(bundleContext).removeBundleListener(any());
62         target.deactivate();
63     }
64 }