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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations