Merge "BUG-2953: do not use a complete InMemoryDataStore"
[controller.git] / opendaylight / md-sal / messagebus-impl / src / test / java / org / opendaylight / controller / config / yang / messagebus / app / impl / MessageBusAppImplModuleTest.java
1 /*
2  * Copyright (c) 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 package org.opendaylight.controller.config.yang.messagebus.app.impl;
9
10 import org.junit.Before;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13 import org.opendaylight.controller.config.api.DependencyResolver;
14 import org.opendaylight.controller.config.api.JmxAttribute;
15 import org.opendaylight.controller.config.api.ModuleIdentifier;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
18 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
21 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
23 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
24 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
25 import org.opendaylight.controller.sal.core.api.Broker;
26 import org.opendaylight.controller.sal.core.api.Provider;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.osgi.framework.BundleContext;
30
31 import javax.management.ObjectName;
32
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNotNull;
35 import static org.mockito.Matchers.any;
36 import static org.mockito.Matchers.eq;
37 import static org.mockito.Mockito.doNothing;
38 import static org.mockito.Mockito.doReturn;
39 import static org.mockito.Mockito.mock;
40
41 public class MessageBusAppImplModuleTest {
42
43     MessageBusAppImplModule messageBusAppImplModule;
44     ModuleIdentifier moduleIdentifier;
45     DependencyResolver dependencyResolverMock;
46
47     @BeforeClass
48     public static void initTestClass() throws IllegalAccessException, InstantiationException {
49     }
50
51     @Before
52     public void setUp() throws Exception {
53         moduleIdentifier = new ModuleIdentifier("factoryName1", "instanceName1");
54         dependencyResolverMock = mock(DependencyResolver.class);
55         messageBusAppImplModule = new MessageBusAppImplModule(moduleIdentifier, dependencyResolverMock);
56     }
57
58     @Test
59     public void constructorTest() {
60         assertNotNull("Instance has not been created correctly.", messageBusAppImplModule);
61     }
62
63     @Test
64     public void constructorBTest() {
65         MessageBusAppImplModule messageBusAppImplModuleOld = mock(MessageBusAppImplModule.class);
66         java.lang.AutoCloseable oldInstanceAutocloseableMock = mock(AutoCloseable.class);
67         MessageBusAppImplModule messageBusAppImplModule = new MessageBusAppImplModule(moduleIdentifier, dependencyResolverMock, messageBusAppImplModuleOld, oldInstanceAutocloseableMock);
68         assertNotNull("Instance has not been created correctly.", messageBusAppImplModule);
69     }
70
71     @Test
72     public void setGetBundleContextTest() {
73         BundleContext bundleContext = mock(BundleContext.class);
74         messageBusAppImplModule.setBundleContext(bundleContext);
75         assertEquals("Set and/or get method/s don't work correctly.", bundleContext, messageBusAppImplModule.getBundleContext());
76     }
77
78     @Test
79     public void createInstanceTest() throws Exception{
80         org.opendaylight.controller.sal.binding.api.BindingAwareBroker bindingAwareBrokerMock = mock(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class);
81         Broker brokerMock = mock(Broker.class);
82         doReturn(brokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class));
83         doReturn(bindingAwareBrokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class));
84         messageBusAppImplModule.resolveDependencies();
85
86         BindingAwareBroker.ProviderContext providerContext = mock(BindingAwareBroker.ProviderContext.class);
87         doReturn(providerContext).when(bindingAwareBrokerMock).registerProvider(any(BindingAwareProvider.class));
88         Broker.ProviderSession providerSessionMock = mock(Broker.ProviderSession.class);
89         doReturn(providerSessionMock).when(brokerMock).registerProvider(any(Provider.class));
90         DataBroker dataBrokerMock = mock(DataBroker.class);
91         doReturn(dataBrokerMock).when(providerContext).getSALService(eq(DataBroker.class));
92         DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class);
93         doReturn(domNotificationPublishServiceMock).when(providerSessionMock).getService(DOMNotificationPublishService.class);
94         DOMMountPointService domMountPointServiceMock = mock(DOMMountPointService.class);
95         doReturn(domMountPointServiceMock).when(providerSessionMock).getService(DOMMountPointService.class);
96         MountPointService mountPointServiceMock = mock(MountPointService.class);
97         doReturn(mountPointServiceMock).when(providerContext).getSALService(eq(MountPointService.class));
98         RpcProviderRegistry rpcProviderRegistryMock = mock(RpcProviderRegistry.class);
99         doReturn(rpcProviderRegistryMock).when(providerContext).getSALService(eq(RpcProviderRegistry.class));
100
101         WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
102         doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
103         doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
104
105         assertNotNull("EventSourceRegistryWrapper has not been created correctly.", messageBusAppImplModule.createInstance());
106     }
107
108 }

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