Merge "Add missing copyright text"
[controller.git] / opendaylight / md-sal / messagebus-impl / src / test / java / org / opendaylight / controller / messagebus / app / impl / NetconfEventSourceTest.java
index 58da9e3eb13dfe54ec3eb41f74b12f8681b8d95b..5e1a07062d38596724225bf22b1edf33b084df2d 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.controller.messagebus.app.impl;
 
-import static org.junit.Assert.assertEquals;
+//import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
@@ -15,18 +15,15 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-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 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;
@@ -61,30 +58,25 @@ public class NetconfEventSourceTest {
     NetconfEventSource netconfEventSource;
     DOMMountPoint domMountPointMock;
     JoinTopicInput joinTopicInputMock;
-    AsyncDataChangeEvent asyncDataChangeEventMock;
-    Node dataObjectMock;
 
     @Before
     public void setUp() throws Exception {
         Map<String, String> streamMap = new HashMap<>();
-        streamMap.put("string1", "string2");
+        streamMap.put("uriStr1", "string2");
         domMountPointMock = mock(DOMMountPoint.class);
         DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class);
-        MountPoint mountPointMock = mock(MountPoint.class);
 
         RpcConsumerRegistry rpcConsumerRegistryMock = mock(RpcConsumerRegistry.class);
         Optional<BindingService> onlyOptionalMock = (Optional<BindingService>) 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);
+                = 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");
+                = 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
@@ -102,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<InstanceIdentifier, DataObject> dataChangeMap = new HashMap<>();
-        dataChangeMap.put(brmIdent, dataObjectMock);
-        doReturn(dataChangeMap).when(asyncDataChangeEventMock).getUpdatedData();
-        doReturn(new HashMap<InstanceIdentifier, DataObject>()).when(asyncDataChangeEventMock).getOriginalData();
-        doReturn(true).when(dataObjectMock).isConnected();
-
-        Set<String> localSet = getActiveStreams();
-        localSet.add("activeStream1");
-
-        Optional<DOMService> optionalMock = (Optional<DOMService>) 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();
@@ -143,7 +106,7 @@ public class NetconfEventSourceTest {
         doReturn(topicId).when(joinTopicInputMock).getTopicId();
         NotificationPattern notificationPatternMock = mock(NotificationPattern.class);
         doReturn(notificationPatternMock).when(joinTopicInputMock).getNotificationPattern();
-        doReturn("regexString1").when(notificationPatternMock).getValue();
+        doReturn("uriStr1").when(notificationPatternMock).getValue();
 
         SchemaContext schemaContextMock = mock(SchemaContext.class);
         doReturn(schemaContextMock).when(domMountPointMock).getSchemaContext();
@@ -163,16 +126,15 @@ 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<NetconfEventSource> listenerRegistrationMock = (ListenerRegistration<NetconfEventSource>)mock(ListenerRegistration.class);
+        doReturn(listenerRegistrationMock).when(domNotificationServiceMock).registerNotificationListener(any(NetconfEventSource.class), any(SchemaPath.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);
+        Optional<DOMService> optionalMock = (Optional<DOMService>) 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));
     }
 
-}
+}
\ No newline at end of file