use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class DefaultServerRequestTests method pathVariable.
@Test
public void pathVariable() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
assertThat(request.pathVariable("foo")).isEqualTo("bar");
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class DefaultServerRequestTests method cookies.
@Test
public void cookies() {
HttpCookie cookie = new HttpCookie("foo", "bar");
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com").cookie(cookie));
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
MultiValueMap<String, HttpCookie> expected = new LinkedMultiValueMap<>();
expected.add("foo", cookie);
assertThat(request.cookies()).isEqualTo(expected);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class DefaultServerRequestTests method pathVariableNotFound.
@Test
public void pathVariableNotFound() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
assertThatIllegalArgumentException().isThrownBy(() -> request.pathVariable("baz"));
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceTransformerSupportTests method resolveUrlPathWithRelativePath.
@Test
public void resolveUrlPathWithRelativePath() {
Resource resource = getResource("main.css");
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
String actual = this.transformer.resolveUrlPath("bar.css", exchange, resource, this.chain).block(TIMEOUT);
assertThat(actual).isEqualTo("bar-11e16cf79faee7ac698c805cf28248d2.css");
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceTransformerSupportTests method toAbsolutePath.
@Test
public void toAbsolutePath() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
String absolute = this.transformer.toAbsolutePath("img/image.png", exchange);
assertThat(absolute).isEqualTo("/resources/img/image.png");
absolute = this.transformer.toAbsolutePath("/img/image.png", exchange);
assertThat(absolute).isEqualTo("/img/image.png");
}
Aggregations