use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput in project lispflowmapping by opendaylight.
the class MappingServiceTest method getMappingTest_withNullMapRecord.
/**
* Tests {@link MappingService#getMapping} method with null MappingRecord.
*/
@Test
public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
// input
final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(null);
final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "data-missing", "No mapping was found in the mapping database").build();
final RpcError error = rpc.getErrors().iterator().next();
// result
final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
final RpcError errorResult = result.get().getErrors().iterator().next();
assertEquals(1, result.get().getErrors().size());
assertEquals(error.getMessage(), errorResult.getMessage());
assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
assertEquals(error.getCause(), errorResult.getCause());
assertEquals(error.getErrorType(), errorResult.getErrorType());
assertEquals(error.getInfo(), errorResult.getInfo());
assertEquals(error.getTag(), errorResult.getTag());
assertEquals(error.getSeverity(), errorResult.getSeverity());
assertEquals(rpc.getResult(), result.get().getResult());
assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput in project lispflowmapping by opendaylight.
the class MappingServiceTest method getMappingTest.
/**
* Tests {@link MappingService#getMapping} method.
*/
@Test
public void getMappingTest() throws ExecutionException, InterruptedException {
// input
final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
final MappingData mappingData = getDefaultMappingData();
final MappingRecord nonBinaryMappingRecord = getDefaultMappingRecordBuilder().setEid(LispAddressUtil.toEid(new Ipv4Address(IPV4_STRING), null)).build();
Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingData);
final RpcResult<GetMappingOutput> rpc = RpcResultBuilder.success(new GetMappingOutputBuilder().setMappingRecord(nonBinaryMappingRecord)).build();
// result
final Future<RpcResult<GetMappingOutput>> result = mappingService.getMapping(getMappingInput);
final RpcResult<GetMappingOutput> rpcResult = result.get();
assertEquals(rpc.getResult(), rpcResult.getResult());
assertEquals(rpc.getErrors(), rpcResult.getErrors());
assertEquals(rpc.isSuccessful(), rpcResult.isSuccessful());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.GetMappingOutput in project lispflowmapping by opendaylight.
the class MappingService method getMapping.
@Override
public Future<RpcResult<GetMappingOutput>> getMapping(GetMappingInput input) {
Preconditions.checkNotNull(input, "get-mapping RPC input must be not null!");
LOG.trace("RPC received to get the following mapping: " + input.toString());
RpcResultBuilder<GetMappingOutput> rpcResultBuilder;
MappingData reply = mappingSystem.getMapping(convertToBinaryIfNecessary(input.getEid()));
if (reply == null) {
String message = "No mapping was found in the mapping database";
rpcResultBuilder = RpcResultBuilder.<GetMappingOutput>failed().withError(RpcError.ErrorType.APPLICATION, NOT_FOUND_TAG, message);
} else {
final MappingRecord convertedReply = convertFromBinaryIfNecessary(reply.getRecord());
rpcResultBuilder = RpcResultBuilder.success(new GetMappingOutputBuilder().setMappingRecord(convertedReply));
}
return Futures.immediateFuture(rpcResultBuilder.build());
}
Aggregations