X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fmessagebus-netconf%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fmessagebus%2Feventsources%2Fnetconf%2FNetconfEventSourceManagerTest.java;h=7a61344cdfc1731f5d26a22545910f79f5713967;hb=6345ccffb82ea4392a0b89d6ae11655e6302a46a;hp=6d9938cdc81f8f9674bacde70e4aca23786b4ddd;hpb=f597da23057c39e38a38fda0038f2388506c0a14;p=netconf.git diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java index 6d9938cdc8..7a61344cdf 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManagerTest.java @@ -8,7 +8,6 @@ package org.opendaylight.netconf.messagebus.eventsources.netconf; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Matchers.notNull; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -18,15 +17,16 @@ import static org.mockito.Mockito.verify; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; +import java.util.Collections; import java.util.HashMap; -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.DataObjectModification; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; +import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; import org.opendaylight.controller.md.sal.binding.api.MountPointService; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; @@ -44,8 +44,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.r import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -56,7 +54,7 @@ public class NetconfEventSourceManagerTest { DOMMountPointService domMountPointServiceMock; MountPointService mountPointServiceMock; EventSourceRegistry eventSourceTopologyMock; - AsyncDataChangeEvent asyncDataChangeEventMock; + DataTreeModification dataTreeModificationMock; RpcProviderRegistry rpcProviderRegistryMock; EventSourceRegistry eventSourceRegistry; @@ -64,6 +62,7 @@ public class NetconfEventSourceManagerTest { public static void initTestClass() throws IllegalAccessException, InstantiationException { } + @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final DataBroker dataBrokerMock = mock(DataBroker.class); @@ -75,9 +74,8 @@ public class NetconfEventSourceManagerTest { eventSourceRegistry = mock(EventSourceRegistry.class); listenerRegistrationMock = mock(ListenerRegistration.class); - doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataChangeListener(eq(LogicalDatastoreType - .OPERATIONAL), any(InstanceIdentifier.class), any(NetconfEventSourceManager.class), eq( - AsyncDataBroker.DataChangeScope.SUBTREE)); + doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataTreeChangeListener( + any(DataTreeIdentifier.class), any(NetconfEventSourceManager.class)); DOMMountPoint domMountPointMock = mock(DOMMountPoint.class); Optional optionalDomMountServiceMock = Optional.of(domMountPointMock); @@ -106,42 +104,42 @@ public class NetconfEventSourceManagerTest { @Test public void onDataChangedCreateEventSourceTestByCreateEntry() throws Exception { onDataChangedTestHelper(true, false, true, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); + netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock)); verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); } @Test public void onDataChangedCreateEventSourceTestByUpdateEntry() throws Exception { onDataChangedTestHelper(false, true, true, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); + netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock)); verify(eventSourceRegistry, times(1)).registerEventSource(any(EventSource.class)); } @Test public void onDataChangedCreateEventSourceTestNotNeconf() throws Exception { onDataChangedTestHelper(false, true, false, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); + netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock)); verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); } @Test public void onDataChangedCreateEventSourceTestNotNotificationCapability() throws Exception { onDataChangedTestHelper(true, false, true, "bad-prefix"); - netconfEventSourceManager.onDataChanged(asyncDataChangeEventMock); + netconfEventSourceManager.onDataTreeChanged(Collections.singletonList(dataTreeModificationMock)); verify(eventSourceRegistry, times(0)).registerEventSource(any(EventSource.class)); } + @SuppressWarnings("unchecked") private void onDataChangedTestHelper(boolean create, boolean update, boolean isNetconf, String notificationCapabilityPrefix) throws Exception { - asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class); - Map mapCreate = new HashMap<>(); - Map mapUpdate = new HashMap<>(); + dataTreeModificationMock = mock(DataTreeModification.class); + DataObjectModification mockModification = mock(DataObjectModification.class); + doReturn(create ? DataObjectModification.ModificationType.WRITE : + DataObjectModification.ModificationType.SUBTREE_MODIFIED).when(mockModification).getModificationType(); + doReturn(mockModification).when(dataTreeModificationMock).getRootNode(); - Node node01; + final Node node01; String nodeId = "Node01"; - doReturn(mapCreate).when(asyncDataChangeEventMock).getCreatedData(); - doReturn(mapUpdate).when(asyncDataChangeEventMock).getUpdatedData(); - if (isNetconf) { node01 = NetconfTestUtils .getNetconfNode(nodeId, "node01.test.local", ConnectionStatus.Connected, @@ -151,13 +149,10 @@ public class NetconfEventSourceManagerTest { node01 = NetconfTestUtils.getNode(nodeId); } - if (create) { - mapCreate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); - } - if (update) { - mapUpdate.put(NetconfTestUtils.getInstanceIdentifier(node01), node01); - } + doReturn(node01).when(mockModification).getDataAfter(); + doReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, + NetconfTestUtils.getInstanceIdentifier(node01))).when(dataTreeModificationMock).getRootPath(); } -} \ No newline at end of file +}