00214f6ba7b54b1d6acb58b28816ccd7c9bb4daf
[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.Test;
19 import org.mockito.Mockito;
20 import org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider;
21 import org.opendaylight.controller.config.manager.impl.osgi.mapping.RefreshingSCPModuleInfoRegistry;
22 import org.opendaylight.yangtools.concepts.ObjectRegistration;
23 import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
24 import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
25 import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
26 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
28 import org.osgi.framework.BundleContext;
29 import org.osgi.framework.ServiceRegistration;
30
31 public class RefreshingSCPModuleInfoRegistryTest {
32     @Test
33     public void testConstructor() throws Exception {
34         ModuleInfoRegistry reg = mock(ModuleInfoRegistry.class);
35         SchemaContextProvider prov = mock(SchemaContextProvider.class);
36         doReturn("string").when(prov).toString();
37         BundleContext ctxt = mock(BundleContext.class);
38         ServiceRegistration<?> servReg = mock(ServiceRegistration.class);
39         doReturn(servReg).when(ctxt).registerService(any(Class.class), any(SchemaContextProvider.class), any(Dictionary.class));
40         doReturn(servReg).when(ctxt).registerService(Mockito.anyString(), any(Object.class), any(Dictionary.class));
41         doNothing().when(servReg).setProperties(any(Dictionary.class));
42
43         final ClassLoadingStrategy classLoadingStrat = mock(ClassLoadingStrategy.class);
44         final BindingContextProvider codecRegistryProvider = mock(BindingContextProvider.class);
45         doNothing().when(codecRegistryProvider).update(classLoadingStrat, prov);
46         final BindingRuntimeContext bindingRuntimeContext = mock(BindingRuntimeContext.class);
47         doReturn("B-runtime-context").when(bindingRuntimeContext).toString();
48         doReturn(bindingRuntimeContext).when(codecRegistryProvider).getBindingContext();
49
50         RefreshingSCPModuleInfoRegistry scpreg = new RefreshingSCPModuleInfoRegistry(reg, prov, classLoadingStrat, codecRegistryProvider, ctxt);
51
52         doNothing().when(servReg).unregister();
53
54         YangModuleInfo modInfo = mock(YangModuleInfo.class);
55         doReturn("").when(modInfo).toString();
56         ObjectRegistration<YangModuleInfo> ymi = mock(ObjectRegistration.class);
57         doReturn(ymi).when(reg).registerModuleInfo(modInfo);
58
59         scpreg.registerModuleInfo(modInfo);
60
61         verify(codecRegistryProvider).update(classLoadingStrat, prov);
62
63         scpreg.close();
64
65         Mockito.verify(servReg, Mockito.times(1)).setProperties(any(Dictionary.class));
66         Mockito.verify(servReg, Mockito.times(1)).unregister();
67     }
68 }

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