Search in sources :

Example 21 with Condition

use of com.hotels.styx.server.routing.Condition 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)

Example 22 with Condition

use of com.hotels.styx.server.routing.Condition in project styx by ExpediaGroup.

the class AntlrConditionTest method matchesHttpHeader.

@Test
public void matchesHttpHeader() {
    Condition condition = condition("header('Host') == 'bbc.co.uk'");
    LiveHttpRequest request = newRequest("/path").header(HOST, "bbc.co.uk").build();
    assertThat(condition.evaluate(request, context), is(true));
    LiveHttpRequest request2 = newRequest("/path").header(HOST, "hotels.com").build();
    assertThat(condition.evaluate(request2, context), is(false));
    LiveHttpRequest request3 = newRequest("/path").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

Condition (com.hotels.styx.server.routing.Condition)22 Test (org.junit.jupiter.api.Test)22 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)19