Prepare the YANG models for RESTCONF
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / lisp / MapServerTest.java
index e82a33e8663e5685ff855c7252caca5443ae01f1..775639180c8eb2cf2360949f9424f1b7dacb0a35 100644 (file)
@@ -26,25 +26,24 @@ import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceRLOCGroup;
 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapNotify;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRegister;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord.Action;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecordBuilder;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.Ipv4;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.NoBuilder;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.locatorrecords.LocatorRecord;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.locatorrecords.LocatorRecordBuilder;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapregisternotification.MapRegisterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.EidToLocatorRecord.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.LispAFIAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.MapNotify;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.MapRegister;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.eidtolocatorrecords.EidToLocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.eidtolocatorrecords.EidToLocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.lispaddresscontainer.address.no.NoAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.locatorrecords.LocatorRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.mapregisternotification.MapRegisterBuilder;
 
 public class MapServerTest extends BaseTestCase {
 
     private LispMappingService testedMapServer;
     private ILispDAO lispDAO;
     private MapRegisterBuilder mapRegisterBuilder;
-    private Ipv4 eid;
-    private Ipv4 rloc;
+    private LispAFIAddress eid;
+    private LispAFIAddress rloc;
     private ValueSaverAction<MappingEntry<?>[]> mappingEntriesSaver;
     private MapRegister mapRegisterWithAuthentication;
 
@@ -59,7 +58,7 @@ public class MapServerTest extends BaseTestCase {
         mapRegisterBuilder.setKeyId((short) 0);
         mapRegisterBuilder.setAuthenticationData(new byte[0]);
         eid = LispAFIConvertor.asIPAfiAddress("10.31.0.5");
-        rloc = LispAFIConvertor.asIPAfiAddress("0x192.168.136.10");
+        rloc = LispAFIConvertor.asIPAfiAddress("192.168.136.10");
         EidToLocatorRecordBuilder recordBuilder = new EidToLocatorRecordBuilder();
         recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(eid)).setMaskLength((short) 32);
         recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
@@ -82,26 +81,26 @@ public class MapServerTest extends BaseTestCase {
         mapRegisterBuilder.setWantMapNotify(false);
 
         addDefaultPutAndGetExpectations(eid, 32);
-        assertNull(testedMapServer.handleMapRegister(mapRegisterBuilder.build()));
+        assertNull(testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false));
 
         MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
         assertEquals(1, entries.length);
 
         assertEquals(AbstractLispComponent.ADDRESS_SUBKEY, entries[0].getKey());
         assertEquals(1, ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().size());
-        assertEquals(rloc, ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(0).getLispAddressContainer().getAddress());
+        assertEquals(rloc, LispAFIConvertor.toAFI(((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(0).getLispAddressContainer()));
     }
 
     @Test
     public void handleMapRegisterIpv4__ValidNotifyEchoesRegister() throws Exception {
         mapRegisterBuilder.getEidToLocatorRecord().add(
-                getDefaultEidToLocatorBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(new NoBuilder().build())).build());
+                getDefaultEidToLocatorBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(new NoAddressBuilder().build())).build());
         mapRegisterBuilder.setWantMapNotify(true);
 
         addDefaultPutAndGetExpectations(eid, 32);
-        addDefaultPutAndGetExpectations(new NoBuilder().build(), 32);
+        addDefaultPutAndGetExpectations(new NoAddressBuilder().build(), 32);
         MapRegister mr = mapRegisterBuilder.build();
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mr);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mr, false);
         assertEquals(mr.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
         ArrayAssert.assertEquals(mr.getAuthenticationData(), mapNotify.getAuthenticationData());
         assertEquals(mr.getKeyId(), mapNotify.getKeyId());
@@ -126,7 +125,7 @@ public class MapServerTest extends BaseTestCase {
 
         addDefaultPutAndGetExpectations(eid, 32);
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterBuilder.build());
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false);
 
         EidToLocatorRecord actualEidToLocator = mapNotify.getEidToLocatorRecord().get(0);
         assertEquals(LispAFIConvertor.toContainer(eid), actualEidToLocator.getLispAddressContainer());
@@ -149,7 +148,7 @@ public class MapServerTest extends BaseTestCase {
 
         addDefaultPutAndGetExpectations(eid, mask);
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mr);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mr, false);
         assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("10.31.0.5")), mapNotify.getEidToLocatorRecord().get(0)
                 .getLispAddressContainer());
         ArrayAssert.assertEquals(mr.getAuthenticationData(), mapNotify.getAuthenticationData());
@@ -175,7 +174,7 @@ public class MapServerTest extends BaseTestCase {
 
         MapRegister mapRegister = mapRegisterBuilder.build();
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister, false);
         assertEquals(LispAFIConvertor.toContainer(addr), mapNotify.getEidToLocatorRecord().get(0).getLispAddressContainer());
         ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
         assertEquals(mapRegister.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
@@ -200,7 +199,7 @@ public class MapServerTest extends BaseTestCase {
 
         MapRegister mapRegister = mapRegisterBuilder.build();
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister, false);
         assertEquals(LispAFIConvertor.toContainer(addr), mapNotify.getEidToLocatorRecord().get(0).getLispAddressContainer());
         ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
         assertEquals(mapRegister.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
@@ -223,7 +222,7 @@ public class MapServerTest extends BaseTestCase {
 
         addDefaultPutAndGetExpectations(eid, mask);
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mr);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mr, false);
         assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("10.31.0.5")), mapNotify.getEidToLocatorRecord().get(0)
                 .getLispAddressContainer());
         ArrayAssert.assertEquals(mr.getAuthenticationData(), mapNotify.getAuthenticationData());
@@ -247,7 +246,7 @@ public class MapServerTest extends BaseTestCase {
 
         addDefaultPutAndGetExpectations(eid, mask);
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mr);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mr, false);
         assertEquals(LispAFIConvertor.toContainer(LispAFIConvertor.asIPAfiAddress("10.31.0.5")), mapNotify.getEidToLocatorRecord().get(0)
                 .getLispAddressContainer());
         ArrayAssert.assertEquals(mr.getAuthenticationData(), mapNotify.getAuthenticationData());
@@ -273,7 +272,7 @@ public class MapServerTest extends BaseTestCase {
 
         MapRegister mapRegister = mapRegisterBuilder.build();
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister, false);
         assertEquals(LispAFIConvertor.toContainer(addr), mapNotify.getEidToLocatorRecord().get(0).getLispAddressContainer());
         ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
         assertEquals(mapRegister.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
@@ -298,7 +297,7 @@ public class MapServerTest extends BaseTestCase {
 
         MapRegister mapRegister = mapRegisterBuilder.build();
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister, false);
         assertEquals(LispAFIConvertor.toContainer(addr), mapNotify.getEidToLocatorRecord().get(0).getLispAddressContainer());
         ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
         assertEquals(mapRegister.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
@@ -323,7 +322,7 @@ public class MapServerTest extends BaseTestCase {
 
         MapRegister mapRegister = mapRegisterBuilder.build();
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister, false);
         assertEquals(LispAFIConvertor.toContainer(addr), mapNotify.getEidToLocatorRecord().get(0).getLispAddressContainer());
         ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
         assertEquals(mapRegister.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
@@ -348,7 +347,7 @@ public class MapServerTest extends BaseTestCase {
 
         MapRegister mapRegister = mapRegisterBuilder.build();
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister, false);
         assertEquals(LispAFIConvertor.toContainer(addr), mapNotify.getEidToLocatorRecord().get(0).getLispAddressContainer());
         ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
         assertEquals(mapRegister.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
@@ -378,7 +377,7 @@ public class MapServerTest extends BaseTestCase {
 
         MapRegister mapRegister = mapRegisterBuilder.build();
 
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister, false);
         assertEquals(LispAFIConvertor.toContainer(eid), mapNotify.getEidToLocatorRecord().get(0).getLispAddressContainer());
         assertEquals(LispAFIConvertor.toContainer(addr), mapNotify.getEidToLocatorRecord().get(1).getLispAddressContainer());
         ArrayAssert.assertEquals(mapRegister.getAuthenticationData(), mapNotify.getAuthenticationData());
@@ -405,7 +404,7 @@ public class MapServerTest extends BaseTestCase {
 
         mapRegisterBuilder.getEidToLocatorRecord().add(recordBuilder.build());
 
-        testedMapServer.handleMapRegister(mapRegisterBuilder.build());
+        testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false);
 
         MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
         assertEquals(1, entries.length);
@@ -440,7 +439,7 @@ public class MapServerTest extends BaseTestCase {
 
         mapRegisterBuilder.getEidToLocatorRecord().add(recordBuilder.build());
 
-        testedMapServer.handleMapRegister(mapRegisterBuilder.build());
+        testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false);
 
         MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
         assertEquals(2, entries.length);
@@ -470,6 +469,8 @@ public class MapServerTest extends BaseTestCase {
 
     @Test
     public void handleMapRegister__TestDontOverwrite() throws Exception {
+        int hc = LispAFIConvertor.toContainer(rloc).getAddress().hashCode();
+
         addDefaultPutAndGetExpectations(eid, 32);
         testedMapServer.setOverwrite(false);
 
@@ -478,7 +479,7 @@ public class MapServerTest extends BaseTestCase {
         MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
         assertEquals(1, entries.length);
 
-        assertEquals(String.valueOf(rloc.hashCode()), entries[0].getKey());
+        assertEquals(String.valueOf(hc), entries[0].getKey());
         assertEquals(LispAFIConvertor.toContainer(rloc), ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(0)
                 .getLispAddressContainer());
     }
@@ -493,7 +494,7 @@ public class MapServerTest extends BaseTestCase {
         mapRegisterBuilder = getDefaultMapRegisterBuilder();
         mapRegisterBuilder.getEidToLocatorRecord().add(recordBuilder.build());
 
-        testedMapServer.handleMapRegister(mapRegisterBuilder.build());
+        testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false);
     }
 
     @Test
@@ -519,7 +520,7 @@ public class MapServerTest extends BaseTestCase {
         mapRegisterBuilder.getEidToLocatorRecord().add(etlrBuilder.build());
         mapRegisterBuilder.getEidToLocatorRecord().add(etlr2Builder.build());
         addDefaultPutAndGetExpectations(address, 32);
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterBuilder.build());
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false);
 
         assertEquals(LispAFIConvertor.toContainer(rloc1), mapNotify.getEidToLocatorRecord().get(0).getLocatorRecord().get(0)
                 .getLispAddressContainer());
@@ -535,7 +536,7 @@ public class MapServerTest extends BaseTestCase {
     public void handleMapRegisterIpv4__ChekWrongPassword() throws Exception {
 
         addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32, 0, 31, "bla");
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication, false);
         assertEquals(null, mapNotify);
     }
 
@@ -544,7 +545,7 @@ public class MapServerTest extends BaseTestCase {
 
         addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32, 30, 25, "password");
         addPutExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32);
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication, false);
         assertEquals(mapRegisterWithAuthentication.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
         assertEquals(mapRegisterWithAuthentication.getKeyId(), mapNotify.getKeyId());
         assertEquals(mapRegisterWithAuthentication.getNonce(), mapNotify.getNonce());
@@ -554,7 +555,7 @@ public class MapServerTest extends BaseTestCase {
     public void handleMapRegisterIpv4__ChcekNoPassword() throws Exception {
 
         addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32, 30, 0, "password");
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication, false);
         assertEquals(null, mapNotify);
     }
 
@@ -562,17 +563,18 @@ public class MapServerTest extends BaseTestCase {
     public void handleMapRegisterIpv4__ChcekNoreturn() throws Exception {
 
         addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32);
-        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication, false);
         assertEquals(mapNotify, null);
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void handleAddAuthenticationKey() throws Exception {
         String password = "pass";
         IMappingServiceKey key = getDefualtKey();
         oneOf(lispDAO).put(weq(key),
                 weq((MappingEntry<String>[]) (Arrays.asList(new MappingEntry<String>(AbstractLispComponent.PASSWORD_SUBKEY, password)).toArray())));
-        assertEquals(true, testedMapServer.addAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask(), password));
+        testedMapServer.addAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask(), password);
     }
 
     @Test
@@ -598,7 +600,7 @@ public class MapServerTest extends BaseTestCase {
     public void handleRemoveAuthenticationKey() throws Exception {
         IMappingServiceKey key = getDefualtKey();
         oneOf(lispDAO).removeSpecific(weq(key), with(AbstractLispComponent.PASSWORD_SUBKEY));
-        assertEquals(true, testedMapServer.removeAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask()));
+        testedMapServer.removeAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask());
     }
 
     private void addDefaultPutAndGetExpectations(LispAFIAddress addr, int mask) {