Bump upstreams
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / mdsal / AuthenticationKeyDataListenerTest.java
index 052d7fb2cc98b8deac1e8b85235aec59c1974e46..269cb58ab11426b8590765f4f2c91f04dcf8b93c 100644 (file)
@@ -7,26 +7,28 @@
  */
 package org.opendaylight.lispflowmapping.implementation.mdsal;
 
-import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
-
-import com.google.common.collect.Lists;
 import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
-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.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
+import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container
-        .MappingAuthkeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
 
 public class AuthenticationKeyDataListenerTest {
 
@@ -57,9 +59,10 @@ public class AuthenticationKeyDataListenerTest {
         iMappingSystemMock = Mockito.mock(IMappingSystem.class);
         authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBrokerMock, iMappingSystemMock);
 
-        final InstanceIdentifier<AuthenticationKey> instanceIdentifierMock = Mockito.mock(InstanceIdentifier.class);
-        final DataTreeIdentifier<AuthenticationKey> dataTreeIdentifier =
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, instanceIdentifierMock);
+        final DataTreeIdentifier<AuthenticationKey> dataTreeIdentifier = DataTreeIdentifier.of(
+            LogicalDatastoreType.CONFIGURATION,
+            InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
+                .child(AuthenticationKey.class));
 
         change_del = Mockito.mock(DataTreeModification.class);
         change_subtreeModified = Mockito.mock(DataTreeModification.class);
@@ -74,21 +77,19 @@ public class AuthenticationKeyDataListenerTest {
         Mockito.when(change_subtreeModified.getRootNode()).thenReturn(mod_subtreeModified);
         Mockito.when(change_write.getRootPath()).thenReturn(dataTreeIdentifier);
         Mockito.when(change_write.getRootNode()).thenReturn(mod_write);
-        Mockito.when(mod_del.getModificationType()).thenReturn(ModificationType.DELETE);
-        Mockito.when(mod_subtreeModified.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED);
-        Mockito.when(mod_write.getModificationType()).thenReturn(ModificationType.WRITE);
+        Mockito.when(mod_del.modificationType()).thenReturn(ModificationType.DELETE);
+        Mockito.when(mod_subtreeModified.modificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED);
+        Mockito.when(mod_write.modificationType()).thenReturn(ModificationType.WRITE);
     }
 
     /**
      * Tests {@link AuthenticationKeyDataListener#onDataTreeChanged} method with DELETE modification type.
      */
     @Test
-    @SuppressWarnings("unchecked")
     public void onDataTreeChangedTest_delete() {
-        final List<DataTreeModification<AuthenticationKey>> changes = Lists.newArrayList(change_del);
-        Mockito.when(mod_del.getDataBefore()).thenReturn(AUTHENTICATION_KEY_1);
+        Mockito.when(mod_del.dataBefore()).thenReturn(AUTHENTICATION_KEY_1);
 
-        authenticationKeyDataListener.onDataTreeChanged(changes);
+        authenticationKeyDataListener.onDataTreeChanged(List.of(change_del));
         Mockito.verify(iMappingSystemMock).removeAuthenticationKey(IPV4_EID_1);
     }
 
@@ -96,12 +97,10 @@ public class AuthenticationKeyDataListenerTest {
      * Tests {@link AuthenticationKeyDataListener#onDataTreeChanged} method with WRITE modification type.
      */
     @Test
-    @SuppressWarnings("unchecked")
     public void onDataTreeChangedTest_write() {
-        final List<DataTreeModification<AuthenticationKey>> changes = Lists.newArrayList(change_write);
-        Mockito.when(mod_write.getDataAfter()).thenReturn(AUTHENTICATION_KEY_2);
+        Mockito.when(mod_write.dataAfter()).thenReturn(AUTHENTICATION_KEY_2);
 
-        authenticationKeyDataListener.onDataTreeChanged(changes);
+        authenticationKeyDataListener.onDataTreeChanged(List.of(change_write));
         Mockito.verify(iMappingSystemMock).addAuthenticationKey(IPV4_EID_2, AUTHENTICATION_KEY_2.getMappingAuthkey());
     }
 
@@ -109,12 +108,10 @@ public class AuthenticationKeyDataListenerTest {
      * Tests {@link AuthenticationKeyDataListener#onDataTreeChanged} method with SUBTREE_MODIFIED modification type.
      */
     @Test
-    @SuppressWarnings("unchecked")
     public void onDataTreeChangedTest_subtreeModified() {
-        final List<DataTreeModification<AuthenticationKey>> changes = Lists.newArrayList(change_subtreeModified);
-        Mockito.when(mod_subtreeModified.getDataAfter()).thenReturn(AUTHENTICATION_KEY_3);
+        Mockito.when(mod_subtreeModified.dataAfter()).thenReturn(AUTHENTICATION_KEY_3);
 
-        authenticationKeyDataListener.onDataTreeChanged(changes);
+        authenticationKeyDataListener.onDataTreeChanged(List.of(change_subtreeModified));
         Mockito.verify(iMappingSystemMock).addAuthenticationKey(IPV4_EID_3, AUTHENTICATION_KEY_3.getMappingAuthkey());
     }
 
@@ -122,16 +119,12 @@ public class AuthenticationKeyDataListenerTest {
      * Tests {@link AuthenticationKeyDataListener#onDataTreeChanged} method with multiple modification types.
      */
     @Test
-    @SuppressWarnings("unchecked")
     public void onDataTreeChangedTest_multipleModTypes() {
-        final List<DataTreeModification<AuthenticationKey>> changes =
-                Lists.newArrayList(change_del, change_write, change_subtreeModified);
-
-        Mockito.when(mod_del.getDataBefore()).thenReturn(AUTHENTICATION_KEY_1);
-        Mockito.when(mod_write.getDataAfter()).thenReturn(AUTHENTICATION_KEY_2);
-        Mockito.when(mod_subtreeModified.getDataAfter()).thenReturn(AUTHENTICATION_KEY_3);
+        Mockito.when(mod_del.dataBefore()).thenReturn(AUTHENTICATION_KEY_1);
+        Mockito.when(mod_write.dataAfter()).thenReturn(AUTHENTICATION_KEY_2);
+        Mockito.when(mod_subtreeModified.dataAfter()).thenReturn(AUTHENTICATION_KEY_3);
 
-        authenticationKeyDataListener.onDataTreeChanged(changes);
+        authenticationKeyDataListener.onDataTreeChanged(List.of(change_del, change_write, change_subtreeModified));
         Mockito.verify(iMappingSystemMock).removeAuthenticationKey(IPV4_EID_1);
         Mockito.verify(iMappingSystemMock).addAuthenticationKey(IPV4_EID_2, AUTHENTICATION_KEY_2.getMappingAuthkey());
         Mockito.verify(iMappingSystemMock).addAuthenticationKey(IPV4_EID_3, AUTHENTICATION_KEY_3.getMappingAuthkey());
@@ -145,21 +138,21 @@ public class AuthenticationKeyDataListenerTest {
     public void onDataTreeChangedTest_noModType() {
         final DataTreeModification<AuthenticationKey> changeNoModType = Mockito.mock(DataTreeModification.class);
         final DataObjectModification<AuthenticationKey> modNoType = Mockito.mock(DataObjectModification.class);
-        final List<DataTreeModification<AuthenticationKey>> changes = Lists.newArrayList(changeNoModType);
 
         Mockito.when(changeNoModType.getRootNode()).thenReturn(modNoType);
-        Mockito.when(modNoType.getModificationType()).thenReturn(null);
+        Mockito.when(modNoType.modificationType()).thenReturn(null);
 
-        authenticationKeyDataListener.onDataTreeChanged(changes);
+        authenticationKeyDataListener.onDataTreeChanged(List.of(changeNoModType));
         Mockito.verifyZeroInteractions(iMappingSystemMock);
     }
 
     private static AuthenticationKey getAuthenticationKey(Eid eid, String password) {
         return new AuthenticationKeyBuilder()
+                .withKey(new AuthenticationKeyKey(new EidUri("uri-1")))
                 .setEid(eid)
                 .setMappingAuthkey(new MappingAuthkeyBuilder()
                         .setKeyString(password)
-                        .setKeyType(1).build())
+                        .setKeyType(Uint16.valueOf(1)).build())
                 .build();
     }
 }