use of org.onap.namingservice.model.NameGenResponse in project so by onap.
the class NamingClientResponseValidator method formatError.
protected String formatError(HttpStatusCodeException e) throws IOException {
ObjectMapper mapper = new ObjectMapper();
NameGenResponse errorResponse = mapper.readValue(e.getResponseBodyAsString(), NameGenResponse.class);
NameGenResponseError error = errorResponse.getError();
String errorMessageString = null;
if (error != null) {
errorMessageString = error.getMessage();
}
String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString);
logger.error(LoggingAnchor.FIVE, MessageEnum.RA_GENERAL_EXCEPTION.toString(), errorMessage, "BPMN", ErrorCode.DataError.getValue(), errorMessage);
return errorMessage;
}
use of org.onap.namingservice.model.NameGenResponse in project so by onap.
the class NamingClient method postNameGenRequest.
public String postNameGenRequest(NameGenRequest request) throws BadResponseException, IOException {
String targetUrl = env.getProperty(ENDPOINT);
HttpHeaders headers = setHeaders(env.getProperty(AUTH));
logger.info("Sending postNameGenRequest to url: {}", targetUrl);
HttpEntity<NameGenRequest> requestEntity = new HttpEntity<>(request, headers);
ResponseEntity<NameGenResponse> response;
try {
response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class);
} catch (HttpStatusCodeException e) {
throw new BadResponseException(namingClientResponseValidator.formatError(e));
}
return namingClientResponseValidator.validateNameGenResponse(response);
}
use of org.onap.namingservice.model.NameGenResponse in project so by onap.
the class NamingServiceResourcesTest method generateInstanceGroupNameTest.
@Test
public void generateInstanceGroupNameTest() throws Exception {
NameGenResponse name = new NameGenResponse();
ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
Element element = new Element();
NameGenRequest req = new NameGenRequest();
doReturn(element).when(MOCK_namingRequestObjectBuilder).elementMapper(isA(String.class), isA(String.class), isA(String.class), isA(String.class), isA(String.class));
doReturn("generatedInstanceGroupName").when(MOCK_namingClient).postNameGenRequest(isA(NameGenRequest.class));
doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenRequestMapper(isA(List.class));
String generatedName = namingServiceResources.generateInstanceGroupName(instanceGroup, "policyInstanceName", "nfNamingCode");
verify(MOCK_namingClient, times(1)).postNameGenRequest(any(NameGenRequest.class));
assertEquals(generatedName, "generatedInstanceGroupName");
}
use of org.onap.namingservice.model.NameGenResponse in project so by onap.
the class NamingClientResponseValidatorTest method validateNameGenResponseNoNameGeneratedTest.
@Test
public void validateNameGenResponseNoNameGeneratedTest() throws BadResponseException {
NameGenResponse name = new NameGenResponse();
Respelement respElement = new Respelement();
respElement.setResourceName("instance-group");
respElement.setResourceValue(instanceGroupName);
List<Respelement> respList = new ArrayList<Respelement>();
respList.add(respElement);
name.setElements(respList);
ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
String actual = responseValidator.validateNameGenResponse(resp);
assertEquals(actual, "");
}
use of org.onap.namingservice.model.NameGenResponse in project so by onap.
the class NamingClientResponseValidatorTest method validateNameGenResponseSuccessTest.
@Test
public void validateNameGenResponseSuccessTest() throws BadResponseException {
NameGenResponse name = new NameGenResponse();
Respelement respElement = new Respelement();
respElement.setResourceName("instance-group-name");
respElement.setResourceValue(instanceGroupName);
List<Respelement> respList = new ArrayList<Respelement>();
respList.add(respElement);
name.setElements(respList);
ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
String actual = responseValidator.validateNameGenResponse(resp);
assertEquals(actual, "generatedInstanceGroupName");
}
Aggregations