use of io.netty.handler.codec.http.HttpContent in project riposte by Nike-Inc.
the class RequestInfoImplTest method addContentChunk_adds_chunk_content_length_to_rawContentLengthInBytes.
@Test
public void addContentChunk_adds_chunk_content_length_to_rawContentLengthInBytes() throws IOException {
// given
RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
requestInfo.isCompleteRequestWithAllChunks = false;
String chunk1String = UUID.randomUUID().toString();
String lastChunkString = UUID.randomUUID().toString();
byte[] chunk1Bytes = chunk1String.getBytes();
byte[] lastChunkBytes = lastChunkString.getBytes();
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer(chunk1Bytes));
HttpContent lastChunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(lastChunkBytes));
// when
requestInfo.addContentChunk(chunk1);
requestInfo.addContentChunk(lastChunk);
// then
assertThat(requestInfo.contentChunks.size(), is(2));
assertThat(requestInfo.isCompleteRequestWithAllChunks(), is(true));
assertThat(requestInfo.getRawContentLengthInBytes(), is(chunk1Bytes.length + lastChunkBytes.length));
}
use of io.netty.handler.codec.http.HttpContent in project riposte by Nike-Inc.
the class RequestInfoImplTest method addContentChunk_adds_chunk_to_list_and_retains_it_for_chunks_that_are_not_the_last.
@Test
public void addContentChunk_adds_chunk_to_list_and_retains_it_for_chunks_that_are_not_the_last() {
// given
RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
requestInfo.isCompleteRequestWithAllChunks = false;
HttpContent chunk1Mock = mock(HttpContent.class);
HttpContent chunk2Mock = mock(HttpContent.class);
doReturn(mock(ByteBuf.class)).when(chunk1Mock).content();
doReturn(mock(ByteBuf.class)).when(chunk2Mock).content();
// when
requestInfo.addContentChunk(chunk1Mock);
requestInfo.addContentChunk(chunk2Mock);
// then
assertThat(requestInfo.contentChunks.size(), is(2));
assertThat(requestInfo.contentChunks.get(0), is(chunk1Mock));
assertThat(requestInfo.contentChunks.get(1), is(chunk2Mock));
assertThat(requestInfo.isCompleteRequestWithAllChunks(), is(false));
assertThat(requestInfo.getRawContentBytes(), nullValue());
assertThat(requestInfo.getRawContent(), nullValue());
verify(chunk1Mock).retain();
verify(chunk1Mock).content();
verifyNoMoreInteractions(chunk1Mock);
verify(chunk2Mock).retain();
verify(chunk2Mock).content();
verifyNoMoreInteractions(chunk2Mock);
}
use of io.netty.handler.codec.http.HttpContent in project riposte by Nike-Inc.
the class HttpUtilsTest method extractContentChunks_returns_null_for_request_that_is_not_HttpContent.
@Test
public void extractContentChunks_returns_null_for_request_that_is_not_HttpContent() {
// given
HttpRequest request = mock(HttpRequest.class);
// when
List<HttpContent> result = HttpUtils.extractContentChunks(request);
// then
assertThat(result, nullValue());
}
use of io.netty.handler.codec.http.HttpContent in project riposte by Nike-Inc.
the class HttpUtilsTest method extractContentChunks_works_for_request_that_is_also_HttpContent.
@Test
public void extractContentChunks_works_for_request_that_is_also_HttpContent() {
// given
HttpRequest request = mock(FullHttpRequest.class);
// when
List<HttpContent> result = HttpUtils.extractContentChunks(request);
// then
assertThat(result, notNullValue());
assertThat(result.size(), is(1));
assertThat(result.get(0), is(request));
}
use of io.netty.handler.codec.http.HttpContent in project riposte by Nike-Inc.
the class ProcessFinalResponseOutputHandlerTest method write_does_nothing_to_finalContentLength_if_msg_is_HttpContent_but_responseInfo_is_null.
@Test
public void write_does_nothing_to_finalContentLength_if_msg_is_HttpContent_but_responseInfo_is_null() throws Exception {
// given
HttpContent msgMock = mock(HttpContent.class);
ByteBuf contentMock = mock(ByteBuf.class);
int contentBytes = (int) (Math.random() * 10000);
doReturn(contentMock).when(msgMock).content();
doReturn(contentBytes).when(contentMock).readableBytes();
doReturn(null).when(stateMock).getResponseInfo();
assertThat(responseInfo.getFinalContentLength()).isNull();
// when
handler.write(ctxMock, msgMock, promiseMock);
// then
assertThat(responseInfo.getFinalContentLength()).isNull();
}
Aggregations