use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class CloudFoundryRouteServicePredicateFactoryTest method itReturnsFalseWithNoHeaders.
@Test
public void itReturnsFalseWithNoHeaders() {
MockServerHttpRequest request = MockServerHttpRequest.get("someurl").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(predicate.test(exchange)).isFalse();
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest 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();
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class LoadBalancerClientFilterTests method encodedParameters.
@Test
public void encodedParameters() {
URI url = UriComponentsBuilder.fromUriString("http://localhost/get?a=b&c=d[]").buildAndExpand().encode().toUri();
MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, url).build();
URI lbUrl = UriComponentsBuilder.fromUriString("lb://service1?a=b&c=d[]").buildAndExpand().encode().toUri();
// prove that it is encoded
assertThat(lbUrl.getRawQuery()).isEqualTo("a=b&c=d%5B%5D");
assertThat(lbUrl).hasParameter("c", "d[]");
ServerWebExchange webExchange = testFilter(request, lbUrl);
URI uri = webExchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
assertThat(uri).hasScheme("http").hasHost("service1-host1").hasParameter("a", "b").hasParameter("c", "d[]");
// prove that it is not double encoded
assertThat(uri.getRawQuery()).isEqualTo("a=b&c=d%5B%5D");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class LoadBalancerClientFilterTests method noQueryParams.
@Test
public void noQueryParams() {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/get").build();
ServerWebExchange webExchange = testFilter(request, URI.create("lb://service1"));
URI uri = webExchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
assertThat(uri).hasScheme("http").hasHost("service1-host1");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class RouteToRequestUrlFilterTests method encodedUrl.
@Test
public void encodedUrl() {
URI url = UriComponentsBuilder.fromUriString("http://localhost/abc def/get").buildAndExpand().encode().toUri();
// prove that it is encoded
assertThat(url.getRawPath()).isEqualTo("/abc%20def/get");
assertThat(url).hasPath("/abc def/get");
MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, url).build();
ServerWebExchange webExchange = testFilter(request, "http://myhost");
URI uri = webExchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
assertThat(uri).hasScheme("http").hasHost("myhost").hasPath("/abc def/get");
// prove that it is not double encoded
assertThat(uri.getRawPath()).isEqualTo("/abc%20def/get");
}
Aggregations