use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderTest method testWhenMethodIsOneOf.
@Test
void testWhenMethodIsOneOf() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenMethodIsOneOf(POST, PUT).thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(request.method()).thenReturn(POST);
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(request.method()).thenReturn(PUT);
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(request.method()).thenReturn(GET);
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderTest method testWhenPathMatches.
@Test
void testWhenPathMatches() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenPathMatches(".*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("/defabc");
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(request.path()).thenReturn("/ABC");
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
when(request.path()).thenReturn("/abcdef");
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderTest method testWhenIsSsl.
@Test
void testWhenIsSsl() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenIsSsl().thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(ctx.sslSession()).thenReturn(mock(SSLSession.class));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(ctx.sslSession()).thenReturn(null);
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderTest method testWhenBiPredicate.
@Test
void testWhenBiPredicate() {
final SocketAddress addr1 = mock(SocketAddress.class);
final SocketAddress addr2 = mock(SocketAddress.class);
final StreamingHttpService service = new HttpPredicateRouterBuilder().when((ctx, req) -> ctx.remoteAddress() == addr1).thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(ctx.remoteAddress()).thenReturn(addr1);
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(ctx.remoteAddress()).thenReturn(addr2);
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderTest method testWhenPredicate.
@Test
void testWhenPredicate() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().when(req -> HTTP_1_1.equals(req.version())).thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(request.version()).thenReturn(HTTP_1_0);
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
Aggregations