Search in sources :

Example 11 with Condition

use of com.hotels.styx.server.routing.Condition 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));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test)

Example 12 with Condition

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

the class AntlrConditionTest method cookieValueMatchesWithString.

@Test
public void cookieValueMatchesWithString() {
    Condition condition = condition("cookie('TheCookie') == 'foobar-foobar-baz'");
    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-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 13 with Condition

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

the class AntlrConditionTest method matchesRequestPath.

@Test
public void matchesRequestPath() {
    Condition condition = condition("path() == '/some-request'");
    assertThat(condition.evaluate(newRequest("/some-request").build(), context), is(true));
}
Also used : Condition(com.hotels.styx.server.routing.Condition) Test(org.junit.jupiter.api.Test)

Example 14 with Condition

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

the class AntlrConditionTest method matchesHeaderPresence.

@Test
public void matchesHeaderPresence() {
    Condition condition = condition("header('Host')");
    LiveHttpRequest request = newRequest("/foo").header(HOST, "bbc.co.uk").build();
    assertThat(condition.evaluate(request, context), is(true));
    LiveHttpRequest request2 = newRequest("/foo").build();
    assertThat(condition.evaluate(request2, 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 15 with Condition

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

the class AntlrConditionTest method cookieValueMatchesWithRegexp.

@Test
public void cookieValueMatchesWithRegexp() {
    Condition condition = condition("cookie('TheCookie') =~ 'foobar-.*-baz'");
    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-x-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)

Aggregations

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