Search in sources :

Example 6 with Condition

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

the class AntlrConditionTest method cookieValueIsPresent.

@Test
public void cookieValueIsPresent() {
    Condition condition = condition("cookie('TheCookie')");
    LiveHttpRequest request = newRequest().cookies(requestCookie("TheCookie", "foobar-foobar-baz")).header("App-Name", "app3").build();
    assertThat(condition.evaluate(request, context), is(true));
    request = newRequest().cookies(requestCookie("AnotherCookie", "foobar-foobar-baz")).header("App-Name", "app3").build();
    assertThat(condition.evaluate(request, context), is(false));
    request = newRequest().header("App-Name", "app3").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 7 with Condition

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

the class AntlrConditionTest method matchesCompositionOfExpressionsWithEnd.

@Test
public void matchesCompositionOfExpressionsWithEnd() {
    Condition condition = condition("header('Host') == 'bbc.co.uk' AND header('Content-Length') == '7' AND header('App-Name')=='app1'");
    LiveHttpRequest request = newRequest().header(HOST, "bbc.co.uk").header(CONTENT_LENGTH, "7").header("App-Name", "app1").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 8 with Condition

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

the class AntlrConditionTest method andExpressionsHasHigherPrecedenceThanOrExpression.

@Test
public void andExpressionsHasHigherPrecedenceThanOrExpression() {
    Condition condition = condition("header('Host') == 'bbc.co.uk' " + "AND header('Content-Length') == '7' " + "OR header('App-Name') =~ 'app[0-9]'");
    LiveHttpRequest request = newRequest().header("App-Name", "app5").build();
    assertThat(condition.evaluate(request, context), is(true));
    request = newRequest().header(HOST, "bbc.co.uk").header(CONTENT_LENGTH, "7").build();
    assertThat(condition.evaluate(request, context), is(true));
    request = newRequest().header(HOST, "bbc.co.uk").header(CONTENT_LENGTH, "8").build();
    assertThat(condition.evaluate(request, context), is(false));
    request = newRequest().header(HOST, "hotels.com").header(CONTENT_LENGTH, "7").header("App-Name", "appX").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 9 with Condition

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

the class AntlrConditionTest method acceptsDoubleQuotesAsFunctionArgument.

@Test
public void acceptsDoubleQuotesAsFunctionArgument() 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 10 with Condition

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

the class AntlrConditionTest method userAgentMatchesUserAgent.

@Test
public void userAgentMatchesUserAgent() {
    Condition condition = condition("userAgent() == 'Mozilla Firefox 1.1.2' OR userAgent() =~ 'Safari.*'");
    LiveHttpRequest request = get("/blah").header(USER_AGENT, "Mozilla Firefox 1.1.2").build();
    assertThat(condition.evaluate(request, context), is(true));
    request = get("/blah").header(USER_AGENT, "Mozilla Firefox 1.1.25").build();
    assertThat(condition.evaluate(request, context), is(false));
    request = get("/blah").header(USER_AGENT, "Foxzilla x.y.z").build();
    assertThat(condition.evaluate(request, context), is(false));
    request = get("/blah").header(USER_AGENT, "Safari-XYZ").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)

Aggregations

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