@Test public void doChannelRead_does_nothing_if_msg_is_not_LastHttpContent() throws Exception { // given HttpContent notLastContentMsg = mock(HttpContent.class); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, notLastContentMsg); // then verifyZeroInteractions(requestInfoMock); verifyZeroInteractions(endpointMock); verifyZeroInteractions(stateMock); verifyZeroInteractions(requestValidatorMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_nothing_if_endpoint_is_null() throws Exception { // given doReturn(null).when(stateMock).getEndpointForExecution(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verifyNoMoreInteractions(requestValidatorMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_nothing_if_request_isCompleteRequestWithAllChunks_returns_false() throws Exception { // given doReturn(false).when(requestInfoMock).isCompleteRequestWithAllChunks(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verifyNoMoreInteractions(requestValidatorMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_nothing_if_endpoint_does_not_want_to_validate() throws Exception { // given doReturn(false).when(endpointMock).isValidateRequestContent(any()); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verifyNoMoreInteractions(requestValidatorMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_nothing_if_request_isContentDeserializerSetup_returns_false() throws Exception { // given doReturn(false).when(requestInfoMock).isContentDeserializerSetup(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verifyNoMoreInteractions(requestValidatorMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_calls_request_getContent_method_if_endpoint_wants_validation() throws Exception { // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(requestInfoMock).getContent(); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_nothing_if_content_is_null_and_require_content_is_false() throws Exception { // given doReturn(null).when(requestInfoMock).getContent(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verifyNoMoreInteractions(requestValidatorMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_delegates_to_async_processing_when_requested_by_endpoint() throws Exception { // given doReturn(true).when(endpointMock).shouldValidateAsynchronously(requestInfoMock); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(stateMock).addPreEndpointExecutionWorkChainSegment(any(Function.class)); verifyZeroInteractions(requestValidatorMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_validates_without_validationGroups_if_validationGroups_is_null() throws Exception { // given doReturn(null).when(endpointMock).validationGroups(any()); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(requestValidatorMock).validateRequestContent(requestInfoMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_not_call_request_getContent_method_if_endpoint_does_not_want_validation() throws Exception { // given doReturn(false).when(endpointMock).isValidateRequestContent(any()); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(requestInfoMock, never()).getContent(); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_validates_with_validationGroups_if_validationGroups_is_not_null() throws Exception { // given Class<?>[] validationGroups = new Class[]{}; doReturn(validationGroups).when(endpointMock).validationGroups(any()); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(requestValidatorMock).validateRequestContent(requestInfoMock, validationGroups); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_not_call_request_getContent_method_if_endpoint_is_null() throws Exception { // given doReturn(null).when(stateMock).getEndpointForExecution(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(requestInfoMock, never()).getContent(); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_executes_validation_synchronously_when_requested_by_endpoint() throws Exception { // given doReturn(false).when(endpointMock).shouldValidateAsynchronously(requestInfoMock); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(stateMock, never()).addPreEndpointExecutionWorkChainSegment(any(Function.class)); verify(requestValidatorMock).validateRequestContent(requestInfoMock); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); } }
@Test public void doChannelRead_throws_exception_if_content_is_null_and_endpoint_requires_content() throws Exception { // given doReturn(0).when(requestInfoMock).getRawContentLengthInBytes(); doReturn(true).when(endpointMock).isValidateRequestContent(requestInfoMock); doReturn(true).when(endpointMock).isRequireRequestContent(); // when Throwable ex = catchThrowable(() -> handler.doChannelRead(ctxMock, msg)); // then assertThat(ex) .isInstanceOf(MissingRequiredContentException.class); // then verifyNoMoreInteractions(requestValidatorMock); }