Search in sources :

Example 1 with NameGenResponse

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;
}
Also used : NameGenResponseError(org.onap.namingservice.model.NameGenResponseError) NameGenResponse(org.onap.namingservice.model.NameGenResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with NameGenResponse

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) NameGenResponse(org.onap.namingservice.model.NameGenResponse) HttpEntity(org.springframework.http.HttpEntity) BadResponseException(org.onap.so.client.exception.BadResponseException) NameGenRequest(org.onap.namingservice.model.NameGenRequest) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Example 3 with NameGenResponse

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");
}
Also used : NameGenResponse(org.onap.namingservice.model.NameGenResponse) ResponseEntity(org.springframework.http.ResponseEntity) Element(org.onap.namingservice.model.Element) NameGenRequest(org.onap.namingservice.model.NameGenRequest) List(java.util.List) Test(org.junit.Test)

Example 4 with NameGenResponse

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, "");
}
Also used : NameGenResponse(org.onap.namingservice.model.NameGenResponse) ResponseEntity(org.springframework.http.ResponseEntity) Respelement(org.onap.namingservice.model.Respelement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with NameGenResponse

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");
}
Also used : NameGenResponse(org.onap.namingservice.model.NameGenResponse) ResponseEntity(org.springframework.http.ResponseEntity) Respelement(org.onap.namingservice.model.Respelement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

NameGenResponse (org.onap.namingservice.model.NameGenResponse)8 Test (org.junit.Test)5 ResponseEntity (org.springframework.http.ResponseEntity)5 Respelement (org.onap.namingservice.model.Respelement)4 ArrayList (java.util.ArrayList)3 NameGenRequest (org.onap.namingservice.model.NameGenRequest)2 NameGenResponseError (org.onap.namingservice.model.NameGenResponseError)2 BadResponseException (org.onap.so.client.exception.BadResponseException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 Element (org.onap.namingservice.model.Element)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)1