Prepare the YANG models for RESTCONF
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / lisp / MapServerTest.java
index a7d096ca60da1a1afa31018f810dbefff5422d76..775639180c8eb2cf2360949f9424f1b7dacb0a35 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Contextream, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -11,12 +11,10 @@ package org.opendaylight.lispflowmapping.implementation.lisp;
 import static org.junit.Assert.assertEquals;
 
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Arrays;
 
 import junitx.framework.ArrayAssert;
 
-import org.eclipse.osgi.baseadaptor.bundlefile.MRUBundleFileList;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.lispflowmapping.implementation.LispMappingService;
@@ -26,28 +24,26 @@ import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
 import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
 import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry;
-import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceValue;
+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;
-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;
 
@@ -62,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>());
@@ -85,25 +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("value", entries[0].getKey());
-        assertEquals(rloc, ((MappingServiceValue) entries[0].getValue()).getRlocs().get(0).getRecord().getLispAddressContainer().getAddress());
+        assertEquals(AbstractLispComponent.ADDRESS_SUBKEY, entries[0].getKey());
+        assertEquals(1, ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().size());
+        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());
@@ -128,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());
@@ -151,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());
@@ -177,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());
@@ -202,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());
@@ -225,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());
@@ -249,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());
@@ -275,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());
@@ -300,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());
@@ -325,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());
@@ -350,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());
@@ -380,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());
@@ -407,24 +404,103 @@ 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);
 
-        assertEquals("value", entries[0].getKey());
-        assertEquals(LispAFIConvertor.toContainer(rloc0), ((MappingServiceValue) entries[0].getValue()).getRlocs().get(0).getRecord()
+        assertEquals(AbstractLispComponent.ADDRESS_SUBKEY, entries[0].getKey());
+        assertEquals(LispAFIConvertor.toContainer(rloc0), ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(0)
                 .getLispAddressContainer());
-        assertEquals(LispAFIConvertor.toContainer(rloc1), ((MappingServiceValue) entries[0].getValue()).getRlocs().get(1).getRecord()
+        assertEquals(LispAFIConvertor.toContainer(rloc1), ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(1)
                 .getLispAddressContainer());
 
     }
 
     @Test
-    public void handleMapRegister__MultipleEIDs() throws Exception {
+    public void handleMapRegister__MultipleTypes() throws Exception {
         addDefaultPutAndGetExpectations(eid, 32);
 
+        mapRegisterBuilder = getDefaultMapRegisterBuilder();
         LispAFIAddress rloc0 = rloc;
+        // LispAFIAddress rloc1 =
+        // LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:7");
+        String subkey = "bla";
+        LispAFIAddress rloc1 = LispAFIConvertor
+                .asKeyValue(subkey, LispAFIConvertor.toPrimitive(LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:7")));
+        EidToLocatorRecordBuilder recordBuilder = getDefaultEidToLocatorBuilder();
+        recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
+        LocatorRecordBuilder locatorBuilder1 = getDefaultLocatorBuilder();
+        locatorBuilder1.setLispAddressContainer(LispAFIConvertor.toContainer(rloc0));
+        LocatorRecordBuilder locatorBuilder2 = getDefaultLocatorBuilder();
+        locatorBuilder2.setLispAddressContainer(LispAFIConvertor.toContainer(rloc1));
+        recordBuilder.getLocatorRecord().add(locatorBuilder1.build());
+        recordBuilder.getLocatorRecord().add(locatorBuilder2.build());
+
+        mapRegisterBuilder.getEidToLocatorRecord().add(recordBuilder.build());
+
+        testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false);
+
+        MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
+        assertEquals(2, entries.length);
+
+        assertEquals(AbstractLispComponent.ADDRESS_SUBKEY, entries[0].getKey());
+        assertEquals(subkey, entries[1].getKey());
+        assertEquals(LispAFIConvertor.toContainer(rloc0), ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(0)
+                .getLispAddressContainer());
+        assertEquals(LispAFIConvertor.toContainer(rloc1), ((MappingServiceRLOCGroup) entries[1].getValue()).getRecords().get(0)
+                .getLispAddressContainer());
+
+    }
+
+    @Test
+    public void handleMapRegister__TestOverwrite() throws Exception {
+        addDefaultPutAndGetExpectations(eid, 32);
+
+        addEidToLocatorRecord();
+
+        MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
+        assertEquals(1, entries.length);
+
+        assertEquals(AbstractLispComponent.ADDRESS_SUBKEY, entries[0].getKey());
+        assertEquals(LispAFIConvertor.toContainer(rloc), ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(0)
+                .getLispAddressContainer());
+    }
+
+    @Test
+    public void handleMapRegister__TestDontOverwrite() throws Exception {
+        int hc = LispAFIConvertor.toContainer(rloc).getAddress().hashCode();
+
+        addDefaultPutAndGetExpectations(eid, 32);
+        testedMapServer.setOverwrite(false);
+
+        addEidToLocatorRecord();
+
+        MappingEntry<?>[] entries = mappingEntriesSaver.lastValue;
+        assertEquals(1, entries.length);
+
+        assertEquals(String.valueOf(hc), entries[0].getKey());
+        assertEquals(LispAFIConvertor.toContainer(rloc), ((MappingServiceRLOCGroup) entries[0].getValue()).getRecords().get(0)
+                .getLispAddressContainer());
+    }
+
+    private void addEidToLocatorRecord() {
+        EidToLocatorRecordBuilder recordBuilder = getDefaultEidToLocatorBuilder();
+        recordBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(eid));
+        LocatorRecordBuilder locatorBuilder = getDefaultLocatorBuilder();
+        locatorBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(rloc));
+        recordBuilder.getLocatorRecord().add(locatorBuilder.build());
+
+        mapRegisterBuilder = getDefaultMapRegisterBuilder();
+        mapRegisterBuilder.getEidToLocatorRecord().add(recordBuilder.build());
+
+        testedMapServer.handleMapRegister(mapRegisterBuilder.build(), false);
+    }
+
+    @Test
+    public void handleMapRegister__MultipleEIDs() throws Exception {
+        addDefaultPutAndGetExpectations(eid, 32);
+
         LispAFIAddress rloc1 = LispAFIConvertor.asIPv6AfiAddress("0:0:0:0:0:0:0:7");
         mapRegisterBuilder = getDefaultMapRegisterBuilder();
         EidToLocatorRecordBuilder etlrBuilder = getDefaultEidToLocatorBuilder();
@@ -444,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());
@@ -456,132 +532,82 @@ public class MapServerTest extends BaseTestCase {
 
     }
 
-    // @Test
-    // public void handleMapRegisterIpv4__ChekWrongPassword() throws Exception {
-    //
-    // addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 0, 31,
-    // "bla");
-    // MapNotify mapNotify =
-    // testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
-    // assertEquals(null, mapNotify);
-    // }
-    //
-    // @Test
-    // public void handleMapRegisterIpv4__ChcekNoPasswordAndThenPassword()
-    // throws Exception {
-    //
-    // addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 30, 25,
-    // "password");
-    // addPutExpectations(new LispIpv4Address("153.16.254.1"), 32);
-    // MapNotify mapNotify =
-    // testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
-    // assertEquals(mapRegisterWithAuthentication.getEidToLocatorRecords(),
-    // mapNotify.getEidToLocatorRecords());
-    // assertEquals(mapRegisterWithAuthentication.getKeyId(),
-    // mapNotify.getKeyId());
-    // assertEquals(mapRegisterWithAuthentication.getNonce(),
-    // mapNotify.getNonce());
-    // }
-    //
-    // @Test
-    // public void handleMapRegisterIpv4__ChcekNoPassword() throws Exception {
-    //
-    // addGetExpectations(new LispIpv4Address("153.16.254.1"), 32, 30, 0,
-    // "password");
-    // MapNotify mapNotify =
-    // testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
-    // assertEquals(null, mapNotify);
-    // }
-    //
-    // @Test
-    // public void handleMapRegisterIpv4__ChcekNoreturn() throws Exception {
-    //
-    // addGetExpectations(new LispIpv4Address("153.16.254.1"), 32);
-    // MapNotify mapNotify =
-    // testedMapServer.handleMapRegister(mapRegisterWithAuthentication);
-    // assertEquals(mapNotify, null);
-    // }
-    //
-    // @Test
-    // public void handleAddAuthenticationKey() throws Exception {
-    // IMappingServiceKey key = getDefualtKey();
-    // MappingServiceValue value = getDefualtValue();
-    // MappingEntry<MappingServiceValue> mappingEntry = new
-    // MappingEntry<MappingServiceValue>("value", value);
-    // oneOf(lispDAO).get(weq(key));
-    // oneOf(lispDAO).put(weq(key), weq(convertToArray(mappingEntry)));
-    // assertEquals(true, testedMapServer.addAuthenticationKey(eid,
-    // key.getMask(), value.getKey()));
-    // }
-    //
-    // @Test
-    // public void handleGetAuthenticationKey() throws Exception {
-    // IMappingServiceKey key = getDefualtKey();
-    // MappingServiceValue value = getDefualtValue();
-    // Map<String, MappingServiceValue> map = new HashMap<String,
-    // MappingServiceValue>();
-    // map.put("value", value);
-    // atLeast(1).of(lispDAO).get(weq(key));
-    // ret(map);
-    // assertEquals(value.getKey(), testedMapServer.getAuthenticationKey(eid,
-    // key.getMask()));
-    // }
-    //
-    // @Test
-    // public void handleGetAuthenticationKeyNoIteration() throws Exception {
-    // testedMapServer.setShouldIterateMask(false);
-    // IMappingServiceKey key = getDefualtKey();
-    // IMappingServiceKey passKey = getKey(30);
-    // MappingServiceValue value = getDefualtValue();
-    // Map<String, MappingServiceValue> map = new HashMap<String,
-    // MappingServiceValue>();
-    // map.put("value", value);
-    // oneOf(lispDAO).get(weq(key));
-    // allowing(lispDAO).get(weq(passKey));
-    // ret(map);
-    // assertEquals(null, testedMapServer.getAuthenticationKey(eid,
-    // key.getMask()));
-    // }
-    //
-    // @Test
-    // public void handleRemoveAuthenticationKey() throws Exception {
-    // IMappingServiceKey key = getDefualtKey();
-    // MappingServiceValue value = new MappingServiceValue();
-    // Map<String, MappingServiceValue> map = new HashMap<String,
-    // MappingServiceValue>();
-    // map.put("value", value);
-    // oneOf(lispDAO).get(weq(key));
-    // ret(map);
-    // oneOf(lispDAO).remove(weq(key));
-    // assertEquals(true, testedMapServer.removeAuthenticationKey(eid,
-    // key.getMask()));
-    // }
-    //
-    // @Test
-    // public void handleRemoveAuthenticationKeyWhereKeyDosntExist() throws
-    // Exception {
-    // IMappingServiceKey key = getDefualtKey();
-    // MappingServiceValue value = new MappingServiceValue();
-    // Map<String, MappingServiceValue> map = new HashMap<String,
-    // MappingServiceValue>();
-    // map.put("value", value);
-    // oneOf(lispDAO).get(weq(key));
-    // assertEquals(false, testedMapServer.removeAuthenticationKey(eid,
-    // key.getMask()));
-    // }
+    @Test
+    public void handleMapRegisterIpv4__ChekWrongPassword() throws Exception {
+
+        addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32, 0, 31, "bla");
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication, false);
+        assertEquals(null, mapNotify);
+    }
+
+    @Test
+    public void handleMapRegisterIpv4__ChcekNoPasswordAndThenPassword() throws Exception {
+
+        addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32, 30, 25, "password");
+        addPutExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32);
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication, false);
+        assertEquals(mapRegisterWithAuthentication.getEidToLocatorRecord(), mapNotify.getEidToLocatorRecord());
+        assertEquals(mapRegisterWithAuthentication.getKeyId(), mapNotify.getKeyId());
+        assertEquals(mapRegisterWithAuthentication.getNonce(), mapNotify.getNonce());
+    }
+
+    @Test
+    public void handleMapRegisterIpv4__ChcekNoPassword() throws Exception {
+
+        addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32, 30, 0, "password");
+        MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegisterWithAuthentication, false);
+        assertEquals(null, mapNotify);
+    }
+
+    @Test
+    public void handleMapRegisterIpv4__ChcekNoreturn() throws Exception {
+
+        addGetExpectations(LispAFIConvertor.asIPAfiAddress("153.16.254.1"), 32);
+        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())));
+        testedMapServer.addAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask(), password);
+    }
+
+    @Test
+    public void handleGetAuthenticationKey() throws Exception {
+        IMappingServiceKey key = getDefualtKey();
+        oneOf(lispDAO).getSpecific(weq(key), with(AbstractLispComponent.PASSWORD_SUBKEY));
+        ret("password");
+        assertEquals("password", testedMapServer.getAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask()));
+    }
+
+    @Test
+    public void handleGetAuthenticationKeyNoIteration() throws Exception {
+        testedMapServer.setShouldIterateMask(false);
+        IMappingServiceKey key = getDefualtKey();
+        IMappingServiceKey passKey = getKey(30);
+        oneOf(lispDAO).getSpecific(weq(key), with(AbstractLispComponent.PASSWORD_SUBKEY));
+        allowing(lispDAO).getSpecific(weq(passKey), with(AbstractLispComponent.PASSWORD_SUBKEY));
+        ret("password");
+        assertEquals(null, testedMapServer.getAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask()));
+    }
+
+    @Test
+    public void handleRemoveAuthenticationKey() throws Exception {
+        IMappingServiceKey key = getDefualtKey();
+        oneOf(lispDAO).removeSpecific(weq(key), with(AbstractLispComponent.PASSWORD_SUBKEY));
+        testedMapServer.removeAuthenticationKey(LispAFIConvertor.toContainer(eid), key.getMask());
+    }
 
     private void addDefaultPutAndGetExpectations(LispAFIAddress addr, int mask) {
         addPutExpectations(addr, mask);
         addGetExpectations(addr, mask);
     }
 
-    @SuppressWarnings("rawtypes")
-    private MappingEntry[] convertToArray(MappingEntry<MappingServiceValue> entry) {
-        MappingEntry[] arr = new MappingEntry[1];
-        arr[0] = entry;
-        return arr;
-    }
-
     private void addGetExpectations(LispAFIAddress address, int mask) {
         addGetExpectations(address, mask, 0, 0, "password");
     }
@@ -593,22 +619,23 @@ public class MapServerTest extends BaseTestCase {
 
     private void addGetExpectations(LispAFIAddress address, int mask, int withoutPassword, int withPassword, String password) {
         if (withoutPassword > 0) {
-            Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
-            result.put("value", new MappingServiceValue());
+            String result = null;
+            result = null;
             allowing(lispDAO).getSpecific(
-                    with(MappingServiceKeyUtil.generateMappingServiceKey(LispAFIConvertor.toContainer(address), withoutPassword)), with("value"));
+                    with(MappingServiceKeyUtil.generateMappingServiceKey(LispAFIConvertor.toContainer(address), withoutPassword)), with("password"));
             ret(result);
         }
         if (withPassword > 0) {
-            Map<String, MappingServiceValue> result = new HashMap<String, MappingServiceValue>();
-            result.put("value", new MappingServiceValue());
-            result.get("value").setKey(password);
-            allowing(lispDAO).get(with(MappingServiceKeyUtil.generateMappingServiceKey(LispAFIConvertor.toContainer(address), withPassword)));
+            String result = null;
+            result = password;
+            allowing(lispDAO).getSpecific(with(MappingServiceKeyUtil.generateMappingServiceKey(LispAFIConvertor.toContainer(address), withPassword)),
+                    with("password"));
             ret(result);
         }
         for (int i = mask; i >= 0; i--) {
-            allowing(lispDAO).get(with(MappingServiceKeyUtil.generateMappingServiceKey(LispAFIConvertor.toContainer(address), i)));
-            ret(new HashMap<String, MappingServiceValue>());
+            allowing(lispDAO).getSpecific(with(MappingServiceKeyUtil.generateMappingServiceKey(LispAFIConvertor.toContainer(address), i)),
+                    with("password"));
+            ret(null);
         }
     }
 
@@ -621,13 +648,6 @@ public class MapServerTest extends BaseTestCase {
         return key;
     }
 
-    private MappingServiceValue getDefualtValue() {
-        MappingServiceValue value = new MappingServiceValue();
-        String password = "pass";
-        value.setKey(password);
-        return value;
-    }
-
     private MapRegisterBuilder getDefaultMapRegisterBuilder() {
         MapRegisterBuilder mrb = new MapRegisterBuilder();
         mrb.setKeyId((short) 0);