use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class AntlrConditionTest method regexpMatchesHttpHeader.
@Test
public void regexpMatchesHttpHeader() {
Condition condition = condition("header('Host') =~ '.*\\.co\\.uk'");
LiveHttpRequest request = newRequest().header(HOST, "bbc.co.uk").build();
assertThat(condition.evaluate(request, context), is(true));
LiveHttpRequest request2 = request.newBuilder().header(HOST, "hotels.com").build();
assertThat(condition.evaluate(request2, context), is(false));
LiveHttpRequest request3 = request.newBuilder().header(HOST, "hotels.co.uk").build();
assertThat(condition.evaluate(request3, context), is(true));
LiveHttpRequest request4 = newRequest().build();
assertThat(condition.evaluate(request4, context), is(false));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class AntlrConditionTest method combinesStringEqualsAndStringRegexpMatchOperationsWithAndOperator.
@Test
public void combinesStringEqualsAndStringRegexpMatchOperationsWithAndOperator() {
Condition condition = condition("header('Host') == 'bbc.co.uk' AND header('Content-Length') =~ '[123][0-9]'");
LiveHttpRequest request = newRequest().header(HOST, "bbc.co.uk").header(CONTENT_LENGTH, "20").build();
assertThat(condition.evaluate(request, context), is(true));
LiveHttpRequest request2 = newRequest().header(HOST, "bbc.co.uk").header(CONTENT_LENGTH, "70").build();
assertThat(condition.evaluate(request2, context), is(false));
}
use of com.hotels.styx.api.LiveHttpRequest 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.api.LiveHttpRequest 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.api.LiveHttpRequest 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));
}
Aggregations