Search in sources :

Example 16 with MockServerWebExchange

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, ".");
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 17 with MockServerWebExchange

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, ".");
}
Also used : MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 18 with MockServerWebExchange

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");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 19 with MockServerWebExchange

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();
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 20 with MockServerWebExchange

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");
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)224 Test (org.junit.jupiter.api.Test)216 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)61 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HttpHeaders (org.springframework.http.HttpHeaders)25 Resource (org.springframework.core.io.Resource)24 HandlerResult (org.springframework.web.reactive.HandlerResult)23 MethodParameter (org.springframework.core.MethodParameter)22 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)19 MediaType (org.springframework.http.MediaType)19 Mono (reactor.core.publisher.Mono)18 BeforeEach (org.junit.jupiter.api.BeforeEach)17 HttpMethod (org.springframework.http.HttpMethod)15 StepVerifier (reactor.test.StepVerifier)13 Arrays (java.util.Arrays)12 Collections (java.util.Collections)12 List (java.util.List)12 HttpStatus (org.springframework.http.HttpStatus)12 IOException (java.io.IOException)10