use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method resourceNotFound.
private void resourceNotFound(HttpMethod httpMethod) throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.method(httpMethod, "").toExchange();
setPathWithinHandlerMapping(exchange, "not-there.css");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method modified.
@Test
public void modified() throws Exception {
long timestamp = resourceLastModified("test/foo.css") / 1000 * 1000 - 1;
MockServerWebExchange exchange = MockServerHttpRequest.get("").ifModifiedSince(timestamp).toExchange();
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertNull(exchange.getResponse().getStatusCode());
assertResponseBody(exchange, "h1 { color:red; }");
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method partialContentInvalidRangeHeader.
@Test
public void partialContentInvalidRangeHeader() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("range", "bytes=foo bar").toExchange();
setPathWithinHandlerMapping(exchange, "foo.txt");
StepVerifier.create(this.handler.handle(exchange)).expectNextCount(0).expectComplete().verify();
assertEquals(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE, exchange.getResponse().getStatusCode());
assertEquals("bytes", exchange.getResponse().getHeaders().getFirst("Accept-Ranges"));
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method getResourceWithHtmlMediaType.
@Test
public void getResourceWithHtmlMediaType() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
setPathWithinHandlerMapping(exchange, "foo.html");
this.handler.handle(exchange).block(TIMEOUT);
HttpHeaders headers = exchange.getResponse().getHeaders();
assertEquals(MediaType.TEXT_HTML, headers.getContentType());
assertEquals("max-age=3600", headers.getCacheControl());
assertTrue(headers.containsKey("Last-Modified"));
assertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("test/foo.html") / 1000);
assertEquals("bytes", headers.getFirst("Accept-Ranges"));
assertEquals(1, headers.get("Accept-Ranges").size());
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method getResourceFromSubDirectoryOfAlternatePath.
@Test
public void getResourceFromSubDirectoryOfAlternatePath() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
setPathWithinHandlerMapping(exchange, "js/baz.js");
this.handler.handle(exchange).block(TIMEOUT);
assertEquals(MediaType.parseMediaType("text/javascript"), exchange.getResponse().getHeaders().getContentType());
assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
}
Aggregations