use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsServiceBasedOnPath.
@Test
public void selectsServiceBasedOnPath() throws Exception {
Registry.Changes<BackendService> changes = added(appA().newCopy().path("/").build(), appB().newCopy().path("/appB/hotel/details.html").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/appB/hotel/details.html").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method selectsUsingSingleSlashPathIfAppsAreProvidedInOppositeOrder.
@Test
public void selectsUsingSingleSlashPathIfAppsAreProvidedInOppositeOrder() throws Exception {
Registry.Changes<BackendService> changes = added(appB().newCopy().path("/appB/hotel/details.html").build(), appA().newCopy().path("/").build());
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(changes);
LiveHttpRequest request = get("/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_A));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class BackendServicesRouterTest method doesNotMatchRequestIfFinalSlashIsMissing.
@Test
public void doesNotMatchRequestIfFinalSlashIsMissing() {
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(added(appB().newCopy().path("/appB/hotel/details.html").build()));
LiveHttpRequest request = get("/ba/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(route, is(Optional.empty()));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class InterceptorPipelineBuilderTest method buildsPipelineWithInterceptors.
@Test
public void buildsPipelineWithInterceptors() throws Exception {
HttpHandler pipeline = new InterceptorPipelineBuilder(environment, plugins, handler, false).build();
LiveHttpResponse response = Mono.from(pipeline.handle(get("/foo").build(), requestContext())).block();
assertThat(response.header("plug1"), isValue("1"));
assertThat(response.header("plug2"), isValue("1"));
assertThat(response.status(), is(OK));
}
use of com.hotels.styx.api.HttpHandler in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method sendsExceptionUponExtraSubscriptionInsideInterceptor.
@ParameterizedTest
@MethodSource("multipleSubscriptionInterceptors")
public void sendsExceptionUponExtraSubscriptionInsideInterceptor(HttpInterceptor interceptor) throws Exception {
HttpHandler handler = (request, context) -> Eventual.of(response(OK).build());
List<HttpInterceptor> interceptors = singletonList(interceptor);
StandardHttpPipeline pipeline = new StandardHttpPipeline(interceptors, handler, RequestTracker.NO_OP);
Eventual<LiveHttpResponse> responseObservable = pipeline.handle(get("/").build(), requestContext());
assertThrows(IllegalStateException.class, () -> Mono.from(responseObservable).block());
}
Aggregations