Search in sources :

Example 16 with OK

use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.

the class HttpServerFilterOrderTest method conditional.

@Test
void conditional() throws Exception {
    StreamingHttpService filter1 = newMockService();
    StreamingHttpService filter2 = newMockService();
    StreamingHttpService filter3 = newMockService();
    ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendServiceFilter(req -> true, addFilter(filter1)).appendServiceFilter(req -> false, addFilter(filter2)).appendServiceFilter(req -> true, addFilter(filter3)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
    BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
    HttpResponse resp = client.request(client.get("/"));
    assertThat("Unexpected response.", resp.status(), is(OK));
    InOrder verifier = inOrder(filter1, filter2, filter3);
    verifier.verify(filter1).handle(any(), any(), any());
    verifier.verify(filter2, never()).handle(any(), any(), any());
    verifier.verify(filter3).handle(any(), any(), any());
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) InOrder(org.mockito.InOrder) ServerContext(io.servicetalk.transport.api.ServerContext) HttpClients.forSingleAddress(io.servicetalk.http.netty.HttpClients.forSingleAddress) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpServiceFilterFactory(io.servicetalk.http.api.StreamingHttpServiceFilterFactory) Mockito.when(org.mockito.Mockito.when) OK(io.servicetalk.http.api.HttpResponseStatus.OK) Test(org.junit.jupiter.api.Test) StreamingHttpServiceFilter(io.servicetalk.http.api.StreamingHttpServiceFilter) Mockito.never(org.mockito.Mockito.never) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) ExecutionStrategyInfluencer(io.servicetalk.transport.api.ExecutionStrategyInfluencer) Mockito.inOrder(org.mockito.Mockito.inOrder) HttpExecutionStrategies(io.servicetalk.http.api.HttpExecutionStrategies) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) InOrder(org.mockito.InOrder) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) HttpResponse(io.servicetalk.http.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 17 with OK

use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.

the class HttpServerFilterOrderTest method conditionalNonOffload.

@Test
void conditionalNonOffload() throws Exception {
    StreamingHttpService filter0 = newMockService();
    StreamingHttpService filter1 = newMockService();
    StreamingHttpService filter2 = newMockService();
    StreamingHttpService filter3 = newMockService();
    ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendServiceFilter(addFilter(filter0)).appendNonOffloadingServiceFilter(req -> true, addFilter(filter1)).appendNonOffloadingServiceFilter(req -> false, addFilter(filter2)).appendNonOffloadingServiceFilter(req -> true, addFilter(filter3)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
    BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
    HttpResponse resp = client.request(client.get("/"));
    assertThat("Unexpected response.", resp.status(), is(OK));
    InOrder verifier = inOrder(filter1, filter2, filter3, filter0);
    verifier.verify(filter1).handle(any(), any(), any());
    verifier.verify(filter2, never()).handle(any(), any(), any());
    verifier.verify(filter3).handle(any(), any(), any());
    verifier.verify(filter0).handle(any(), any(), any());
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) InOrder(org.mockito.InOrder) ServerContext(io.servicetalk.transport.api.ServerContext) HttpClients.forSingleAddress(io.servicetalk.http.netty.HttpClients.forSingleAddress) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpServiceFilterFactory(io.servicetalk.http.api.StreamingHttpServiceFilterFactory) Mockito.when(org.mockito.Mockito.when) OK(io.servicetalk.http.api.HttpResponseStatus.OK) Test(org.junit.jupiter.api.Test) StreamingHttpServiceFilter(io.servicetalk.http.api.StreamingHttpServiceFilter) Mockito.never(org.mockito.Mockito.never) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) ExecutionStrategyInfluencer(io.servicetalk.transport.api.ExecutionStrategyInfluencer) Mockito.inOrder(org.mockito.Mockito.inOrder) HttpExecutionStrategies(io.servicetalk.http.api.HttpExecutionStrategies) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) InOrder(org.mockito.InOrder) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) HttpResponse(io.servicetalk.http.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

OK (io.servicetalk.http.api.HttpResponseStatus.OK)17 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)13 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)9 HttpResponse (io.servicetalk.http.api.HttpResponse)9 Single (io.servicetalk.concurrent.api.Single)8 ServerContext (io.servicetalk.transport.api.ServerContext)8 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)8 Test (org.junit.jupiter.api.Test)8 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)7 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)6 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)6 Buffer (io.servicetalk.buffer.api.Buffer)5 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)5 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)5 HOST (io.servicetalk.http.api.HttpHeaderNames.HOST)5 HttpRequest (io.servicetalk.http.api.HttpRequest)5 Matchers.is (org.hamcrest.Matchers.is)5 Publisher (io.servicetalk.concurrent.api.Publisher)4 AbstractHttpRequesterFilterTest (io.servicetalk.http.api.AbstractHttpRequesterFilterTest)4 BlockingHttpRequester (io.servicetalk.http.api.BlockingHttpRequester)4