Search in sources :

Example 1 with Assertions.catchThrowable

use of org.assertj.core.api.Assertions.catchThrowable in project riposte by Nike-Inc.

the class RoutingHandlerTest method doChannelRead_HttpRequest_throws_exception_when_failed_decoder_result.

@Test
public void doChannelRead_HttpRequest_throws_exception_when_failed_decoder_result() {
    // given
    HttpRequest msgMock = mock(HttpRequest.class);
    Throwable decoderFailureCauseMock = mock(Throwable.class);
    DecoderResult decoderResult = DecoderResult.failure(decoderFailureCauseMock);
    doReturn(decoderResult).when(msgMock).decoderResult();
    doReturn(null).when(stateMock).getRequestInfo();
    // when
    Throwable thrownException = Assertions.catchThrowable(() -> handlerSpy.doChannelRead(ctxMock, msgMock));
    // then
    assertThat(thrownException).isExactlyInstanceOf(InvalidHttpRequestException.class);
    assertThat(thrownException.getCause()).isSameAs(decoderFailureCauseMock);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DecoderResult(io.netty.handler.codec.DecoderResult) Test(org.junit.Test)

Example 2 with Assertions.catchThrowable

use of org.assertj.core.api.Assertions.catchThrowable in project riposte by Nike-Inc.

the class RoutingHandlerTest method doChannelRead_HttpRequest_throws_exception_when_content_length_header_greater_than_configured_global_request_limit.

@Test
public void doChannelRead_HttpRequest_throws_exception_when_content_length_header_greater_than_configured_global_request_limit() {
    // given
    doReturn(null).when(endpointMock).maxRequestSizeInBytesOverride();
    maxRequestSizeInBytes = 10;
    httpHeaders.set(CONTENT_LENGTH, 100);
    handlerSpy = spy(new RoutingHandler(endpoints, maxRequestSizeInBytes, distributedTracingConfigMock));
    // when
    Throwable thrownException = Assertions.catchThrowable(() -> handlerSpy.doChannelRead(ctxMock, msg));
    // then
    assertThat(thrownException).isExactlyInstanceOf(RequestTooBigException.class);
    assertThat(thrownException.getMessage()).isEqualTo("Content-Length header value exceeded configured max request size of 10");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test)

Example 3 with Assertions.catchThrowable

use of org.assertj.core.api.Assertions.catchThrowable in project riposte by Nike-Inc.

the class RoutingHandlerTest method doChannelRead_HttpRequest_endpoint_overridden_max_request_size_throws_exception.

@DataProvider(value = { "99", "101" })
@Test
public void doChannelRead_HttpRequest_endpoint_overridden_max_request_size_throws_exception(int maxRequestSize) {
    // given
    doReturn(100).when(endpointMock).maxRequestSizeInBytesOverride();
    httpHeaders.set(CONTENT_LENGTH, 101);
    handlerSpy = spy(new RoutingHandler(endpoints, maxRequestSize, distributedTracingConfigMock));
    // when
    Throwable thrownException = Assertions.catchThrowable(() -> handlerSpy.doChannelRead(ctxMock, msg));
    // then
    assertThat(thrownException).isExactlyInstanceOf(RequestTooBigException.class);
    assertThat(thrownException.getMessage()).isEqualTo("Content-Length header value exceeded configured max request size of 100");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 Test (org.junit.Test)3 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DecoderResult (io.netty.handler.codec.DecoderResult)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1