/*
- * 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,
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;
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;
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>());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
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();
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());
}
- // @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");
}
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);
}
}
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);