mdsal-notification simple unit test added 14/46114/2
authorRudolf Brisuda <rbrisuda@cisco.com>
Fri, 23 Sep 2016 09:04:54 +0000 (11:04 +0200)
committerRudolf Brisuda <rbrisuda@cisco.com>
Fri, 23 Sep 2016 09:08:29 +0000 (11:08 +0200)
Change-Id: Iabf4f59f80ab28871c2fa340a24eb0954dc8fa99
Signed-off-by: Rudolf Brisuda <rbrisuda@cisco.com>
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/controller/config/yang/netconf/mdsal/notification/CapabilityChangeNotificationProducerTest.java

index 8149ea00ff0b5e5e20b584798a6dbb899142bff1..e2156413bcd178af85de108ff27ff84682940d60 100644 (file)
@@ -57,7 +57,8 @@ public class CapabilityChangeNotificationProducerTest {
         Capabilities newCapabilities = new CapabilitiesBuilder().setCapability(newCapabilitiesList).build();
         Map<InstanceIdentifier<?>, DataObject> createdData = Maps.newHashMap();
         createdData.put(capabilitiesIdentifier, newCapabilities);
-        verifyDataTreeChange(null, newCapabilities, changedCapabilitesFrom(newCapabilitiesList, Collections.<Uri>emptyList()));
+        verifyDataTreeChange(DataObjectModification.ModificationType.WRITE, null, newCapabilities,
+                changedCapabilitesFrom(newCapabilitiesList, Collections.<Uri>emptyList()));
     }
 
     @Test
@@ -66,16 +67,27 @@ public class CapabilityChangeNotificationProducerTest {
         final List<Uri> updatedCapabilitiesList = Lists.newArrayList(new Uri("originalCapability"), new Uri("newCapability"));
         Capabilities originalCapabilities = new CapabilitiesBuilder().setCapability(originalCapabilitiesList).build();
         Capabilities updatedCapabilities = new CapabilitiesBuilder().setCapability(updatedCapabilitiesList).build();
-        verifyDataTreeChange(originalCapabilities, updatedCapabilities, changedCapabilitesFrom(
+        verifyDataTreeChange(DataObjectModification.ModificationType.WRITE, originalCapabilities, updatedCapabilities, changedCapabilitesFrom(
                 Lists.newArrayList(new Uri("newCapability")), Lists.newArrayList(new Uri("anotherOriginalCapability"))));
     }
 
+    @Test
+    public void testOnDataChangedDelete() {
+        final List<Uri> originalCapabilitiesList = Lists.newArrayList(new Uri("originalCapability"),
+                new Uri("anotherOriginalCapability"));
+        final Capabilities originalCapabilities =
+                new CapabilitiesBuilder().setCapability(originalCapabilitiesList).build();
+        verifyDataTreeChange(DataObjectModification.ModificationType.DELETE, originalCapabilities, null,
+                changedCapabilitesFrom(Collections.emptyList(), originalCapabilitiesList));
+    }
+
     @SuppressWarnings("unchecked")
-    private void verifyDataTreeChange(Capabilities originalCapabilities, Capabilities updatedCapabilities,
+    private void verifyDataTreeChange(final DataObjectModification.ModificationType modificationType,
+                                      Capabilities originalCapabilities, Capabilities updatedCapabilities,
                                       NetconfCapabilityChange expectedChange) {
         final DataTreeModification<Capabilities> treeChange2 = mock(DataTreeModification.class);
         final DataObjectModification<Capabilities> objectChange2 = mock(DataObjectModification.class);
-        doReturn(DataObjectModification.ModificationType.WRITE).when(objectChange2).getModificationType();
+        doReturn(modificationType).when(objectChange2).getModificationType();
         doReturn(objectChange2).when(treeChange2).getRootNode();
         doReturn(originalCapabilities).when(objectChange2).getDataBefore();
         doReturn(updatedCapabilities).when(objectChange2).getDataAfter();