use of com.hotels.styx.server.routing.Condition in project styx by ExpediaGroup.
the class AntlrConditionTest method notExpressionNegatesTheExpressionResult.
@Test
public void notExpressionNegatesTheExpressionResult() {
Condition condition = condition("NOT header('Host')");
LiveHttpRequest request1 = newRequest().header(HOST, "bbc.co.uk").build();
assertThat(condition.evaluate(request1, context), is(false));
LiveHttpRequest request2 = newRequest().header(CONTENT_LENGTH, 7).build();
assertThat(condition.evaluate(request2, context), is(true));
}
use of com.hotels.styx.server.routing.Condition in project styx by ExpediaGroup.
the class AntlrConditionTest method notMatchingRequestPath.
@Test
public void notMatchingRequestPath() {
Condition condition = condition("path() == '/some-request'");
assertThat(condition.evaluate(newRequest("/random-request").build(), context), is(false));
}
use of com.hotels.styx.server.routing.Condition in project styx by ExpediaGroup.
the class AntlrConditionTest method notExpressionHasHigherPrecedenceThanAndExpression.
@Test
public void notExpressionHasHigherPrecedenceThanAndExpression() {
Condition condition = condition("header('Host') " + "AND NOT header('App-Name') =~ 'app[0-9]' OR header('App-Name') =~ 'shop[0-9]'");
LiveHttpRequest request1 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "landing1").build();
assertThat(condition.evaluate(request1, context), is(true));
LiveHttpRequest request2 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "app2").build();
assertThat(condition.evaluate(request2, context), is(false));
LiveHttpRequest request3 = newRequest().header(HOST, "bbc.co.uk").header("App-Name", "shop1").build();
assertThat(condition.evaluate(request3, context), is(true));
}
use of com.hotels.styx.server.routing.Condition 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.server.routing.Condition 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));
}
Aggregations