Search in sources :

Example 46 with StreamingHttpService

use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.

the class HttpPredicateRouterBuilderTest method testFallback.

@Test
void testFallback() {
    final StreamingHttpService service = new HttpPredicateRouterBuilder().when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
    assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
Also used : StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) Test(org.junit.jupiter.api.Test)

Example 47 with StreamingHttpService

use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.

the class HttpPredicateRouterBuilderTest method testWhenIsNotSsl.

@Test
void testWhenIsNotSsl() {
    final StreamingHttpService service = new HttpPredicateRouterBuilder().whenIsNotSsl().thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
    when(ctx.sslSession()).thenReturn(null);
    assertSame(responseA, service.handle(ctx, request, reqRespFactory));
    when(ctx.sslSession()).thenReturn(mock(SSLSession.class));
    assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
Also used : StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) SSLSession(javax.net.ssl.SSLSession) Test(org.junit.jupiter.api.Test)

Example 48 with StreamingHttpService

use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.

the class HttpPredicateRouterBuilderTest method testWhenPathIsOneOf.

@Test
void testWhenPathIsOneOf() {
    final StreamingHttpService service = new HttpPredicateRouterBuilder().whenPathIsOneOf("/abc", "/def").thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
    when(request.path()).thenReturn("/abc");
    assertSame(responseA, service.handle(ctx, request, reqRespFactory));
    when(request.path()).thenReturn("/def");
    assertSame(responseA, service.handle(ctx, request, reqRespFactory));
    when(request.path()).thenReturn("/abcd");
    assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
Also used : StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) Test(org.junit.jupiter.api.Test)

Example 49 with StreamingHttpService

use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.

the class HttpPredicateRouterBuilderTest method testWhenPathEquals.

@Test
void testWhenPathEquals() {
    final StreamingHttpService service = new HttpPredicateRouterBuilder().whenPathEquals("/abc").thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
    when(request.path()).thenReturn("/abc");
    assertSame(responseA, service.handle(ctx, request, reqRespFactory));
    when(request.path()).thenReturn("/abcd");
    assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
Also used : StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) Test(org.junit.jupiter.api.Test)

Example 50 with StreamingHttpService

use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.

the class HttpPredicateRouterBuilderTest method testWhenPathMatchesPattern.

@Test
void testWhenPathMatchesPattern() {
    final StreamingHttpService service = new HttpPredicateRouterBuilder().whenPathMatches(Pattern.compile(".*ABC", CASE_INSENSITIVE)).thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
    when(request.path()).thenReturn("/abc");
    assertSame(responseA, service.handle(ctx, request, reqRespFactory));
    when(request.path()).thenReturn("/defabc");
    assertSame(responseA, service.handle(ctx, request, reqRespFactory));
    when(request.path()).thenReturn("/abcdef");
    assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
Also used : StreamingHttpService(io.servicetalk.http.api.StreamingHttpService) Test(org.junit.jupiter.api.Test)

Aggregations

StreamingHttpService (io.servicetalk.http.api.StreamingHttpService)53 Test (org.junit.jupiter.api.Test)38 ServerContext (io.servicetalk.transport.api.ServerContext)11 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)9 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)9 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)9 HttpExecutionStrategy (io.servicetalk.http.api.HttpExecutionStrategy)8 HttpServiceContext (io.servicetalk.http.api.HttpServiceContext)7 Single (io.servicetalk.concurrent.api.Single)6 HttpResponse (io.servicetalk.http.api.HttpResponse)6 StreamingHttpResponseFactory (io.servicetalk.http.api.StreamingHttpResponseFactory)6 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)5 BlockingStreamingHttpService (io.servicetalk.http.api.BlockingStreamingHttpService)5 HttpApiConversions.toStreamingHttpService (io.servicetalk.http.api.HttpApiConversions.toStreamingHttpService)5 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)5 StreamingHttpServiceFilter (io.servicetalk.http.api.StreamingHttpServiceFilter)5 InOrder (org.mockito.InOrder)5 HttpExecutionContext (io.servicetalk.http.api.HttpExecutionContext)4 HttpExecutionStrategies (io.servicetalk.http.api.HttpExecutionStrategies)4 HttpExecutionStrategies.defaultStrategy (io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy)4