@Test public void doChannelRead_does_nothing_if_msg_is_not_HttpRequest() { // given String pathTemplate = "/some/path/with/{id}"; Collection<String> pathTemplates = new ArrayList<String>() {{ add(pathTemplate); }}; doReturn(pathTemplates).when(matcherMock).matchingPathTemplates(); HttpObject msg = mock(HttpObject.class); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg); // then verify(handlerSpy).doChannelRead(ctxMock, msg); verifyNoMoreInteractions(handlerSpy); verifyNoMoreInteractions(requestInfoMock); verifyNoMoreInteractions(stateMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_HttpRequest_under_max_global_request_size_processed_successfully() { // given doReturn(null).when(endpointMock).maxRequestSizeInBytesOverride(); maxRequestSizeInBytes = 101; httpHeaders.set(CONTENT_LENGTH, 100); handlerSpy = spy(new RoutingHandler(endpoints, maxRequestSizeInBytes)); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg); // then assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_calls_findSingleEndpointForExecution_then_sets_path_params_and_endpoint_on_state_then_returns_CONTINUE_if_msg_is_HttpRequest() { // given doReturn(Arrays.asList(defaultPath)).when(matcherMock).matchingPathTemplates(); HttpRequest msg = mock(HttpRequest.class); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg); // then verify(handlerSpy).findSingleEndpointForExecution(requestInfoMock); verify(requestInfoMock).setPathParamsBasedOnPathTemplate(defaultPath); verify(stateMock).setEndpointForExecution(endpointMock, defaultPath); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@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)); // 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"); }
@DataProvider(value = { "99", "100" }) @Test public void doChannelRead_HttpRequest_does_not_throw_TooLongFrameException_if_content_length_is_less_than_endpoint_overridden_value( int maxRequestSize ) { // given doReturn(100).when(endpointMock).maxRequestSizeInBytesOverride(); httpHeaders.set(CONTENT_LENGTH, 100); handlerSpy = spy(new RoutingHandler(endpoints, maxRequestSize)); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg); // then assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@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)); // 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"); }
@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); }
@DataProvider(value = { "true", "false" }) @Test public void doChannelRead_HttpRequest_does_not_throw_TooLongFrameException_if_content_length_header_is_missing( boolean isChunkedTransferEncoding ) { // given if (isChunkedTransferEncoding) { httpHeaders.set(TRANSFER_ENCODING, CHUNKED); } doReturn(null).when(endpointMock).maxRequestSizeInBytesOverride(); maxRequestSizeInBytes = 101; handlerSpy = spy(new RoutingHandler(endpoints, maxRequestSizeInBytes)); // when PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg); // then assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msgMock);