Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / test / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / NodeConnectorNotificationSupplierImplTest.java
index 3c6b038b0d276e4c506f4eb2662feeb096820eaa..a14d6e2e2eb85eea1eb56c6d7942a876963f990d 100644 (file)
@@ -10,20 +10,21 @@ package org.opendaylight.openflowplugin.applications.notification.supplier.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
 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.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.Collection;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Matchers;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
+import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
@@ -36,60 +37,60 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.No
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-/**
- *
- */
 public class NodeConnectorNotificationSupplierImplTest {
 
-    private static final String FLOW_NODE_ID = "test-111";
+    private static final String FLOW_NODE_ID = "openflow:111";
     private static final String FLOW_CODE_CONNECTOR_ID = "test-con-111";
     private NodeConnectorNotificationSupplierImpl notifSupplierImpl;
-    private NotificationProviderService notifProviderService;
+    private NotificationPublishService notifProviderService;
     private DataBroker dataBroker;
 
     @Before
     public void initalization() {
-        notifProviderService = mock(NotificationProviderService.class);
+        notifProviderService = mock(NotificationPublishService.class);
         dataBroker = mock(DataBroker.class);
         notifSupplierImpl = new NodeConnectorNotificationSupplierImpl(notifProviderService, dataBroker);
-        TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
+        TestSupplierVerifyHelper.verifyDataTreeChangeListenerRegistration(dataBroker);
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = NullPointerException.class)
     public void testNullChangeEvent() {
-        notifSupplierImpl.onDataChanged(null);
+        notifSupplierImpl.onDataTreeChanged(null);
     }
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void testNullableChangeEvent() {
-        notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+        notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
     }
 
     @Test
     public void testEmptyChangeEvent() {
-        notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
+        notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
     }
 
     @Test
     public void testCreate() {
-        final NodeConnectorUpdated notification = notifSupplierImpl.createNotification(createTestFlowCapableNodeConnecor(),
-                createTestFlowCapableConnectorNodePath());
+        final NodeConnectorUpdated notification = notifSupplierImpl
+                .createNotification(createTestFlowCapableNodeConnecor(), createTestFlowCapableConnectorNodePath());
         assertNotNull(notification);
         assertEquals(FLOW_CODE_CONNECTOR_ID, notification.getId().getValue());
         assertEquals(FLOW_CODE_CONNECTOR_ID, notification.getNodeConnectorRef().getValue()
-                .firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue());
-        assertEquals(FLOW_NODE_ID, notification.getNodeConnectorRef().getValue().firstKeyOf(Node.class, NodeKey.class).getId().getValue());
+                .firstKeyOf(NodeConnector.class).getId().getValue());
+        assertEquals(FLOW_NODE_ID,
+                     notification.getNodeConnectorRef().getValue().firstKeyOf(Node.class).getId()
+                             .getValue());
     }
 
     @Test
-    public void testCreateChangeEvent() {
-        final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
-        createdData.put(createTestFlowCapableConnectorNodePath(), createTestFlowCapableNodeConnecor());
-        notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
-        verify(notifProviderService, times(1)).publish(Matchers.any(NodeConnectorUpdated.class));
+    public void testCreateChangeEvent() throws InterruptedException {
+        final TestData<FlowCapableNodeConnector> testData = new TestData<>(createTestFlowCapableConnectorNodePath(),
+                null, createTestFlowCapableNodeConnecor(), DataObjectModification.ModificationType.WRITE);
+        Collection<DataTreeModification<FlowCapableNodeConnector>> collection = new ArrayList<>();
+        collection.add(testData);
+        notifSupplierImpl.onDataTreeChanged(collection);
+        verify(notifProviderService, times(1)).putNotification(any(NodeConnectorUpdated.class));
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -104,19 +105,24 @@ public class NodeConnectorNotificationSupplierImplTest {
 
     @Test
     public void testDelete() {
-        final NodeConnectorRemoved notification = notifSupplierImpl.deleteNotification(createTestFlowCapableConnectorNodePath());
+        final NodeConnectorRemoved notification = notifSupplierImpl
+                .deleteNotification(createTestFlowCapableConnectorNodePath());
         assertNotNull(notification);
         assertEquals(FLOW_CODE_CONNECTOR_ID, notification.getNodeConnectorRef().getValue()
-                .firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue());
-        assertEquals(FLOW_NODE_ID, notification.getNodeConnectorRef().getValue().firstKeyOf(Node.class, NodeKey.class).getId().getValue());
+                .firstKeyOf(NodeConnector.class).getId().getValue());
+        assertEquals(FLOW_NODE_ID,
+                     notification.getNodeConnectorRef().getValue().firstKeyOf(Node.class).getId()
+                             .getValue());
     }
 
     @Test
-    public void testDeleteChangeEvent() {
-        final Set<InstanceIdentifier<?>> removeData = new HashSet<>();
-        removeData.add(createTestFlowCapableConnectorNodePath());
-        notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(null, null, removeData));
-        verify(notifProviderService, times(1)).publish(Matchers.any(NodeConnectorRemoved.class));
+    public void testDeleteChangeEvent() throws InterruptedException {
+        final TestData<FlowCapableNodeConnector> testData = new TestData<>(createTestFlowCapableConnectorNodePath(),
+                createTestFlowCapableNodeConnecor(), null, DataObjectModification.ModificationType.DELETE);
+        Collection<DataTreeModification<FlowCapableNodeConnector>> collection = new ArrayList<>();
+        collection.add(testData);
+        notifSupplierImpl.onDataTreeChanged(collection);
+        verify(notifProviderService, times(1)).putNotification(any(NodeConnectorRemoved.class));
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -126,7 +132,8 @@ public class NodeConnectorNotificationSupplierImplTest {
 
     private static InstanceIdentifier<FlowCapableNodeConnector> createTestFlowCapableConnectorNodePath() {
         return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID)))
-                .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(FLOW_CODE_CONNECTOR_ID))).augmentation(FlowCapableNodeConnector.class);
+                .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(FLOW_CODE_CONNECTOR_ID)))
+                .augmentation(FlowCapableNodeConnector.class);
     }
 
     private static FlowCapableNodeConnector createTestFlowCapableNodeConnecor() {