use of com.hotels.styx.api.LiveHttpRequest 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.api.LiveHttpRequest 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));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class AntlrConditionTest method andExpressionsHasHigherPrecedenceThanOrExpressionOrBeforeAnd.
@Test
public void andExpressionsHasHigherPrecedenceThanOrExpressionOrBeforeAnd() {
Condition condition = condition("header('App-Name') =~ 'app[0-9]' " + "OR header('Host') == 'bbc.co.uk' " + "AND header('Content-Length') == '7'");
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.api.LiveHttpRequest in project styx by ExpediaGroup.
the class FunctionResolverTest method throwsExceptionIfOneArgumentFunctionDoesNotExist.
@Test
public void throwsExceptionIfOneArgumentFunctionDoesNotExist() {
LiveHttpRequest request = get("/foo").header("Host", "www.hotels.com").cookies(requestCookie("lang", "en_US|en-us_hotels_com")).build();
Exception e = assertThrows(DslFunctionResolutionError.class, () -> functionResolver.resolveFunction("foobar", singletonList("barfoo")).call(request, context));
assertThat(e.getMessage(), matchesPattern("No such function=\\[foobar\\], with n=\\[1\\] arguments=\\[barfoo\\]"));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class FunctionResolverTest method throwsExceptionIfZeroArgumentFunctionDoesNotExist.
@Test
public void throwsExceptionIfZeroArgumentFunctionDoesNotExist() {
LiveHttpRequest request = get("/foo").build();
Exception e = assertThrows(DslFunctionResolutionError.class, () -> functionResolver.resolveFunction("foobar", emptyList()).call(request, context));
assertThat(e.getMessage(), matchesPattern("No such function=\\[foobar\\], with n=\\[0\\] arguments=\\[\\]"));
}
Aggregations