Add KarafFeaturesSupportTest 23/88123/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Feb 2020 13:22:21 +0000 (14:22 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 28 Feb 2020 14:58:28 +0000 (14:58 +0000)
Improve test coverage a bit exercising KarafFeaturesSupport.

JIRA: MDSAL-235
Change-Id: I475e69566bce11c44ec8022b0d6bb1d451f45ff5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-schema-osgi/src/test/java/org/opendaylight/mdsal/dom/schema/osgi/impl/KarafFeaturesSupportTest.java [new file with mode: 0644]

diff --git a/dom/mdsal-dom-schema-osgi/src/test/java/org/opendaylight/mdsal/dom/schema/osgi/impl/KarafFeaturesSupportTest.java b/dom/mdsal-dom-schema-osgi/src/test/java/org/opendaylight/mdsal/dom/schema/osgi/impl/KarafFeaturesSupportTest.java
new file mode 100644 (file)
index 0000000..423fa2f
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.schema.osgi.impl;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import org.apache.karaf.features.DeploymentListener;
+import org.apache.karaf.features.FeaturesService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentFactory;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class KarafFeaturesSupportTest {
+    @Mock
+    private YangParserFactory parserFactory;
+    @Mock
+    private ComponentFactory contextFactory;
+    @Mock
+    private BundleContext bundleContext;
+    @Mock
+    private ServiceReference<FeaturesService> mockRef;
+
+    private RegularYangModuleInfoRegistry infoRegistry;
+
+    @Before
+    public void before() {
+        infoRegistry = new RegularYangModuleInfoRegistry(contextFactory, parserFactory);
+    }
+
+    @Test
+    public void testWrapperWithKaraf() {
+        final FeaturesService mockFeatures = mock(FeaturesService.class);
+        doNothing().when(mockFeatures).registerListener(any(DeploymentListener.class));
+        doReturn(mockFeatures).when(bundleContext).getService(mockRef);
+        doReturn(mockRef).when(bundleContext).getServiceReference(FeaturesService.class);
+
+        final YangModuleInfoRegistry wrapped = KarafFeaturesSupport.wrap(bundleContext, infoRegistry);
+        assertThat(wrapped, instanceOf(KarafYangModuleInfoRegistry.class));
+    }
+
+    @Test
+    public void testWrapperWithoutKaraf() {
+        doReturn(null).when(bundleContext).getServiceReference(FeaturesService.class);
+
+        final YangModuleInfoRegistry wrapped = KarafFeaturesSupport.wrap(bundleContext, infoRegistry);
+        assertSame(infoRegistry, wrapped);
+    }
+}