Search in sources :

Example 1 with DefaultErrorContractDTO

use of com.nike.backstopper.model.DefaultErrorContractDTO in project riposte by Nike-Inc.

the class RiposteUnhandledExceptionHandlerTest method prepareFrameworkResponseUsesErrorResponseBodyNettyAdapterWrapper.

@Test
public void prepareFrameworkResponseUsesErrorResponseBodyNettyAdapterWrapper() {
    RiposteUnhandledExceptionHandler myAdapter = new RiposteUnhandledExceptionHandler(projectApiErrors, utils);
    DefaultErrorContractDTO errorContract = new DefaultErrorContractDTO(UUID.randomUUID().toString(), Arrays.asList(projectApiErrors.getUnauthorizedApiError(), projectApiErrors.getMalformedRequestApiError()));
    ErrorResponseBody result = myAdapter.prepareFrameworkRepresentation(errorContract, 42, null, null, null);
    assertThat(result, instanceOf(ErrorResponseBodyImpl.class));
    ErrorResponseBodyImpl adapterResult = (ErrorResponseBodyImpl) result;
    assertThat(adapterResult.error_id, is(errorContract.error_id));
    assertThat(adapterResult.errors, is(errorContract.errors));
}
Also used : ErrorResponseBodyImpl(com.nike.backstopper.model.riposte.ErrorResponseBodyImpl) DefaultErrorContractDTO(com.nike.backstopper.model.DefaultErrorContractDTO) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) Test(org.junit.Test)

Example 2 with DefaultErrorContractDTO

use of com.nike.backstopper.model.DefaultErrorContractDTO in project riposte by Nike-Inc.

the class VerifyPreEndpointExecutionWorkChainComponentTest method verifyErrorReceived.

private void verifyErrorReceived(ExtractableResponse response, ApiError expectedApiError) throws IOException {
    assertThat(response.statusCode()).isEqualTo(expectedApiError.getHttpStatusCode());
    DefaultErrorContractDTO responseAsError = objectMapper.readValue(response.asString(), DefaultErrorContractDTO.class);
    assertThat(responseAsError.errors).hasSize(1);
    assertThat(responseAsError.errors.get(0).code).isEqualTo(expectedApiError.getErrorCode());
    assertThat(responseAsError.errors.get(0).message).isEqualTo(expectedApiError.getMessage());
}
Also used : DefaultErrorContractDTO(com.nike.backstopper.model.DefaultErrorContractDTO)

Example 3 with DefaultErrorContractDTO

use of com.nike.backstopper.model.DefaultErrorContractDTO in project riposte by Nike-Inc.

the class VerifyRequestAndResponseFilteringComponentTest method verifyErrorReceived.

private void verifyErrorReceived(ExtractableResponse response, ApiError expectedApiError) throws IOException {
    assertThat(response.statusCode()).isEqualTo(expectedApiError.getHttpStatusCode());
    DefaultErrorContractDTO responseAsError = objectMapper.readValue(response.asString(), DefaultErrorContractDTO.class);
    assertThat(responseAsError.errors).hasSize(1);
    assertThat(responseAsError.errors.get(0).code).isEqualTo(expectedApiError.getErrorCode());
    assertThat(responseAsError.errors.get(0).message).isEqualTo(expectedApiError.getMessage());
    assertThat(responseAsError.errors.get(0).metadata).isEqualTo(expectedApiError.getMetadata());
}
Also used : DefaultErrorContractDTO(com.nike.backstopper.model.DefaultErrorContractDTO)

Example 4 with DefaultErrorContractDTO

use of com.nike.backstopper.model.DefaultErrorContractDTO in project riposte by Nike-Inc.

the class VerifyTimeoutsAndProxyConnectionPoolingWorksComponentTest method verify_long_proxy_call_fails_with_timeout.

@Test
public void verify_long_proxy_call_fails_with_timeout() throws IOException, InterruptedException {
    String responseString = given().baseUri("http://127.0.0.1").port(proxyServerShortCallTimeoutConfig.endpointsPort()).basePath(ProxyLongDelayTestEndpoint.MATCHING_PATH).header(LongDelayTestEndpoint.DELAY_MILLIS_HEADER_KEY, String.valueOf(proxyServerShortCallTimeoutConfig.defaultCompletableFutureTimeoutInMillisForNonblockingEndpoints() + 100)).log().all().when().get().then().log().all().statusCode(SampleCoreApiError.TEMPORARY_SERVICE_PROBLEM.getHttpStatusCode()).extract().asString();
    DefaultErrorContractDTO errorContract = objectMapper.readValue(responseString, DefaultErrorContractDTO.class);
    assertThat(errorContract).isNotNull();
    assertThat(errorContract.errors.size()).isEqualTo(1);
    assertThat(errorContract.errors.get(0).code).isEqualTo(SampleCoreApiError.TEMPORARY_SERVICE_PROBLEM.getErrorCode());
}
Also used : DefaultErrorContractDTO(com.nike.backstopper.model.DefaultErrorContractDTO) Test(org.junit.Test)

Example 5 with DefaultErrorContractDTO

use of com.nike.backstopper.model.DefaultErrorContractDTO in project riposte by Nike-Inc.

the class ComponentTestUtils method verifyErrorReceived.

public static void verifyErrorReceived(String response, int responseStatusCode, ApiError expectedApiError) throws IOException {
    assertThat(responseStatusCode).isEqualTo(expectedApiError.getHttpStatusCode());
    DefaultErrorContractDTO responseAsError = objectMapper.readValue(response, DefaultErrorContractDTO.class);
    assertThat(responseAsError.errors).hasSize(1);
    assertThat(responseAsError.errors.get(0).code).isEqualTo(expectedApiError.getErrorCode());
    assertThat(responseAsError.errors.get(0).message).isEqualTo(expectedApiError.getMessage());
    assertThat(responseAsError.errors.get(0).metadata).isEqualTo(expectedApiError.getMetadata());
}
Also used : DefaultErrorContractDTO(com.nike.backstopper.model.DefaultErrorContractDTO)

Aggregations

DefaultErrorContractDTO (com.nike.backstopper.model.DefaultErrorContractDTO)11 Test (org.junit.Test)7 ApiError (com.nike.backstopper.apierror.ApiError)2 ErrorResponseBodyImpl (com.nike.backstopper.model.riposte.ErrorResponseBodyImpl)2 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SampleCoreApiError (com.nike.backstopper.apierror.sample.SampleCoreApiError)1 DefaultErrorDTO (com.nike.backstopper.model.DefaultErrorDTO)1 Pair (com.nike.internal.util.Pair)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1