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%2FEventSourceTopicTest.java;h=6059d9ab4f889be048dbfd8c4281c7ba18ea625e;hp=0c32cb51e32239ce66aa982955b1ffa9637ce2e1;hb=5f587c3e2bfabc09fec49463d04a6fbeba414e9c;hpb=cce450550bec259d4f925389bafd007676f2186f diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java index 0c32cb51e3..6059d9ab4f 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java @@ -8,53 +8,56 @@ package org.opendaylight.controller.messagebus.app.impl; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; 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.util.HashMap; -import java.util.Map; - +import com.google.common.util.concurrent.FluentFuture; +import java.util.Collections; 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.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; 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.eventsource.rev141202.EventSourceService; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicStatus; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import com.google.common.util.concurrent.CheckedFuture; - +@Deprecated(forRemoval = true) public class EventSourceTopicTest { EventSourceTopic eventSourceTopic; - Node dataObjectNodeMock; - NodeId nodeIdMock; DataBroker dataBrokerMock; EventSourceService eventSourceServiceMock; EventSourceTopology eventSourceTopologyMock; @BeforeClass - public static void initTestClass() throws IllegalAccessException, InstantiationException { + public static void initTestClass() { } @Before - public void setUp() throws Exception { - NotificationPattern notificationPattern = new NotificationPattern("value1"); + public void setUp() { + final NotificationPattern notificationPattern = new NotificationPattern("value1"); eventSourceServiceMock = mock(EventSourceService.class); + doReturn(RpcResultBuilder.success(new JoinTopicOutputBuilder().setStatus(JoinTopicStatus.Up).build()) + .buildFuture()).when(eventSourceServiceMock).joinTopic(any(JoinTopicInput.class)); + eventSourceTopologyMock = mock(EventSourceTopology.class); dataBrokerMock = mock(DataBroker.class); doReturn(eventSourceServiceMock).when(eventSourceTopologyMock).getEventSourceService(); @@ -62,14 +65,16 @@ public class EventSourceTopicTest { 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)); - CheckedFuture checkedFutureWriteMock = mock(CheckedFuture.class); - doReturn(checkedFutureWriteMock).when(writeTransactionMock).submit(); + doNothing().when(writeTransactionMock).mergeParentStructurePut(any(LogicalDatastoreType.class), + any(InstanceIdentifier.class), any(DataObject.class)); + FluentFuture checkedFutureWriteMock = mock(FluentFuture.class); + doReturn(checkedFutureWriteMock).when(writeTransactionMock).commit(); - ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class); + ReadTransaction readOnlyTransactionMock = mock(ReadTransaction.class); doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction(); - CheckedFuture checkedFutureReadMock = mock(CheckedFuture.class); - doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH); + FluentFuture checkedFutureReadMock = mock(FluentFuture.class); + doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL, + EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH); eventSourceTopic = EventSourceTopic.create(notificationPattern, "nodeIdPattern1", eventSourceTopologyMock); } @@ -83,26 +88,28 @@ public class EventSourceTopicTest { assertNotNull("Topic has not been created correctly.", eventSourceTopic.getTopicId()); } + @SuppressWarnings("unchecked") @Test - public void onDataChangedTest() { - AsyncDataChangeEvent asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class); - onDataChangedTestHelper(asyncDataChangeEventMock); - eventSourceTopic.onDataChanged(asyncDataChangeEventMock); - verify(dataObjectNodeMock, times(2)).getNodeId(); - verify(nodeIdMock, times(2)).getValue(); - } - - private void onDataChangedTestHelper(AsyncDataChangeEvent asyncDataChangeEventMock){ - Map, DataObject> map = new HashMap<>(); - InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class); - dataObjectNodeMock = mock(Node.class); - doReturn(getNodeKey("testNodeId01")).when(dataObjectNodeMock).getKey(); - map.put(instanceIdentifierMock, dataObjectNodeMock); - doReturn(map).when(asyncDataChangeEventMock).getUpdatedData(); - doReturn(map).when(asyncDataChangeEventMock).getCreatedData(); - nodeIdMock = mock(NodeId.class); + public void onDataTreeChangedTest() { + InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class); + DataTreeModification mockDataTreeModification = mock(DataTreeModification.class); + DataObjectModification mockModification = mock(DataObjectModification.class); + doReturn(mockModification).when(mockDataTreeModification).getRootNode(); + doReturn(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifierMock)) + .when(mockDataTreeModification).getRootPath(); + doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType(); + + Node dataObjectNodeMock = mock(Node.class); + doReturn(getNodeKey("testNodeId01")).when(dataObjectNodeMock).key(); + NodeId nodeIdMock = mock(NodeId.class); doReturn(nodeIdMock).when(dataObjectNodeMock).getNodeId(); doReturn("nodeIdPattern1").when(nodeIdMock).getValue(); + + doReturn(dataObjectNodeMock).when(mockModification).getDataAfter(); + + eventSourceTopic.onDataTreeChanged(Collections.singletonList(mockDataTreeModification)); + verify(dataObjectNodeMock).getNodeId(); + verify(nodeIdMock).getValue(); } @Test @@ -112,7 +119,7 @@ public class EventSourceTopicTest { verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class)); } - public NodeKey getNodeKey(String nodeId){ + public NodeKey getNodeKey(final String nodeId) { return new NodeKey(new NodeId(nodeId)); } -} \ No newline at end of file +}