BUG-4367: Use SchemaSourceProvider to retrieve sources for yang
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / osgi / RefreshingSCPModuleInfoRegistryTest.java
1 /*
2  * Copyright (c) 2014, 2015 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.osgi;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.verify;
16
17 import java.util.Dictionary;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider;
24 import org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry;
25 import org.opendaylight.yangtools.concepts.ObjectRegistration;
26 import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
27 import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
28 import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
29 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
30 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
31 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
32 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
33 import org.osgi.framework.BundleContext;
34 import org.osgi.framework.ServiceRegistration;
35
36 public class RefreshingSCPModuleInfoRegistryTest {
37
38     @Mock
39     SchemaSourceProvider<YangTextSchemaSource> sourceProvider;
40
41     @Before public void setUp() throws Exception {
42         MockitoAnnotations.initMocks(this);
43     }
44
45     @Test
46     public void testConstructor() throws Exception {
47         ModuleInfoRegistry reg = mock(ModuleInfoRegistry.class);
48         SchemaContextProvider prov = mock(SchemaContextProvider.class);
49         doReturn("string").when(prov).toString();
50         BundleContext ctxt = mock(BundleContext.class);
51         ServiceRegistration<?> servReg = mock(ServiceRegistration.class);
52         doReturn(servReg).when(ctxt).registerService(any(Class.class), any(SchemaContextProvider.class), any(Dictionary.class));
53         doReturn(servReg).when(ctxt).registerService(Mockito.anyString(), any(Object.class), any(Dictionary.class));
54         doNothing().when(servReg).setProperties(any(Dictionary.class));
55
56         final ClassLoadingStrategy classLoadingStrat = mock(ClassLoadingStrategy.class);
57         final BindingContextProvider codecRegistryProvider = mock(BindingContextProvider.class);
58         doNothing().when(codecRegistryProvider).update(classLoadingStrat, prov);
59         final BindingRuntimeContext bindingRuntimeContext = mock(BindingRuntimeContext.class);
60         doReturn("B-runtime-context").when(bindingRuntimeContext).toString();
61         doReturn(bindingRuntimeContext).when(codecRegistryProvider).getBindingContext();
62
63         RefreshingSCPModuleInfoRegistry scpreg = new RefreshingSCPModuleInfoRegistry(reg, prov, classLoadingStrat, sourceProvider, codecRegistryProvider, ctxt);
64
65         doNothing().when(servReg).unregister();
66
67         YangModuleInfo modInfo = mock(YangModuleInfo.class);
68         doReturn("").when(modInfo).toString();
69         ObjectRegistration<YangModuleInfo> ymi = mock(ObjectRegistration.class);
70         doReturn(ymi).when(reg).registerModuleInfo(modInfo);
71
72         scpreg.registerModuleInfo(modInfo);
73
74         verify(codecRegistryProvider).update(classLoadingStrat, prov);
75
76         scpreg.close();
77
78         Mockito.verify(servReg, Mockito.times(1)).setProperties(any(Dictionary.class));
79         Mockito.verify(servReg, Mockito.times(1)).unregister();
80     }
81 }

©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.