use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullresp_misslastcontent.
@Test
public final void test_httpobjs2fullresp_misslastcontent() throws Exception {
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
final HttpContent[] resp_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> resps = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(response);
this.addAll(Arrays.asList(resp_contents));
}
};
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
FullHttpResponse fullresp = null;
thrown.expect(RuntimeException.class);
try {
fullresp = Nettys.httpobjs2fullresp(resps);
} finally {
assertNull(fullresp);
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.
the class RxNettysTestCase method test_BUILD_FULL_REQUEST_WhenNoLastContent.
@Test
public final void test_BUILD_FULL_REQUEST_WhenNoLastContent() {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> reqs = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(request);
this.addAll(Arrays.asList(req_contents));
}
};
final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(reqs.toArray(new HttpObject[0]));
assertNull(fullreq);
}
use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.
the class RxNettysTestCase method testSplitFullHttpMessageForRequest.
@Test
public final void testSplitFullHttpMessageForRequest() throws Exception {
final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf(REQ_CONTENT));
final TestSubscriber<HttpObject> reqSubscriber = new TestSubscriber<>();
Observable.just(request).flatMap(RxNettys.splitFullHttpMessage()).subscribe(reqSubscriber);
reqSubscriber.assertValueCount(2);
final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(reqSubscriber.getOnNextEvents().toArray(new HttpObject[0]));
assertNotNull(fullreq);
assertEquals(REQ_CONTENT, new String(Nettys.dumpByteBufAsBytes(fullreq.content()), Charsets.UTF_8));
}
use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.
the class RxNettysTestCase method testSplitFullHttpMessageForResponse.
@Test
public final void testSplitFullHttpMessageForResponse() {
final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, OK, Nettys4Test.buildByteBuf(REQ_CONTENT));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
final TestSubscriber<HttpObject> respSubscriber = new TestSubscriber<>();
Observable.just(response).flatMap(RxNettys.splitFullHttpMessage()).subscribe(respSubscriber);
respSubscriber.assertValueCount(2);
// final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(
// respSubscriber.getOnNextEvents().toArray(new HttpObject[0]));
// assertNotNull(fullreq);
// assertEquals(REQ_CONTENT, new String(Nettys.dumpByteBufAsBytes(fullreq.content()), Charsets.UTF_8));
}
use of io.netty.handler.codec.http.HttpObject in project jocean-http by isdom.
the class RxNettysTestCase method testAsHttpRequestOp.
@Test
public final void testAsHttpRequestOp() {
final TestSubscriber<HttpRequest> testSubscriber = new TestSubscriber<>();
Observable.<HttpObject>just(new HttpObject() {
@Override
public DecoderResult decoderResult() {
return null;
}
@Override
public void setDecoderResult(DecoderResult result) {
}
@Override
public DecoderResult getDecoderResult() {
return null;
}
}).compose(RxNettys.asHttpRequest()).subscribe(testSubscriber);
testSubscriber.assertNoValues();
testSubscriber.assertNotCompleted();
testSubscriber.assertError(RuntimeException.class);
}
Aggregations