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=fda32a6adee1da1ccbd12a820bdc67867159c299;hp=ced2e1f01b47ab2bdbfbc1b2c0de972b4f7a6578;hb=f9814cf027886294b74fb6c8748f4a3e0a545e86;hpb=2d62916cb1f4b4045f4fc38fbd313f8339f9ac67 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..fda32a6ade 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,15 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; 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.DataTreeIdentifier; 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; @@ -32,9 +34,11 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistr import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicInput; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.DestroyTopicInput; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.DestroyTopicInputBuilder; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.EventAggregatorService; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; @@ -46,21 +50,15 @@ import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; - public class EventSourceTopologyTest { EventSourceTopology eventSourceTopology; DataBroker dataBrokerMock; RpcProviderRegistry rpcProviderRegistryMock; CreateTopicInput createTopicInputMock; - ListenerRegistration listenerRegistrationMock; + ListenerRegistration listenerRegistrationMock; NodeKey nodeKey; - - @BeforeClass - public static void initTestClass() throws IllegalAccessException, InstantiationException { - } + RpcRegistration aggregatorRpcReg; @Before public void setUp() throws Exception { @@ -75,25 +73,40 @@ public class EventSourceTopologyTest { assertNotNull("Instance has not been created correctly.", eventSourceTopology); } - private void constructorTestHelper(){ - RpcRegistration aggregatorRpcReg = mock(RpcRegistration.class); + private void constructorTestHelper() { + aggregatorRpcReg = mock(RpcRegistration.class); EventSourceService eventSourceService = mock(EventSourceService.class); - doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class), any(EventSourceTopology.class)); + doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class), + any(EventSourceTopology.class)); doReturn(eventSourceService).when(rpcProviderRegistryMock).getRpcService(EventSourceService.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)); + doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), + any(DataObject.class),eq(true)); CheckedFuture checkedFutureMock = mock(CheckedFuture.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)); + } + + @Test + public void destroyTopicTest() throws Exception { + topicTestHelper(); + TopicId topicId = new TopicId("topic-id-007"); + Map localMap = eventSourceTopology.getEventSourceTopicMap(); + EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"), + "pattern", eventSourceTopology); + localMap.put(topicId, eventSourceTopic); + DestroyTopicInput input = new DestroyTopicInputBuilder().setTopicId(topicId).build(); + eventSourceTopology.destroyTopic(input); + verify(listenerRegistrationMock, times(1)).close(); + } - private void topicTestHelper() throws Exception{ + private void topicTestHelper() throws Exception { constructorTestHelper(); createTopicInputMock = mock(CreateTopicInput.class); eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock); @@ -104,10 +117,8 @@ public class EventSourceTopologyTest { doReturn(pattern).when(createTopicInputMock).getNodeIdPattern(); listenerRegistrationMock = mock(ListenerRegistration.class); - doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataChangeListener(eq(LogicalDatastoreType.OPERATIONAL), - any(InstanceIdentifier.class), - any(EventSourceTopic.class), - eq(DataBroker.DataChangeScope.SUBTREE)); + doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataTreeChangeListener( + any(DataTreeIdentifier.class), any(EventSourceTopic.class)); ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class); doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction(); @@ -131,11 +142,17 @@ public class EventSourceTopologyTest { } @Test - public void destroyTopicTest() throws Exception{ + public void closeTest() throws Exception { + constructorTestHelper(); topicTestHelper(); - //TODO: modify test when destroyTopic will be implemented - DestroyTopicInput destroyTopicInput = null; - assertNotNull("Instance has not been created correctly.", eventSourceTopology.destroyTopic(destroyTopicInput)); + Map localMap = eventSourceTopology.getEventSourceTopicMap(); + TopicId topicIdMock = mock(TopicId.class); + EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"), + "pattern", eventSourceTopology); + localMap.put(topicIdMock, eventSourceTopic); + eventSourceTopology.close(); + verify(aggregatorRpcReg, times(1)).close(); + verify(listenerRegistrationMock, times(1)).close(); } @Test @@ -145,13 +162,52 @@ public class EventSourceTopologyTest { EventSource eventSourceMock = mock(EventSource.class); NodeId nodeId = new NodeId("nodeIdValue1"); nodeKey = new NodeKey(nodeId); - doReturn(nodeKey).when(nodeMock).getKey(); + doReturn(nodeKey).when(nodeMock).key(); 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)); + 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)); eventSourceTopology.register(eventSourceMock); - verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class)); + 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 = eventSourceTopology + .getRoutedRpcRegistrations(); + NodeKey nodeKeyMock = mock(NodeKey.class); + doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey(); + BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = + 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).key(); + 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)); + } }