Search in sources :

Example 76 with LiveHttpRequest

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

the class AntlrConditionTest method matchesAndExpressions.

@Test
public void matchesAndExpressions() {
    Condition condition = condition("header('Host') == 'bbc.co.uk' AND header('Content-Length') == '7'");
    LiveHttpRequest request = newRequest().header(HOST, "bbc.co.uk").header(CONTENT_LENGTH, "7").build();
    assertThat(condition.evaluate(request, context), is(true));
    LiveHttpRequest request2 = newRequest().header(HOST, "bbc.co.uk").header(CONTENT_LENGTH, "1").build();
    assertThat(condition.evaluate(request2, context), is(false));
    LiveHttpRequest request3 = newRequest().header(HOST, "hotels.com").header(CONTENT_LENGTH, "7").build();
    assertThat(condition.evaluate(request3, context), is(false));
    LiveHttpRequest request4 = newRequest().header(CONTENT_LENGTH, "7").build();
    assertThat(condition.evaluate(request4, context), is(false));
    LiveHttpRequest request5 = newRequest().header(HOST, "bbc.co.uk").build();
    assertThat(condition.evaluate(request5, context), is(false));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 77 with LiveHttpRequest

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

the class AntlrConditionTest method matchesOrExpressions.

@Test
public void matchesOrExpressions() {
    Condition condition = condition("header('Host') == 'bbc.co.uk' OR header('Content-Length') == '7'");
    LiveHttpRequest request = newRequest().header(HOST, "bbc.co.uk").build();
    assertThat(condition.evaluate(request, context), is(true));
    LiveHttpRequest request2 = newRequest().header(HOST, "hotels.com").header(CONTENT_LENGTH, "7").build();
    assertThat(condition.evaluate(request2, context), is(true));
    LiveHttpRequest request3 = newRequest().header(HOST, "hotels.com").header(CONTENT_LENGTH, "8").build();
    assertThat(condition.evaluate(request3, context), is(false));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 78 with LiveHttpRequest

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

the class AntlrConditionTest method methodMatchesString.

@Test
public void methodMatchesString() {
    Condition condition = condition("method() == 'GET'");
    LiveHttpRequest request = get("/blah").build();
    assertThat(condition.evaluate(request, context), is(true));
    request = post("/blah").build();
    assertThat(condition.evaluate(request, context), is(false));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 79 with LiveHttpRequest

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

the class AntlrConditionTest method acceptsSingleQuotesAsFunctionArgument.

@Test
public void acceptsSingleQuotesAsFunctionArgument() throws Exception {
    Condition condition = condition("header('Host') =~ '.*\\.co\\.uk'");
    LiveHttpRequest request = newRequest().header(HOST, "bbc.co.uk").build();
    assertThat(condition.evaluate(request, context), is(true));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 80 with LiveHttpRequest

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

the class AntlrConditionTest method parenthesisChangesOperatorPrecedence.

@Test
public void parenthesisChangesOperatorPrecedence() {
    Condition condition = condition("header('Host') " + "AND (header('App-Name') =~ 'app[0-9]' OR header('App-Name') =~ 'shop[0-9]')");
    LiveHttpRequest request1 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "app1").build();
    assertThat(condition.evaluate(request1, context), is(true));
    LiveHttpRequest request2 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "shop2").build();
    assertThat(condition.evaluate(request2, context), is(true));
    LiveHttpRequest request3 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "landing3").build();
    assertThat(condition.evaluate(request3, context), is(false));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) 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