use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method unsupportedHttpMethod.
@Test
public void unsupportedHttpMethod() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post(""));
setPathWithinHandlerMapping(exchange, "foo.css");
assertThatExceptionOfType(MethodNotAllowedException.class).isThrownBy(() -> this.handler.handle(exchange).block(TIMEOUT));
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method missingResourcePath.
@Test
public void missingResourcePath() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
setPathWithinHandlerMapping(exchange, "");
StepVerifier.create(this.handler.handle(exchange)).expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertThat(((ResponseStatusException) err).getRawStatusCode()).isEqualTo(404);
}).verify(TIMEOUT);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method getResourceNoCache.
@Test
public void getResourceNoCache() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.setCacheControl(CacheControl.noStore());
this.handler.handle(exchange).block(TIMEOUT);
MockServerHttpResponse response = exchange.getResponse();
assertThat(response.getHeaders().getCacheControl()).isEqualTo("no-store");
assertThat(response.getHeaders().containsKey("Last-Modified")).isTrue();
assertThat(resourceLastModifiedDate("test/foo.css") / 1000).isEqualTo(response.getHeaders().getLastModified() / 1000);
assertThat(response.getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(response.getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method directory.
@Test
public void directory() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
setPathWithinHandlerMapping(exchange, "js/");
StepVerifier.create(this.handler.handle(exchange)).expectErrorSatisfies(err -> {
assertThat(err).isInstanceOf(ResponseStatusException.class);
assertThat(((ResponseStatusException) err).getRawStatusCode()).isEqualTo(404);
}).verify(TIMEOUT);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method notModified.
@Test
public void notModified() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").ifModifiedSince(resourceLastModified("test/foo.css")));
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
}
Aggregations