Search in sources :

Example 31 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class BackendServicesRouterTest method selectsApplicationBasedOnPathIfAppsAreProvidedInOppositeOrder.

@Test
public void selectsApplicationBasedOnPathIfAppsAreProvidedInOppositeOrder() 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("/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 32 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class BackendServicesRouterTest method throwsExceptionWhenNoApplicationMatches.

@Test
public void throwsExceptionWhenNoApplicationMatches() {
    BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
    router.onChange(added(appB().newCopy().path("/appB/hotel/details.html").build()));
    LiveHttpRequest request = get("/qwertyuiop").build();
    assertThat(router.route(request, context), is(Optional.empty()));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 33 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.

the class BackendServicesRouterTest method updatesRoutesOnBackendServicesChange.

@Test
public void updatesRoutesOnBackendServicesChange() throws Exception {
    BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
    LiveHttpRequest request = get("/appB/").build();
    router.onChange(added(appB()));
    Optional<HttpHandler> route = router.route(request, context);
    assertThat(proxyTo(route, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
    router.onChange(new Registry.Changes.Builder<BackendService>().build());
    Optional<HttpHandler> route2 = router.route(request, context);
    assertThat(proxyTo(route2, request).header(ORIGIN_ID_DEFAULT), isValue(APP_B));
}
Also used : HttpHandler(com.hotels.styx.api.HttpHandler) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Origin.newOriginBuilder(com.hotels.styx.api.extension.Origin.newOriginBuilder) BackendService.newBackendServiceBuilder(com.hotels.styx.api.extension.service.BackendService.newBackendServiceBuilder) 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 34 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest 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 35 with LiveHttpRequest

use of com.hotels.styx.api.LiveHttpRequest 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)

Aggregations

LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)82 Test (org.junit.jupiter.api.Test)76 Condition (com.hotels.styx.server.routing.Condition)19 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)14 HttpHandler (com.hotels.styx.api.HttpHandler)10 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)9 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)9 MeterRegistry (com.hotels.styx.api.MeterRegistry)8 BackendService (com.hotels.styx.api.extension.service.BackendService)7 Registry (com.hotels.styx.api.extension.service.spi.Registry)7 Eventual (com.hotels.styx.api.Eventual)6 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)6 HttpResponse (com.hotels.styx.api.HttpResponse)5 Origin.newOriginBuilder (com.hotels.styx.api.extension.Origin.newOriginBuilder)5 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Mono (reactor.core.publisher.Mono)5 HttpRequestMessageLogger (com.hotels.styx.common.logging.HttpRequestMessageLogger)4 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)4