Search in sources :

Example 1 with StringTransformer

use of io.reactivex.netty.channel.StringTransformer in project ribbon by Netflix.

the class RxMovieServerTest method testUpateRecommendations.

@Test
public void testUpateRecommendations() {
    movieServer.movies.put(ORANGE_IS_THE_NEW_BLACK.getId(), ORANGE_IS_THE_NEW_BLACK);
    HttpResponseStatus statusCode = RxNetty.createHttpPost(baseURL + "/users/" + TEST_USER_ID + "/recommendations", Observable.just(ORANGE_IS_THE_NEW_BLACK.getId()), new StringTransformer()).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<HttpResponseStatus>>() {

        @Override
        public Observable<HttpResponseStatus> call(HttpClientResponse<ByteBuf> httpClientResponse) {
            return Observable.just(httpClientResponse.getStatus());
        }
    }).toBlocking().first();
    assertEquals(HttpResponseStatus.OK, statusCode);
    assertTrue(movieServer.userRecommendations.get(TEST_USER_ID).contains(ORANGE_IS_THE_NEW_BLACK.getId()));
}
Also used : StringTransformer(io.reactivex.netty.channel.StringTransformer) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) ByteBuf(io.netty.buffer.ByteBuf) Observable(rx.Observable) Test(org.junit.Test)

Example 2 with StringTransformer

use of io.reactivex.netty.channel.StringTransformer in project ribbon by Netflix.

the class RxMovieServerTest method testMovieRegistration.

@Test
public void testMovieRegistration() {
    String movieFormatted = ORANGE_IS_THE_NEW_BLACK.toString();
    HttpResponseStatus statusCode = RxNetty.createHttpPost(baseURL + "/movies", Observable.just(movieFormatted), new StringTransformer()).flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<HttpResponseStatus>>() {

        @Override
        public Observable<HttpResponseStatus> call(HttpClientResponse<ByteBuf> httpClientResponse) {
            return Observable.just(httpClientResponse.getStatus());
        }
    }).toBlocking().first();
    assertEquals(HttpResponseStatus.CREATED, statusCode);
    assertEquals(ORANGE_IS_THE_NEW_BLACK, movieServer.movies.get(ORANGE_IS_THE_NEW_BLACK.getId()));
}
Also used : StringTransformer(io.reactivex.netty.channel.StringTransformer) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) ByteBuf(io.netty.buffer.ByteBuf) Observable(rx.Observable) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)2 StringTransformer (io.reactivex.netty.channel.StringTransformer)2 HttpClientResponse (io.reactivex.netty.protocol.http.client.HttpClientResponse)2 Test (org.junit.Test)2 Observable (rx.Observable)2