use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method partialContentSuffixRange.
@Test
public void partialContentSuffixRange() {
MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=-1").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(1);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 9-9/10");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, ".");
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method partialContentByteRangeNoEnd.
@Test
public void partialContentByteRangeNoEnd() {
MockServerHttpRequest request = MockServerHttpRequest.get("").header("range", "bytes=9-").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
setPathWithinHandlerMapping(exchange, "foo.txt");
this.handler.handle(exchange).block(TIMEOUT);
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.PARTIAL_CONTENT);
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
assertThat(exchange.getResponse().getHeaders().getContentLength()).isEqualTo(1);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Range")).isEqualTo("bytes 9-9/10");
assertThat(exchange.getResponse().getHeaders().getFirst("Accept-Ranges")).isEqualTo("bytes");
assertThat(exchange.getResponse().getHeaders().get("Accept-Ranges").size()).isEqualTo(1);
assertResponseBody(exchange, ".");
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceWebHandlerTests method doOverwriteExistingCacheControlHeaders.
// SPR-14005
@Test
public void doOverwriteExistingCacheControlHeaders() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
exchange.getResponse().getHeaders().setCacheControl(CacheControl.noStore().getHeaderValue());
setPathWithinHandlerMapping(exchange, "foo.css");
this.handler.handle(exchange).block(TIMEOUT);
assertThat(exchange.getResponse().getHeaders().getCacheControl()).isEqualTo("max-age=3600");
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class EncodedResourceResolverTests method resolveGzippedWithVersion.
@Test
public void resolveGzippedWithVersion(GzippedFiles gzippedFiles) {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").header("Accept-Encoding", "gzip"));
gzippedFiles.create("foo.css");
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
Resource actual = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertThat(actual.getDescription()).isEqualTo(getResource("foo.css.gz").getDescription());
assertThat(actual.getFilename()).isEqualTo(getResource("foo.css").getFilename());
boolean condition = actual instanceof HttpResource;
assertThat(condition).isTrue();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class EncodedResourceResolverTests method resolveGzipped.
@Test
public void resolveGzipped(GzippedFiles gzippedFiles) {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("").header("Accept-Encoding", "gzip"));
String file = "js/foo.js";
gzippedFiles.create(file);
Resource actual = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
assertThat(actual.getDescription()).isEqualTo(getResource(file + ".gz").getDescription());
assertThat(actual.getFilename()).isEqualTo(getResource(file).getFilename());
boolean condition = actual instanceof HttpResource;
assertThat(condition).isTrue();
HttpHeaders headers = ((HttpResource) actual).getResponseHeaders();
assertThat(headers.getFirst(HttpHeaders.CONTENT_ENCODING)).isEqualTo("gzip");
assertThat(headers.getFirst(HttpHeaders.VARY)).isEqualTo("Accept-Encoding");
}
Aggregations