use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RequestInfoImplTest method setupContentDeserializer_and_getContent_sets_content_to_null_if_type_ref_is_null.
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_type_ref_is_null() throws IOException {
// given
RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
// when
requestInfo.setupContentDeserializer(new ObjectMapper(), null);
// then
assertThat(requestInfo.getContent(), nullValue());
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RequestInfoImplTest method uber_constructor_works_for_valid_values.
@Test
public void uber_constructor_works_for_valid_values() {
// given
String uri = "/some/uri/path/%24foobar%26?notused=blah";
HttpMethod method = HttpMethod.PATCH;
Charset contentCharset = CharsetUtil.US_ASCII;
HttpHeaders headers = new DefaultHttpHeaders().add("header1", "val1").add(HttpHeaders.Names.CONTENT_TYPE, "text/text charset=" + contentCharset.displayName());
QueryStringDecoder queryParams = new QueryStringDecoder(uri + "?foo=bar&secondparam=secondvalue");
Set<Cookie> cookies = new HashSet<>(Arrays.asList(new DefaultCookie("cookie1", "val1"), new DefaultCookie("cookie2", "val2")));
Map<String, String> pathParams = Arrays.stream(new String[][] { { "pathParam1", "val1" }, { "pathParam2", "val2" } }).collect(Collectors.toMap(pair -> pair[0], pair -> pair[1]));
String content = UUID.randomUUID().toString();
byte[] contentBytes = content.getBytes();
LastHttpContent chunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(contentBytes));
chunk.trailingHeaders().add("trailingHeader1", "trailingVal1");
List<HttpContent> contentChunks = Collections.singletonList(chunk);
HttpVersion protocolVersion = HttpVersion.HTTP_1_1;
boolean keepAlive = true;
boolean fullRequest = true;
boolean isMultipart = false;
// when
RequestInfoImpl<?> requestInfo = new RequestInfoImpl<>(uri, method, headers, chunk.trailingHeaders(), queryParams, cookies, pathParams, contentChunks, protocolVersion, keepAlive, fullRequest, isMultipart);
// then
assertThat("getUri should return passed in value", requestInfo.getUri(), is(uri));
assertThat("getPath did not decode as expected", requestInfo.getPath(), is("/some/uri/path/$foobar&"));
assertThat(requestInfo.getMethod(), is(method));
assertThat(requestInfo.getHeaders(), is(headers));
assertThat(requestInfo.getTrailingHeaders(), is(chunk.trailingHeaders()));
assertThat(requestInfo.getQueryParams(), is(queryParams));
assertThat(requestInfo.getCookies(), is(cookies));
assertThat(requestInfo.pathTemplate, nullValue());
assertThat(requestInfo.pathParams, is(pathParams));
assertThat(requestInfo.getRawContentBytes(), is(contentBytes));
assertThat(requestInfo.getRawContent(), is(content));
assertThat(requestInfo.content, nullValue());
assertThat(requestInfo.getContentCharset(), is(contentCharset));
assertThat(requestInfo.getProtocolVersion(), is(protocolVersion));
assertThat(requestInfo.isKeepAliveRequested(), is(keepAlive));
assertThat(requestInfo.isCompleteRequestWithAllChunks, is(fullRequest));
assertThat(requestInfo.isMultipart, is(isMultipart));
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RequestInfoImplTest method setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null.
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null() throws IOException {
// given
RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
assertThat(requestInfo.getRawContentBytes(), nullValue());
// when
requestInfo.setupContentDeserializer(new ObjectMapper(), new TypeReference<TestContentObject>() {
});
// then
assertThat(requestInfo.getContent(), nullValue());
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class NonblockingEndpointExecutionHandlerTest method doExecuteEndpointFunction_provides_friendly_exception_message_if_endpoint_execute_method_returns_null.
@Test
public void doExecuteEndpointFunction_provides_friendly_exception_message_if_endpoint_execute_method_returns_null() {
// given
doReturn(null).when(endpointMock).execute(any(RequestInfo.class), any(Executor.class), any(ChannelHandlerContext.class));
Function<Void, CompletableFuture<ResponseInfo<?>>> executeFunc = handlerSpy.doExecuteEndpointFunction(requestInfo, endpointMock, null, ctxMock);
// when
Throwable ex = catchThrowable(() -> executeFunc.apply(null));
// then
verify(endpointMock).execute(requestInfo, longRunningTaskExecutorMock, ctxMock);
assertThat(ex).isInstanceOf(NullPointerException.class).hasMessage("NonblockingEndpoint.execute() cannot return null.");
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RequestInfoSetterHandlerTest method doChannelRead_creates_and_sets_RequestInfo_on_state_and_RequestInfo_is_marked_as_complete_with_all_chunks_if_msg_is_FullHttpRequest.
@Test
public void doChannelRead_creates_and_sets_RequestInfo_on_state_and_RequestInfo_is_marked_as_complete_with_all_chunks_if_msg_is_FullHttpRequest() {
// given
FullHttpRequest msgMock = mock(FullHttpRequest.class);
String uri = "/some/url";
HttpHeaders headers = new DefaultHttpHeaders();
doReturn(uri).when(msgMock).uri();
doReturn(headers).when(msgMock).headers();
doReturn(headers).when(msgMock).trailingHeaders();
doReturn(byteBufMock).when(msgMock).content();
doReturn(false).when(byteBufMock).isReadable();
doReturn(HttpVersion.HTTP_1_1).when(msgMock).protocolVersion();
doReturn(null).when(stateMock).getRequestInfo();
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msgMock);
// then
ArgumentCaptor<RequestInfo> requestInfoArgumentCaptor = ArgumentCaptor.forClass(RequestInfo.class);
verify(stateMock).setRequestInfo(requestInfoArgumentCaptor.capture());
RequestInfo requestInfo = requestInfoArgumentCaptor.getValue();
assertThat(requestInfo.getUri()).isEqualTo(uri);
assertThat(requestInfo.isCompleteRequestWithAllChunks()).isTrue();
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Aggregations