Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / test / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / MeterNotificationSupplierImplTest.java
index 4d120ae1a9a3f6a9f938f51b7e51c4885df79829..e786f99eb962af505caa846a0482393082cf5da6 100644 (file)
@@ -5,29 +5,23 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item;
 
 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.ArrayList;
 import java.util.Collection;
-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.mockito.Matchers;
-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.DataTreeModification;
-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;
@@ -35,8 +29,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
@@ -45,11 +37,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Met
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
- *
+ * Test for
+ * {@link org.opendaylight.openflowplugin.applications.notification.supplier.impl.item.MeterNotificationSupplierImpl}.
  */
 public class MeterNotificationSupplierImplTest {
 
@@ -58,15 +50,15 @@ public class MeterNotificationSupplierImplTest {
     private static final Long UPDATED_METER_ID = 100L;
 
     private MeterNotificationSupplierImpl 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 MeterNotificationSupplierImpl(notifProviderService, dataBroker);
-        TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
+        TestSupplierVerifyHelper.verifyDataTreeChangeListenerRegistration(dataBroker);
     }
 
     @Test(expected = NullPointerException.class)
@@ -89,18 +81,21 @@ public class MeterNotificationSupplierImplTest {
         final MeterAdded notification = notifSupplierImpl.createNotification(createTestMeter(), createTestMeterPath());
         assertNotNull(notification);
         assertEquals(METER_ID, notification.getMeterId().getValue());
-        assertEquals(METER_ID, notification.getMeterRef().getValue().firstKeyOf(Meter.class, MeterKey.class).getMeterId().getValue());
-        assertEquals(FLOW_NODE_ID, notification.getNode().getValue().firstKeyOf(Node.class, NodeKey.class).getId().getValue());
+        assertEquals(METER_ID,
+                     notification.getMeterRef().getValue().firstKeyOf(Meter.class).getMeterId()
+                             .getValue());
+        assertEquals(FLOW_NODE_ID,
+                     notification.getNode().getValue().firstKeyOf(Node.class).getId().getValue());
     }
 
     @Test
-    public void testCreateChangeEvent() {
-        final TestData testData = new TestData(createTestMeterPath(),null,createTestMeter(),
-                DataObjectModification.ModificationType.WRITE);
+    public void testCreateChangeEvent() throws InterruptedException {
+        final TestData<Meter> testData = new TestData<>(createTestMeterPath(), null, createTestMeter(),
+                                                        DataObjectModification.ModificationType.WRITE);
         Collection<DataTreeModification<Meter>> collection = new ArrayList<>();
         collection.add(testData);
         notifSupplierImpl.onDataTreeChanged(collection);
-        verify(notifProviderService, times(1)).publish(Matchers.any(MeterAdded.class));
+        verify(notifProviderService, times(1)).putNotification(any(MeterAdded.class));
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -119,18 +114,22 @@ public class MeterNotificationSupplierImplTest {
                 .updateNotification(createTestMeter(), createTestMeterPath());
         assertNotNull(notification);
         assertEquals(METER_ID, notification.getMeterId().getValue());
-        assertEquals(METER_ID, notification.getMeterRef().getValue().firstKeyOf(Meter.class, MeterKey.class).getMeterId().getValue());
-        assertEquals(FLOW_NODE_ID, notification.getNode().getValue().firstKeyOf(Node.class, NodeKey.class).getId().getValue());
+        assertEquals(METER_ID,
+                     notification.getMeterRef().getValue().firstKeyOf(Meter.class).getMeterId()
+                             .getValue());
+        assertEquals(FLOW_NODE_ID,
+                     notification.getNode().getValue().firstKeyOf(Node.class).getId().getValue());
     }
 
     @Test
-    public void testUdateChangeEvent() {
-        final TestData testData = new TestData(createTestMeterPath(),createTestMeter(),createUpdatedTestMeter(),
-                DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+    public void testUdateChangeEvent() throws InterruptedException {
+        final TestData<Meter> testData = new TestData<>(createTestMeterPath(), createTestMeter(),
+                                                        createUpdatedTestMeter(),
+                                                        DataObjectModification.ModificationType.SUBTREE_MODIFIED);
         Collection<DataTreeModification<Meter>> collection = new ArrayList<>();
         collection.add(testData);
         notifSupplierImpl.onDataTreeChanged(collection);
-        verify(notifProviderService, times(1)).publish(Matchers.any(MeterUpdated.class));
+        verify(notifProviderService, times(1)).putNotification(any(MeterUpdated.class));
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -148,18 +147,21 @@ public class MeterNotificationSupplierImplTest {
         final MeterRemoved notification = notifSupplierImpl.deleteNotification(createTestMeterPath());
         assertNotNull(notification);
         assertEquals(METER_ID, notification.getMeterId().getValue());
-        assertEquals(METER_ID, notification.getMeterRef().getValue().firstKeyOf(Meter.class, MeterKey.class).getMeterId().getValue());
-        assertEquals(FLOW_NODE_ID, notification.getNode().getValue().firstKeyOf(Node.class, NodeKey.class).getId().getValue());
+        assertEquals(METER_ID,
+                     notification.getMeterRef().getValue().firstKeyOf(Meter.class).getMeterId()
+                             .getValue());
+        assertEquals(FLOW_NODE_ID,
+                     notification.getNode().getValue().firstKeyOf(Node.class).getId().getValue());
     }
 
     @Test
-    public void testDeleteChangeEvent() {
-        final TestData testData = new TestData(createTestMeterPath(),createTestMeter(),null,
-                DataObjectModification.ModificationType.DELETE);
+    public void testDeleteChangeEvent() throws InterruptedException {
+        final TestData<Meter> testData = new TestData<>(createTestMeterPath(), createTestMeter(), null,
+                                                        DataObjectModification.ModificationType.DELETE);
         Collection<DataTreeModification<Meter>> collection = new ArrayList<>();
         collection.add(testData);
         notifSupplierImpl.onDataTreeChanged(collection);
-        verify(notifProviderService, times(1)).publish(Matchers.any(MeterRemoved.class));
+        verify(notifProviderService, times(1)).putNotification(any(MeterRemoved.class));
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -178,7 +180,7 @@ public class MeterNotificationSupplierImplTest {
         return builder.build();
     }
 
-    private static Meter createUpdatedTestMeter(){
+    private static Meter createUpdatedTestMeter() {
         final MeterBuilder builder = new MeterBuilder();
         builder.setMeterId(new MeterId(UPDATED_METER_ID));
         return builder.build();