X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fmessagebus-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmessagebus%2Fapp%2Fimpl%2FNetconfEventSourceTest.java;h=5e1a07062d38596724225bf22b1edf33b084df2d;hb=bd7617c472e0326c56e46036580d187a450c5b80;hp=ed9025780a949ab08ba900613a014e301f047a29;hpb=2720ff2c662769d1c72e5723c18be4f7d79cd642;p=controller.git diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java index ed9025780a..5e1a07062d 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java @@ -7,12 +7,23 @@ */ package org.opendaylight.controller.messagebus.app.impl; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; +//import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +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.net.URI; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.BindingService; -import org.opendaylight.controller.md.sal.binding.api.MountPoint; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; @@ -39,21 +50,8 @@ import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import java.lang.reflect.Field; -import java.net.URI; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -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 com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; public class NetconfEventSourceTest { @@ -67,21 +65,18 @@ public class NetconfEventSourceTest { streamMap.put("uriStr1", "string2"); domMountPointMock = mock(DOMMountPoint.class); DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class); - MountPoint mountPointMock = mock(MountPoint.class); RpcConsumerRegistry rpcConsumerRegistryMock = mock(RpcConsumerRegistry.class); Optional onlyOptionalMock = (Optional) mock(Optional.class); NotificationsService notificationsServiceMock = mock(NotificationsService.class); - doReturn(onlyOptionalMock).when(mountPointMock).getService(RpcConsumerRegistry.class); - doReturn(rpcConsumerRegistryMock).when(onlyOptionalMock).get(); doReturn(notificationsServiceMock).when(rpcConsumerRegistryMock).getRpcService(NotificationsService.class); org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node node = mock(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class); org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId nodeId = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId("NodeId1"); doReturn(nodeId).when(node).getNodeId(); - netconfEventSource = new NetconfEventSource(node, streamMap, domMountPointMock, domNotificationPublishServiceMock, mountPointMock); + netconfEventSource = new NetconfEventSource(node, streamMap, domMountPointMock, domNotificationPublishServiceMock); } @Test @@ -99,35 +94,6 @@ public class NetconfEventSourceTest { verify(dataObjectMock, times(2)).isConnected(); } - @Test - public void onDataChangedResubscribeTest() throws Exception{ - - InstanceIdentifier brmIdent = InstanceIdentifier.create(Nodes.class) - .child(Node.class, new NodeKey(new NodeId("brm"))).augmentation(NetconfNode.class); - - AsyncDataChangeEvent asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class); - NetconfNode dataObjectMock = mock(NetconfNode.class); - Map dataChangeMap = new HashMap<>(); - dataChangeMap.put(brmIdent, dataObjectMock); - doReturn(dataChangeMap).when(asyncDataChangeEventMock).getUpdatedData(); - doReturn(new HashMap()).when(asyncDataChangeEventMock).getOriginalData(); - doReturn(true).when(dataObjectMock).isConnected(); - - Set localSet = getActiveStreams(); - localSet.add("activeStream1"); - - Optional optionalMock = (Optional) mock(Optional.class); - doReturn(optionalMock).when(domMountPointMock).getService(DOMRpcService.class); - DOMRpcService domRpcServiceMock = mock(DOMRpcService.class); - doReturn(domRpcServiceMock).when(optionalMock).get(); - CheckedFuture checkedFutureMock = mock(CheckedFuture.class); - doReturn(checkedFutureMock).when(domRpcServiceMock).invokeRpc(any(SchemaPath.class), any(ContainerNode.class)); - - netconfEventSource.onDataChanged(asyncDataChangeEventMock); - verify(dataObjectMock, times(1)).isConnected(); - assertEquals("Size of set has not been set correctly.", 1, getActiveStreams().size()); - } - @Test public void joinTopicTest() throws Exception{ joinTopicTestHelper(); @@ -160,8 +126,8 @@ public class NetconfEventSourceTest { DOMNotificationService domNotificationServiceMock = mock(DOMNotificationService.class); doReturn(domNotificationServiceMock).when(domNotificationServiceOptionalMock).get(); - ListenerRegistration listenerRegistrationMock = mock(ListenerRegistration.class); - doReturn(listenerRegistrationMock).when(domNotificationServiceMock).registerNotificationListener(any(NetconfEventSource.class), any(List.class)); + ListenerRegistration listenerRegistrationMock = (ListenerRegistration)mock(ListenerRegistration.class); + doReturn(listenerRegistrationMock).when(domNotificationServiceMock).registerNotificationListener(any(NetconfEventSource.class), any(SchemaPath.class)); Optional optionalMock = (Optional) mock(Optional.class); doReturn(optionalMock).when(domMountPointMock).getService(DOMRpcService.class); @@ -171,12 +137,4 @@ public class NetconfEventSourceTest { doReturn(checkedFutureMock).when(domRpcServiceMock).invokeRpc(any(SchemaPath.class), any(ContainerNode.class)); } -//TODO: create Test for NetConfEventSource#onNotification - - private Set getActiveStreams() throws Exception{ - Field nesField = NetconfEventSource.class.getDeclaredField("activeStreams"); - nesField.setAccessible(true); - return (Set) nesField.get(netconfEventSource); - } - } \ No newline at end of file