use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class LoadBalancerClientFilterTests method happyPathWithAttributeRatherThanScheme.
@Test
public void happyPathWithAttributeRatherThanScheme() {
MockServerHttpRequest request = MockServerHttpRequest.get("ws://localhost/get?a=b").build();
URI lbUri = URI.create("ws://service1?a=b");
exchange = MockServerWebExchange.from(request);
exchange.getAttributes().put(GATEWAY_SCHEME_PREFIX_ATTR, "lb");
ServerWebExchange webExchange = testFilter(exchange, lbUri);
URI uri = webExchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
assertThat(uri).hasScheme("ws").hasHost("service1-host1").hasParameter("a", "b");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class LoadBalancerClientFilterTests method happyPath.
@Test
public void happyPath() {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/get?a=b").build();
URI lbUri = URI.create("lb://service1?a=b");
ServerWebExchange webExchange = testFilter(request, lbUri);
URI uri = webExchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
assertThat(uri).hasScheme("http").hasHost("service1-host1").hasParameter("a", "b");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class RouteToRequestUrlFilterTests method testFilter.
private ServerWebExchange testFilter(MockServerHttpRequest request, String url) {
Route value = Route.builder().id("1").uri(URI.create(url)).order(0).predicate(swe -> true).build();
ServerWebExchange exchange = MockServerWebExchange.from(request);
exchange.getAttributes().put(GATEWAY_ROUTE_ATTR, value);
GatewayFilterChain filterChain = mock(GatewayFilterChain.class);
ArgumentCaptor<ServerWebExchange> captor = ArgumentCaptor.forClass(ServerWebExchange.class);
when(filterChain.filter(captor.capture())).thenReturn(Mono.empty());
RouteToRequestUrlFilter filter = new RouteToRequestUrlFilter();
filter.filter(exchange, filterChain);
return captor.getValue();
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class RouteToRequestUrlFilterTests method noQueryParams.
@Test
public void noQueryParams() {
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/get").build();
ServerWebExchange webExchange = testFilter(request, "http://myhost");
URI uri = webExchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
assertThat(uri).hasScheme("http").hasHost("myhost");
}
use of org.springframework.mock.http.server.reactive.MockServerHttpRequest in project spring-cloud-gateway by spring-cloud.
the class RouteToRequestUrlFilterTests method unencodedParameters.
@Test
public void unencodedParameters() {
URI url = URI.create("http://localhost/get?a=b&c=d[]");
// prove that it is unencoded
assertThat(url.getRawQuery()).isEqualTo("a=b&c=d[]");
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").hasParameter("a", "b").hasParameter("c", "d[]");
// prove that it is NOT encoded
assertThat(uri.getRawQuery()).isEqualTo("a=b&c=d[]");
}
Aggregations