use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderCookieTest method testWhenCookieIsPresent.
@Test
void testWhenCookieIsPresent() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenCookie("session").isPresent().thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(headers.getCookiesIterator("session")).then(answerIteratorOf(cookie1));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(headers.getCookiesIterator("session")).thenReturn(emptyIterator());
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderCookieTest method testWhenCookieValues.
@Test
void testWhenCookieValues() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenCookie("session").values(new AnyMatchPredicate<>(cookie1)).thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(headers.getCookiesIterator("session")).then(answerIteratorOf(cookie1));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(headers.getCookiesIterator("session")).then(answerIteratorOf(cookie2, cookie1));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(headers.getCookiesIterator("session")).then(answerIteratorOf(cookie2));
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
when(headers.getCookiesIterator("session")).thenReturn(emptyIterator());
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderHeaderTest method testWhenHeaderFirstValue.
@Test
void testWhenHeaderFirstValue() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenHeader("host").firstValue("localhost").thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(headers.valuesIterator("host")).then(answerIteratorOf("localhost"));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(headers.valuesIterator("host")).then(answerIteratorOf("localhost", "127.0.0.1"));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(headers.valuesIterator("host")).then(answerIteratorOf("127.0.0.1", "localhost"));
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
when(headers.valuesIterator("host")).then(answerIteratorOf("127.0.0.1"));
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
when(headers.valuesIterator("host")).thenReturn(emptyIterator());
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderHeaderTest method testWhenHeaderFirstValueMatchesPattern.
@Test
void testWhenHeaderFirstValueMatchesPattern() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenHeader("host").firstValueMatches(Pattern.compile("127\\..*", CASE_INSENSITIVE)).thenRouteTo(serviceA).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(headers.valuesIterator("host")).then(answerIteratorOf("127.0.0.1"));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(headers.valuesIterator("host")).then(answerIteratorOf("127.0.0.1", "localhost"));
assertSame(responseA, service.handle(ctx, request, reqRespFactory));
when(headers.valuesIterator("host")).then(answerIteratorOf("localhost", "127.0.0.1"));
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
when(headers.valuesIterator("host")).then(answerIteratorOf("localhost"));
assertSame(fallbackResponse, service.handle(ctx, request, reqRespFactory));
}
use of io.servicetalk.http.api.StreamingHttpService in project servicetalk by apple.
the class HttpPredicateRouterBuilderHeaderTest method testMultipleHeaderRoutes.
@Test
void testMultipleHeaderRoutes() {
final StreamingHttpService service = new HttpPredicateRouterBuilder().whenHeader("host").firstValue("a.com").thenRouteTo(serviceA).whenHeader("host").firstValue("b.com").thenRouteTo(serviceB).whenHeader("host").firstValue("c.com").thenRouteTo(serviceC).whenHeader("host").firstValue("d.com").thenRouteTo(serviceD).when((ctx, req) -> true).thenRouteTo(fallbackService).buildStreaming();
when(headers.valuesIterator("host")).then(answerIteratorOf("d.com"));
assertSame(responseD, service.handle(ctx, request, reqRespFactory));
verify(request, times(4)).headers();
verify(headers, times(4)).valuesIterator("host");
}
Aggregations