assertNotNull("Module has not been created correctly.", messageBusAppImplModuleFactory.createModule("instanceName1", dependencyResolverMock, dynamicMBeanWithInstanceMock, bundleContextMock));
}
-}
+}
\ No newline at end of file
*/
package org.opendaylight.controller.config.yang.messagebus.app.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.JmxAttribute;
import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.MountPointService;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.controller.sal.core.api.Broker;
+import org.opendaylight.controller.sal.core.api.Provider;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.osgi.framework.BundleContext;
+import javax.management.ObjectName;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
public class MessageBusAppImplModuleTest {
MessageBusAppImplModule messageBusAppImplModule;
assertEquals("Set and/or get method/s don't work correctly.", bundleContext, messageBusAppImplModule.getBundleContext());
}
- //TODO: create MessageBusAppImplModule.createInstance test
-}
+ @Test
+ public void createInstanceTest() throws Exception{
+ org.opendaylight.controller.sal.binding.api.BindingAwareBroker bindingAwareBrokerMock = mock(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class);
+ Broker brokerMock = mock(Broker.class);
+ doReturn(brokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class));
+ doReturn(bindingAwareBrokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class));
+ messageBusAppImplModule.resolveDependencies();
+
+ BindingAwareBroker.ProviderContext providerContext = mock(BindingAwareBroker.ProviderContext.class);
+ doReturn(providerContext).when(bindingAwareBrokerMock).registerProvider(any(BindingAwareProvider.class));
+ Broker.ProviderSession providerSessionMock = mock(Broker.ProviderSession.class);
+ doReturn(providerSessionMock).when(brokerMock).registerProvider(any(Provider.class));
+ DataBroker dataBrokerMock = mock(DataBroker.class);
+ doReturn(dataBrokerMock).when(providerContext).getSALService(eq(DataBroker.class));
+ DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class);
+ doReturn(domNotificationPublishServiceMock).when(providerSessionMock).getService(DOMNotificationPublishService.class);
+ DOMMountPointService domMountPointServiceMock = mock(DOMMountPointService.class);
+ doReturn(domMountPointServiceMock).when(providerSessionMock).getService(DOMMountPointService.class);
+ MountPointService mountPointServiceMock = mock(MountPointService.class);
+ doReturn(mountPointServiceMock).when(providerContext).getSALService(eq(MountPointService.class));
+ RpcProviderRegistry rpcProviderRegistryMock = mock(RpcProviderRegistry.class);
+ doReturn(rpcProviderRegistryMock).when(providerContext).getSALService(eq(RpcProviderRegistry.class));
+
+ WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
+ doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
+ doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class), eq(true));
+
+ assertNotNull("EventSourceRegistryWrapper has not been created correctly.", messageBusAppImplModule.createInstance());
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.messagebus.app.impl;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.messagebus.spi.EventSource;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class EventSourceRegistrationImplTest {
+
+ EventSourceRegistrationImplLocal eventSourceRegistrationImplLocal;
+ EventSourceTopology eventSourceTopologyMock;
+
+ @BeforeClass
+ public static void initTestClass() throws IllegalAccessException, InstantiationException {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ EventSource eventSourceMock = mock(EventSource.class);
+ eventSourceTopologyMock = mock(EventSourceTopology.class);
+ eventSourceRegistrationImplLocal = new EventSourceRegistrationImplLocal(eventSourceMock, eventSourceTopologyMock);
+ }
+
+ @Test
+ public void removeRegistrationTest() {
+ eventSourceRegistrationImplLocal.removeRegistration();
+ verify(eventSourceTopologyMock, times(1)).unRegister(any(EventSource.class));
+ }
+
+
+ private class EventSourceRegistrationImplLocal extends EventSourceRegistrationImpl{
+
+ /**
+ * @param instance of EventSource that has been registered by {@link EventSourceRegistryImpl#registerEventSource(Node, org.opendaylight.controller.messagebus.spi.EventSource)}
+ * @param eventSourceTopology
+ */
+ public EventSourceRegistrationImplLocal(EventSource instance, EventSourceTopology eventSourceTopology) {
+ super(instance, eventSourceTopology);
+ }
+ }
+
+}
\ No newline at end of file
nodeIdMock = mock(NodeId.class);
doReturn(nodeIdMock).when(dataObjectMock).getId();
- doReturn("0").when(nodeIdMock).getValue();
+ doReturn("nodeIdPattern1").when(nodeIdMock).getValue();
}
@Test
verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class));
}
-}
+}
\ No newline at end of file
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
CreateTopicInput createTopicInputMock;
ListenerRegistration listenerRegistrationMock;
NodeKey nodeKey;
+ RpcRegistration<EventAggregatorService> aggregatorRpcReg;
@BeforeClass
public static void initTestClass() throws IllegalAccessException, InstantiationException {
}
private void constructorTestHelper(){
- RpcRegistration<EventAggregatorService> aggregatorRpcReg = mock(RpcRegistration.class);
+ aggregatorRpcReg = mock(RpcRegistration.class);
EventSourceService eventSourceService = mock(EventSourceService.class);
doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class), any(EventSourceTopology.class));
doReturn(eventSourceService).when(rpcProviderRegistryMock).getRpcService(EventSourceService.class);
doReturn(checkedFutureMock).when(writeTransactionMock).submit();
}
-//TODO: create test for createTopic
-// public void createTopicTest() throws Exception{
-// createTopicTestHelper();
-// assertNotNull("Topic has not been created correctly.", eventSourceTopology.createTopic(createTopicInputMock));
-// }
+ @Test
+ public void createTopicTest() throws Exception{
+ topicTestHelper();
+ assertNotNull("Topic has not been created correctly.", eventSourceTopology.createTopic(createTopicInputMock));
+ }
private void topicTestHelper() throws Exception{
constructorTestHelper();
assertNotNull("Instance has not been created correctly.", eventSourceTopology.destroyTopic(destroyTopicInput));
}
+ @Test
+ public void closeTest() throws Exception{
+ constructorTestHelper();
+ topicTestHelper();
+ Map<DataChangeListener, ListenerRegistration<DataChangeListener>> localMap = getTopicListenerRegistrations();
+ DataChangeListener dataChangeListenerMock = mock(DataChangeListener.class);
+ ListenerRegistration<DataChangeListener> listenerListenerRegistrationMock = (ListenerRegistration<DataChangeListener>) mock(ListenerRegistration.class);
+ localMap.put(dataChangeListenerMock, listenerListenerRegistrationMock);
+ eventSourceTopology.close();
+ verify(aggregatorRpcReg, times(1)).close();
+ verify(listenerListenerRegistrationMock, times(1)).close();
+ }
+
@Test
public void registerTest() throws Exception {
topicTestHelper();
verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class));
}
-}
+ @Test
+ public void unregisterTest() throws Exception {
+ topicTestHelper();
+ EventSource eventSourceMock = mock(EventSource.class);
+ NodeId nodeId = new NodeId("nodeIdValue1");
+ nodeKey = new NodeKey(nodeId);
+ Map<NodeKey, BindingAwareBroker.RoutedRpcRegistration<EventSourceService>> localMap = getRoutedRpcRegistrations();
+ NodeKey nodeKeyMock = mock(NodeKey.class);
+ doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey();
+ BindingAwareBroker.RoutedRpcRegistration<EventSourceService> routedRpcRegistrationMock = (BindingAwareBroker.RoutedRpcRegistration<EventSourceService>) mock(BindingAwareBroker.RoutedRpcRegistration.class);
+ localMap.put(nodeKeyMock, routedRpcRegistrationMock);
+ eventSourceTopology.unRegister(eventSourceMock);
+ verify(routedRpcRegistrationMock, times(1)).close();
+ }
+
+ @Test
+ public void registerEventSourceTest() throws Exception {
+ topicTestHelper();
+ Node nodeMock = mock(Node.class);
+ EventSource eventSourceMock = mock(EventSource.class);
+ NodeId nodeId = new NodeId("nodeIdValue1");
+ nodeKey = new NodeKey(nodeId);
+ doReturn(nodeKey).when(nodeMock).getKey();
+ doReturn(nodeKey).when(eventSourceMock).getSourceNodeKey();
+ BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class);
+ doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock).addRoutedRpcImplementation(EventSourceService.class, eventSourceMock);
+ doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class));
+ assertNotNull("Return value has not been created correctly.", eventSourceTopology.registerEventSource(eventSourceMock));
+ }
+
+ private Map getTopicListenerRegistrations() throws Exception{
+ Field nesField = EventSourceTopology.class.getDeclaredField("topicListenerRegistrations");
+ nesField.setAccessible(true);
+ return (Map) nesField.get(eventSourceTopology);
+ }
+
+ private Map getRoutedRpcRegistrations() throws Exception{
+ Field nesField = EventSourceTopology.class.getDeclaredField("routedRpcRegistrations");
+ nesField.setAccessible(true);
+ return (Map) nesField.get(eventSourceTopology);
+ }
+
+}
\ No newline at end of file
netconfEventSourceManager =
NetconfEventSourceManager.create(dataBrokerMock,
- domNotificationPublishServiceMock,
- domMountPointServiceMock,
- mountPointServiceMock,
- eventSourceRegistry,
- namespaceToStreamList);
+ domNotificationPublishServiceMock,
+ domMountPointServiceMock,
+ mountPointServiceMock,
+ eventSourceRegistry,
+ namespaceToStreamList);
}
@Test
Map<InstanceIdentifier, DataObject> mapUpdate = new HashMap<>();
InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class);
Node dataObjectMock = mock(Node.class);
+
if(create){
mapCreate.put(instanceIdentifierMock, dataObjectMock);
}
if(update){
mapUpdate.put(instanceIdentifierMock, dataObjectMock);
}
+
doReturn(mapCreate).when(asyncDataChangeEventMock).getCreatedData();
doReturn(mapUpdate).when(asyncDataChangeEventMock).getUpdatedData();
NetconfNode netconfNodeMock = mock(NetconfNode.class);
doReturn(esrMock).when(eventSourceRegistry).registerEventSource(any(EventSource.class));
}
-}
+}
\ No newline at end of file
*/
package org.opendaylight.controller.messagebus.app.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.lang.reflect.Field;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.BindingService;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
public class NetconfEventSourceTest {
NetconfEventSource netconfEventSource;
DOMMountPoint domMountPointMock;
JoinTopicInput joinTopicInputMock;
- AsyncDataChangeEvent asyncDataChangeEventMock;
- Node dataObjectMock;
@Before
public void setUp() throws Exception {
Map<String, String> streamMap = new HashMap<>();
- streamMap.put("string1", "string2");
+ streamMap.put("uriStr1", "string2");
domMountPointMock = mock(DOMMountPoint.class);
DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class);
MountPoint mountPointMock = mock(MountPoint.class);
doReturn(rpcConsumerRegistryMock).when(onlyOptionalMock).get();
doReturn(notificationsServiceMock).when(rpcConsumerRegistryMock).getRpcService(NotificationsService.class);
org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node node
- = mock(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class);
+ = mock(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class);
org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId nodeId
- = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId("NodeId1");
+ = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId("NodeId1");
doReturn(nodeId).when(node).getNodeId();
netconfEventSource = new NetconfEventSource(node, streamMap, domMountPointMock, domNotificationPublishServiceMock, mountPointMock);
}
doReturn(topicId).when(joinTopicInputMock).getTopicId();
NotificationPattern notificationPatternMock = mock(NotificationPattern.class);
doReturn(notificationPatternMock).when(joinTopicInputMock).getNotificationPattern();
- doReturn("regexString1").when(notificationPatternMock).getValue();
+ doReturn("uriStr1").when(notificationPatternMock).getValue();
SchemaContext schemaContextMock = mock(SchemaContext.class);
doReturn(schemaContextMock).when(domMountPointMock).getSchemaContext();
doReturn(domNotificationServiceMock).when(domNotificationServiceOptionalMock).get();
ListenerRegistration listenerRegistrationMock = mock(ListenerRegistration.class);
doReturn(listenerRegistrationMock).when(domNotificationServiceMock).registerNotificationListener(any(NetconfEventSource.class), any(List.class));
+
+ Optional<DOMService> optionalMock = (Optional<DOMService>) mock(Optional.class);
+ doReturn(optionalMock).when(domMountPointMock).getService(DOMRpcService.class);
+ DOMRpcService domRpcServiceMock = mock(DOMRpcService.class);
+ doReturn(domRpcServiceMock).when(optionalMock).get();
+ CheckedFuture checkedFutureMock = mock(CheckedFuture.class);
+ doReturn(checkedFutureMock).when(domRpcServiceMock).invokeRpc(any(SchemaPath.class), any(ContainerNode.class));
}
//TODO: create Test for NetConfEventSource#onNotification
return (Set) nesField.get(netconfEventSource);
}
-}
+}
\ No newline at end of file
String bodyString = "TopicDOMNotification [body=" + containerNodeBodyMockToString + "]";
assertEquals("String has not been created correctly.", bodyString, topicDOMNotification.toString());
}
-}
+}
\ No newline at end of file