import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
import org.opendaylight.lispflowmapping.implementation.MappingService;
import org.opendaylight.lispflowmapping.implementation.MappingSystem;
import org.opendaylight.lispflowmapping.implementation.mdsal.AuthenticationKeyDataListener;
-import org.opendaylight.lispflowmapping.implementation.mdsal.DataStoreBackEnd;
import org.opendaylight.lispflowmapping.implementation.mdsal.MappingDataListener;
import org.opendaylight.lispflowmapping.implementation.util.DSBEInputUtil;
import org.opendaylight.lispflowmapping.implementation.util.RPCInputConvertorUtil;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
import org.opendaylight.lispflowmapping.interfaces.dao.SubKeys;
import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.type.MappingData;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
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.MappingAuthkey;
+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.lisp.proto.rev151105.mapping.record.container.MappingRecord;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container
- .MappingRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeysInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.OdlMappingserviceService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeyInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.RemoveKeysInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingsInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container
- .MappingAuthkey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container
- .MappingAuthkeyBuilder;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@RunWith(MockitoJUnitRunner.class)
public class MappingServiceTest {
- @InjectMocks private static MappingService mappingService;
@Mock(name = "mappingSystem") private static MappingSystem mappingSystem;
@Mock(name = "dsbe") private static DataStoreBackEnd dsbe;
- @Mock(name = "mappingServiceRpc") private static BindingAwareBroker
- .RpcRegistration<OdlMappingserviceService> mappingServiceRpc;
@Mock(name = "keyListener") private static AuthenticationKeyDataListener keyListener;
@Mock(name = "mappingListener") private static MappingDataListener mappingListener;
+ private final DataBroker dataBroker = Mockito.mock(DataBroker.class);
+ private final NotificationPublishService notificationPublishService = Mockito
+ .mock(NotificationPublishService.class);
+ private final ILispDAO lispDAO = Mockito.mock(ILispDAO.class);
+
+ @InjectMocks
+ MappingService mappingService = new MappingService(dataBroker,
+ notificationPublishService, lispDAO);
+
private static final String IPV4_STRING = "1.2.3.0";
private static final Eid IPV4_EID = LispAddressUtil.asIpv4Eid(IPV4_STRING);
.setKeyType(1).build();
private static final SiteId SITE_ID = new SiteId(new byte[] {0, 1, 2, 3, 4, 5, 6, 7});
private static final XtrId XTR_ID = new XtrId(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
- private static final Object DUMMY_OBJECT = "dummy_object";
+ private static final MappingData DUMMY_MAPPING = new MappingData(MappingOrigin.Southbound, null);
/**
* Tests {@link MappingService#addKey} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void addKeyTest() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#addKey} method with null MappingAuthkey.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void addKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#addMapping} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void addMappingTest() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#getKey} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void getKeyTest() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#getKey} method with null MappingAuthkey.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void getKeyTest_withNullMappingAuthkey() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#getMapping} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void getMappingTest() throws ExecutionException, InterruptedException {
// input
final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
- final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().build();
+ final MappingData mappingData = getDefaultMappingData(MappingOrigin.Southbound);
+ final MappingRecord nonBinaryMappingRecord = getDefaultMappingRecordBuilder()
+ .setEid(LispAddressUtil.toEid(new Ipv4Address(IPV4_STRING), null)).build();
- Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingRecord);
+ Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingData);
final RpcResult<GetMappingOutput> rpc = RpcResultBuilder
- .success(new GetMappingOutputBuilder().setMappingRecord(mappingRecord)).build();
+ .success(new GetMappingOutputBuilder().setMappingRecord(nonBinaryMappingRecord)).build();
//result
- final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
+ final Future<RpcResult<GetMappingOutput>> result = mappingService.getMapping(getMappingInput);
final RpcResult<GetMappingOutput> rpcResult = result.get();
assertEquals(rpc.getResult(), rpcResult.getResult());
/**
* Tests {@link MappingService#getMapping} method with null MappingRecord.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#removeKey} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void removeKeyTest() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#removeMapping} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void removeMappingTest() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#updateKey} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void updateKeyTest() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#updateKey} method with null MappingAuthkey.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void updateKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#updateMapping} method.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void updateMappingTest() throws ExecutionException, InterruptedException {
/**
* Tests {@link MappingService#addMapping} method from southbound.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void addMappingTest_fromSouthbound() throws ExecutionException, InterruptedException {
// input
- final MappingRecord data = getDefaultMappingRecordBuilder()
+ final MappingRecord record = getDefaultMappingRecordBuilder()
.setXtrId(XTR_ID).build();
+ final MappingData data = getDefaultMappingData(MappingOrigin.Southbound, record);
mappingService.addMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data);
Mockito.verify(mappingSystem).addMapping(MappingOrigin.Southbound, IPV4_EID, data);
Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, IPV4_EID, SITE_ID, data));
- Mockito.verify(dsbe).addXtrIdMapping(DSBEInputUtil.toXtrIdMapping(data));
}
/**
* Tests {@link MappingService#addMapping} method from northbound.
- *
- * @throws ExecutionException
- * @throws InterruptedException
*/
@Test
public void addMappingTest_fromNorthbound() throws ExecutionException, InterruptedException {
// input
final MappingOrigin origin = MappingOrigin.Northbound;
- final MappingRecord data = getDefaultMappingRecordBuilder()
+ final MappingRecord record = getDefaultMappingRecordBuilder()
.setXtrId(XTR_ID).build();
+ final MappingData data = getDefaultMappingData(origin, record);
mappingService.addMapping(origin, IPV4_EID, SITE_ID, data);
Mockito.verify(dsbe).addMapping(DSBEInputUtil.toMapping(origin, IPV4_EID, SITE_ID, data));
@Test
public void getMappingTest_withOriginAndEid() {
Mockito.when(mappingSystem.getMapping(Mockito.any(MappingOrigin.class), Mockito.any(Eid.class)))
- .thenReturn(DUMMY_OBJECT);
- assertEquals(DUMMY_OBJECT, mappingService.getMapping(MappingOrigin.Northbound, IPV4_EID));
+ .thenReturn(DUMMY_MAPPING);
+ assertEquals(DUMMY_MAPPING, mappingService.getMapping(MappingOrigin.Northbound, IPV4_EID));
}
/**
*/
@Test
public void getMappingTest_withEid() {
- Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
- assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID));
+ Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class))).thenReturn(DUMMY_MAPPING);
+ assertEquals(DUMMY_MAPPING, mappingService.getMapping(IPV4_EID));
}
/**
*/
@Test
public void getMappingTest_withSrcAndDstEid() {
- Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class), Mockito.any(Eid.class))).thenReturn(DUMMY_OBJECT);
- assertEquals(DUMMY_OBJECT, mappingService.getMapping(IPV4_EID, IPV4_EID));
+ Mockito.when(mappingSystem.getMapping(Mockito.any(Eid.class), Mockito.any(Eid.class)))
+ .thenReturn(DUMMY_MAPPING);
+ assertEquals(DUMMY_MAPPING, mappingService.getMapping(IPV4_EID, IPV4_EID));
}
/**
*/
@Test
public void addDataTest() {
- mappingService.addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
- Mockito.verify(mappingSystem).addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_OBJECT);
+ mappingService.addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_MAPPING);
+ Mockito.verify(mappingSystem).addData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD, DUMMY_MAPPING);
}
/**
@Test
public void getDataTest() {
Mockito.when(mappingSystem.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD))
- .thenReturn(DUMMY_OBJECT);
- assertEquals(DUMMY_OBJECT, mappingService.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD));
+ .thenReturn(DUMMY_MAPPING);
+ assertEquals(DUMMY_MAPPING, mappingService.getData(MappingOrigin.Northbound, IPV4_EID, SubKeys.RECORD));
}
/**
@Test
public void close() throws Exception {
mappingService.close();
- Mockito.verify(mappingServiceRpc).close();
Mockito.verify(keyListener).closeDataChangeListener();
Mockito.verify(mappingListener).closeDataChangeListener();
}
assertNull(mappingService.getAllMappings());
}
+ private static MappingData getDefaultMappingData(MappingOrigin origin) {
+ return getDefaultMappingData(origin, null);
+ }
+
+ private static MappingData getDefaultMappingData(MappingOrigin origin, MappingRecord mappingRecord) {
+ if (mappingRecord == null) {
+ mappingRecord = getDefaultMappingRecordBuilder().build();
+ }
+ return new MappingData(origin, mappingRecord, System.currentTimeMillis());
+ }
+
private static MappingRecordBuilder getDefaultMappingRecordBuilder() {
return new MappingRecordBuilder()
.setAction(MappingRecord.Action.NoAction)
.setRecordTtl(60)
.setEid(IPV4_EID);
}
-}
+}
\ No newline at end of file