Search in sources :

Example 1 with Config

use of org.springframework.cloud.gateway.handler.predicate.CookieRoutePredicateFactory.Config in project spring-cloud-gateway by spring-cloud.

the class CookieRoutePredicateFactoryTests method noCookiesForYou.

@Test
public void noCookiesForYou() {
    MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    Predicate<ServerWebExchange> predicate = new CookieRoutePredicateFactory().apply(new Config().setName("mycookie").setRegexp("ch.p"));
    assertThat(predicate.test(exchange)).isFalse();
}
Also used : MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Config(org.springframework.cloud.gateway.handler.predicate.CookieRoutePredicateFactory.Config) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) Test(org.junit.Test)

Example 2 with Config

use of org.springframework.cloud.gateway.handler.predicate.CookieRoutePredicateFactory.Config in project spring-cloud-gateway by spring-cloud.

the class CookieRoutePredicateFactoryTests method okOneCookieForYou.

@Test
public void okOneCookieForYou() {
    MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com").cookie(new HttpCookie("yourcookie", "sugar"), new HttpCookie("mycookie", "chip")).build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    Predicate<ServerWebExchange> predicate = new CookieRoutePredicateFactory().apply(new Config().setName("mycookie").setRegexp("ch.p"));
    assertThat(predicate.test(exchange)).isTrue();
}
Also used : MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) Config(org.springframework.cloud.gateway.handler.predicate.CookieRoutePredicateFactory.Config) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) HttpCookie(org.springframework.http.HttpCookie) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Config (org.springframework.cloud.gateway.handler.predicate.CookieRoutePredicateFactory.Config)2 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)2 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)2 ServerWebExchange (org.springframework.web.server.ServerWebExchange)2 HttpCookie (org.springframework.http.HttpCookie)1