Search in sources :

Example 1 with NameGenDeleteResponse

use of org.onap.namingservice.model.NameGenDeleteResponse in project so by onap.

the class NamingServiceResourcesTest method deleteInstanceGroupNameTest.

@Test
public void deleteInstanceGroupNameTest() throws Exception {
    NameGenDeleteResponse name = new NameGenDeleteResponse();
    ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
    Deleteelement deleteElement = new Deleteelement();
    deleteElement.setExternalKey(instanceGroup.getId());
    NameGenDeleteRequest req = new NameGenDeleteRequest();
    doReturn(deleteElement).when(MOCK_namingRequestObjectBuilder).deleteElementMapper(isA(String.class));
    doReturn("").when(MOCK_namingClient).deleteNameGenRequest(isA(NameGenDeleteRequest.class));
    doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenDeleteRequestMapper(isA(List.class));
    namingServiceResources.deleteInstanceGroupName(instanceGroup);
    verify(MOCK_namingClient, times(1)).deleteNameGenRequest(any(NameGenDeleteRequest.class));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Deleteelement(org.onap.namingservice.model.Deleteelement) NameGenDeleteRequest(org.onap.namingservice.model.NameGenDeleteRequest) NameGenDeleteResponse(org.onap.namingservice.model.NameGenDeleteResponse) List(java.util.List) Test(org.junit.Test)

Example 2 with NameGenDeleteResponse

use of org.onap.namingservice.model.NameGenDeleteResponse in project so by onap.

the class NamingClientResponseValidatorTest method validateNameGenDeleteResponseBadStatusTest.

@Test
public void validateNameGenDeleteResponseBadStatusTest() throws BadResponseException {
    NameGenDeleteResponse name = new NameGenDeleteResponse();
    ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
    expectedException.expect(BadResponseException.class);
    responseValidator.validateNameGenDeleteResponse(resp);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) NameGenDeleteResponse(org.onap.namingservice.model.NameGenDeleteResponse) Test(org.junit.Test)

Example 3 with NameGenDeleteResponse

use of org.onap.namingservice.model.NameGenDeleteResponse in project so by onap.

the class NamingClientResponseValidatorTest method validateNameGenDeleteResponseSuccessTest.

@Test
public void validateNameGenDeleteResponseSuccessTest() throws BadResponseException {
    NameGenDeleteResponse name = new NameGenDeleteResponse();
    ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
    String actual = responseValidator.validateNameGenDeleteResponse(resp);
    assertEquals(actual, "");
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) NameGenDeleteResponse(org.onap.namingservice.model.NameGenDeleteResponse) Test(org.junit.Test)

Example 4 with NameGenDeleteResponse

use of org.onap.namingservice.model.NameGenDeleteResponse in project so by onap.

the class NamingClientResponseValidator method validateNameGenDeleteResponse.

public String validateNameGenDeleteResponse(ResponseEntity<NameGenDeleteResponse> response) throws BadResponseException {
    if (response == null) {
        logger.error(LoggingAnchor.FIVE, MessageEnum.RA_GENERAL_EXCEPTION.toString(), NO_RESPONSE_FROM_NAMING_SERVICE, "BPMN", ErrorCode.UnknownError.getValue(), NO_RESPONSE_FROM_NAMING_SERVICE);
        throw new BadResponseException(NO_RESPONSE_FROM_NAMING_SERVICE);
    }
    int responseCode = response.getStatusCodeValue();
    String responseMessage = "";
    NameGenDeleteResponse responseBody = response.getBody();
    if (responseBody == null) {
        logger.error(LoggingAnchor.FIVE, MessageEnum.RA_GENERAL_EXCEPTION.toString(), NULL_RESPONSE_FROM_NAMING_SERVICE, "BPMN", ErrorCode.UnknownError.getValue(), NULL_RESPONSE_FROM_NAMING_SERVICE);
        throw new BadResponseException(NULL_RESPONSE_FROM_NAMING_SERVICE);
    }
    if (isHttpCodeSuccess(responseCode)) {
        logger.info("Successful Response from Naming Service");
        return responseMessage;
    } else {
        String errorMessageString = NAMING_SERVICE_ERROR;
        String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString);
        logger.error(LoggingAnchor.FIVE, MessageEnum.RA_GENERAL_EXCEPTION.toString(), errorMessage, "BPMN", ErrorCode.DataError.getValue(), errorMessage);
        throw new BadResponseException(errorMessage);
    }
}
Also used : BadResponseException(org.onap.so.client.exception.BadResponseException) NameGenDeleteResponse(org.onap.namingservice.model.NameGenDeleteResponse)

Example 5 with NameGenDeleteResponse

use of org.onap.namingservice.model.NameGenDeleteResponse in project so by onap.

the class NamingClient method deleteNameGenRequest.

public String deleteNameGenRequest(NameGenDeleteRequest request) throws BadResponseException, IOException {
    String targetUrl = env.getProperty(ENDPOINT);
    HttpHeaders headers = setHeaders(env.getProperty(AUTH));
    logger.info("Sending deleteNameGenRequest to url: {}", targetUrl);
    HttpEntity<NameGenDeleteRequest> requestEntity = new HttpEntity<>(request, headers);
    ResponseEntity<NameGenDeleteResponse> response;
    try {
        response = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, NameGenDeleteResponse.class);
    } catch (HttpStatusCodeException e) {
        throw new BadResponseException(namingClientResponseValidator.formatError(e));
    }
    return namingClientResponseValidator.validateNameGenDeleteResponse(response);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) NameGenDeleteRequest(org.onap.namingservice.model.NameGenDeleteRequest) HttpEntity(org.springframework.http.HttpEntity) NameGenDeleteResponse(org.onap.namingservice.model.NameGenDeleteResponse) BadResponseException(org.onap.so.client.exception.BadResponseException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Aggregations

NameGenDeleteResponse (org.onap.namingservice.model.NameGenDeleteResponse)5 Test (org.junit.Test)3 ResponseEntity (org.springframework.http.ResponseEntity)3 NameGenDeleteRequest (org.onap.namingservice.model.NameGenDeleteRequest)2 BadResponseException (org.onap.so.client.exception.BadResponseException)2 List (java.util.List)1 Deleteelement (org.onap.namingservice.model.Deleteelement)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)1