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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations