@Test public void doChannelRead_does_nothing_if_msg_is_not_LastHttpContent() throws Exception { // given Object wrongMsgType = new Object(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, wrongMsgType); // then verifyZeroInteractions(ctxMock); verifyZeroInteractions(stateMock); verifyZeroInteractions(endpointMock); verifyZeroInteractions(requestInfoSpy); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); } }
@Test public void doChannelRead_uses_custom_deserializer_if_custom_endpoint_one_is_not_null() throws Exception { // given ObjectMapper customDeserializerMock = mock(ObjectMapper.class); doReturn(customDeserializerMock).when(endpointMock).customRequestContentDeserializer(any()); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(requestInfoSpy).setupContentDeserializer(customDeserializerMock, contentTypeRef); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_uses_default_deserializer_if_custom_endpoint_one_is_null() throws Exception { // given doReturn(null).when(endpointMock).customRequestContentDeserializer(any()); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(requestInfoSpy).setupContentDeserializer(defaultHandlerDeserializerMock, contentTypeRef); 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 verify(stateMock).getEndpointForExecution(); verify(stateMock).getRequestInfo(); verifyNoMoreInteractions(stateMock); verifyNoMoreInteractions(endpointMock); verifyNoMoreInteractions(requestInfoSpy); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_uses_TypeReference_from_endpoint_requestContentType_method() throws Exception { // given TypeReference<String> customTypeReference = new TypeReference<String>() {}; doReturn(customTypeReference).when(endpointMock).requestContentType(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then ArgumentCaptor<TypeReference> typeRefArgumentCaptor = ArgumentCaptor.forClass(TypeReference.class); verify(requestInfoSpy).setupContentDeserializer(eq(defaultHandlerDeserializerMock), typeRefArgumentCaptor.capture()); TypeReference<String> actualTypeRef = typeRefArgumentCaptor.getValue(); assertThat(actualTypeRef).isSameAs(customTypeReference); assertThat(actualTypeRef).isNotSameAs(contentTypeRef); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }
@Test public void doChannelRead_does_nothing_if_requestContentType_is_null() throws Exception { // given doReturn(null).when(endpointMock).requestContentType(); // when PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg); // then verify(stateMock).getEndpointForExecution(); verify(stateMock).getRequestInfo(); verifyNoMoreInteractions(stateMock); verify(endpointMock).requestContentType(); verify(requestInfoSpy).isCompleteRequestWithAllChunks(); verifyNoMoreInteractions(endpointMock); verifyNoMoreInteractions(requestInfoSpy); assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE); }