X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fmessagebus-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmessagebus%2Fapp%2Fimpl%2FEventSourceTopologyTest.java;h=50ae4d9389cf143a8864584ae382e27d47893c56;hp=ced2e1f01b47ab2bdbfbc1b2c0de972b4f7a6578;hb=2727bea09c83646b6cbd2ef9672d0b7f6cf3b22f;hpb=4e594bb578f687fb24e242e90b918d91fb59c3ac diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java index ced2e1f01b..50ae4d9389 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java @@ -16,13 +16,16 @@ 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.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; @@ -57,6 +60,7 @@ public class EventSourceTopologyTest { CreateTopicInput createTopicInputMock; ListenerRegistration listenerRegistrationMock; NodeKey nodeKey; + RpcRegistration aggregatorRpcReg; @BeforeClass public static void initTestClass() throws IllegalAccessException, InstantiationException { @@ -76,7 +80,7 @@ public class EventSourceTopologyTest { } private void constructorTestHelper(){ - RpcRegistration 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); @@ -87,11 +91,11 @@ public class EventSourceTopologyTest { 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(); @@ -138,6 +142,19 @@ public class EventSourceTopologyTest { assertNotNull("Instance has not been created correctly.", eventSourceTopology.destroyTopic(destroyTopicInput)); } + @Test + public void closeTest() throws Exception{ + constructorTestHelper(); + topicTestHelper(); + Map> localMap = getTopicListenerRegistrations(); + DataChangeListener dataChangeListenerMock = mock(DataChangeListener.class); + ListenerRegistration listenerListenerRegistrationMock = (ListenerRegistration) 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(); @@ -154,4 +171,46 @@ public class EventSourceTopologyTest { 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> localMap = getRoutedRpcRegistrations(); + NodeKey nodeKeyMock = mock(NodeKey.class); + doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey(); + BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = (BindingAwareBroker.RoutedRpcRegistration) 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