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=8776c996f981278963b8f94d64c587797b0524a2;hp=50ae4d9389cf143a8864584ae382e27d47893c56;hb=30535bcc4c2770cb8500469fe40bdfb37d8ade4d;hpb=745d7a11635b81af7b4e1f1303db071c6c6b198d 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 50ae4d9389..8776c996f9 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,16 +16,16 @@ 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.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.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; @@ -35,9 +35,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; @@ -49,23 +51,16 @@ 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; RpcRegistration aggregatorRpcReg; - @BeforeClass - public static void initTestClass() throws IllegalAccessException, InstantiationException { - } - @Before public void setUp() throws Exception { dataBrokerMock = mock(DataBroker.class); @@ -97,6 +92,18 @@ public class EventSourceTopologyTest { 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 = getEventSourceTopicMap(); + EventSourceTopic eventSourceTopicMock = mock(EventSourceTopic.class); + localMap.put(topicId, eventSourceTopicMock); + DestroyTopicInput input = new DestroyTopicInputBuilder().setTopicId(topicId).build(); + eventSourceTopology.destroyTopic(input); + verify(eventSourceTopicMock, times(1)).close(); + } + private void topicTestHelper() throws Exception{ constructorTestHelper(); createTopicInputMock = mock(CreateTopicInput.class); @@ -108,10 +115,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(); @@ -134,25 +139,17 @@ public class EventSourceTopologyTest { doReturn(nodeId).when(nodeMock).getNodeId(); } - @Test - public void destroyTopicTest() throws Exception{ - topicTestHelper(); - //TODO: modify test when destroyTopic will be implemented - DestroyTopicInput destroyTopicInput = null; - 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); + Map localMap = getEventSourceTopicMap(); + TopicId topicIdMock = mock(TopicId.class); + EventSourceTopic eventSourceTopicMock = mock(EventSourceTopic.class); + localMap.put(topicIdMock, eventSourceTopicMock); eventSourceTopology.close(); verify(aggregatorRpcReg, times(1)).close(); - verify(listenerListenerRegistrationMock, times(1)).close(); + verify(eventSourceTopicMock, times(1)).close(); } @Test @@ -180,7 +177,7 @@ public class EventSourceTopologyTest { Map> localMap = getRoutedRpcRegistrations(); NodeKey nodeKeyMock = mock(NodeKey.class); doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey(); - BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = (BindingAwareBroker.RoutedRpcRegistration) mock(BindingAwareBroker.RoutedRpcRegistration.class); + BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class); localMap.put(nodeKeyMock, routedRpcRegistrationMock); eventSourceTopology.unRegister(eventSourceMock); verify(routedRpcRegistrationMock, times(1)).close(); @@ -201,8 +198,8 @@ public class EventSourceTopologyTest { assertNotNull("Return value has not been created correctly.", eventSourceTopology.registerEventSource(eventSourceMock)); } - private Map getTopicListenerRegistrations() throws Exception{ - Field nesField = EventSourceTopology.class.getDeclaredField("topicListenerRegistrations"); + private Map getEventSourceTopicMap() throws Exception{ + Field nesField = EventSourceTopology.class.getDeclaredField("eventSourceTopicMap"); nesField.setAccessible(true); return (Map) nesField.get(eventSourceTopology); } @@ -213,4 +210,4 @@ public class EventSourceTopologyTest { return (Map) nesField.get(eventSourceTopology); } -} \ No newline at end of file +}