Search in sources :

Example 16 with Condition

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

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

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

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

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

the class AntlrConditionTest method pathPrefixReges.

@Test
public void pathPrefixReges() {
    Condition condition = condition("path() =~ '.foo.*'");
    assertThat(condition.evaluate(get("/foo/bar").build(), context), is(true));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) 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