Search in sources :

Example 11 with HttpHandler

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));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Registry(com.hotels.styx.api.extension.service.spi.Registry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 12 with HttpHandler

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));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Registry(com.hotels.styx.api.extension.service.spi.Registry) MicrometerRegistry(com.hotels.styx.api.MicrometerRegistry) MeterRegistry(com.hotels.styx.api.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 13 with HttpHandler

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()));
}
Also used : HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 14 with HttpHandler

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));
}
Also used : HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 15 with HttpHandler

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());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RequestTracker(com.hotels.styx.server.track.RequestTracker) LiveHttpResponse.response(com.hotels.styx.api.LiveHttpResponse.response) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) HttpInterceptorContext(com.hotels.styx.server.HttpInterceptorContext) Support.requestContext(com.hotels.styx.support.Support.requestContext) Arrays.asList(java.util.Arrays.asList) Matchers.nullValue(org.hamcrest.Matchers.nullValue) LiveHttpRequest.get(com.hotels.styx.api.LiveHttpRequest.get) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MethodSource(org.junit.jupiter.params.provider.MethodSource) Eventual(com.hotels.styx.api.Eventual) HttpHandler(com.hotels.styx.api.HttpHandler) Mono(reactor.core.publisher.Mono) Arguments(org.junit.jupiter.params.provider.Arguments) InetSocketAddress(java.net.InetSocketAddress) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Matchers.contains(org.hamcrest.Matchers.contains) OK(com.hotels.styx.api.HttpResponseStatus.OK) Matchers.is(org.hamcrest.Matchers.is) HttpHandler(com.hotels.styx.api.HttpHandler) HttpInterceptor(com.hotels.styx.api.HttpInterceptor) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

HttpHandler (com.hotels.styx.api.HttpHandler)23 Test (org.junit.jupiter.api.Test)20 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)13 MeterRegistry (com.hotels.styx.api.MeterRegistry)11 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)11 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)10 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)9 Eventual (com.hotels.styx.api.Eventual)8 BackendService (com.hotels.styx.api.extension.service.BackendService)8 Registry (com.hotels.styx.api.extension.service.spi.Registry)8 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)7 OK (com.hotels.styx.api.HttpResponseStatus.OK)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 Mono (reactor.core.publisher.Mono)6 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)5 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 Support.requestContext (com.hotels.styx.support.Support.requestContext)5 Arrays.asList (java.util.Arrays.asList)5 Matchers.is (org.hamcrest.Matchers.is)5