2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.schema.osgi.impl;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertSame;
13 import static org.mockito.ArgumentMatchers.any;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.mockito.Mockito.mock;
18 import org.apache.karaf.features.DeploymentListener;
19 import org.apache.karaf.features.FeaturesService;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Mock;
24 import org.mockito.junit.MockitoJUnitRunner;
25 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
26 import org.osgi.framework.BundleContext;
27 import org.osgi.framework.ServiceReference;
28 import org.osgi.service.component.ComponentFactory;
30 @RunWith(MockitoJUnitRunner.StrictStubs.class)
31 public class KarafFeaturesSupportTest {
33 private YangParserFactory parserFactory;
35 private ComponentFactory contextFactory;
37 private BundleContext bundleContext;
39 private ServiceReference<FeaturesService> mockRef;
41 private RegularYangModuleInfoRegistry infoRegistry;
44 public void before() {
45 infoRegistry = new RegularYangModuleInfoRegistry(contextFactory, parserFactory);
49 public void testWrapperWithKaraf() {
50 final FeaturesService mockFeatures = mock(FeaturesService.class);
51 doNothing().when(mockFeatures).registerListener(any(DeploymentListener.class));
52 doReturn(mockFeatures).when(bundleContext).getService(mockRef);
53 doReturn(mockRef).when(bundleContext).getServiceReference(FeaturesService.class);
55 final YangModuleInfoRegistry wrapped = KarafFeaturesSupport.wrap(bundleContext, infoRegistry);
56 assertThat(wrapped, instanceOf(KarafYangModuleInfoRegistry.class));
60 public void testWrapperWithoutKaraf() {
61 doReturn(null).when(bundleContext).getServiceReference(FeaturesService.class);
63 final YangModuleInfoRegistry wrapped = KarafFeaturesSupport.wrap(bundleContext, infoRegistry);
64 assertSame(infoRegistry, wrapped);