Search in sources :

Example 26 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class CachingResourceResolverTests method resolveResourceInternalFromCache.

@Test
public void resolveResourceInternalFromCache() {
    Resource expected = Mockito.mock(Resource.class);
    this.cache.put(resourceKey("bar.css"), expected);
    MockServerWebExchange exchange = MockServerWebExchange.from(get(""));
    Resource actual = this.chain.resolveResource(exchange, "bar.css", this.locations).block(TIMEOUT);
    assertThat(actual).isSameAs(expected);
}
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 27 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class CachingResourceResolverTests method resolveResourceMatchingEncoding.

@Test
public void resolveResourceMatchingEncoding() {
    Resource resource = Mockito.mock(Resource.class);
    Resource gzipped = Mockito.mock(Resource.class);
    this.cache.put(resourceKey("bar.css"), resource);
    this.cache.put(resourceKey("bar.css+encoding=gzip"), gzipped);
    String file = "bar.css";
    MockServerWebExchange exchange = MockServerWebExchange.from(get(file));
    assertThat(this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT)).isSameAs(resource);
    exchange = MockServerWebExchange.from(get(file).header("Accept-Encoding", "gzip"));
    assertThat(this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT)).isSameAs(gzipped);
}
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 28 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class CssLinkResourceTransformerTests method transform.

@Test
public void transform() {
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/main.css"));
    Resource css = getResource("main.css");
    String expected = "\n" + "@import url(\"/static/bar-11e16cf79faee7ac698c805cf28248d2.css?#iefix\");\n" + "@import url('/static/bar-11e16cf79faee7ac698c805cf28248d2.css#bla-normal');\n" + "@import url(/static/bar-11e16cf79faee7ac698c805cf28248d2.css);\n\n" + "@import \"/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css\";\n" + "@import '/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css';\n\n" + "body { background: url(\"/static/images/image-f448cd1d5dba82b774f3202c878230b3.png?#iefix\") }\n";
    StepVerifier.create(this.transformerChain.transform(exchange, css).cast(TransformedResource.class)).consumeNextWith(transformedResource -> {
        String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
        result = StringUtils.deleteAny(result, "\r");
        assertThat(result).isEqualTo(expected);
    }).expectComplete().verify();
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) EncodedResource(org.springframework.web.reactive.resource.EncodedResourceResolver.EncodedResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 29 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class CssLinkResourceTransformerTests method transformSkippedForGzippedResource.

@Test
public void transformSkippedForGzippedResource(GzippedFiles gzippedFiles) throws Exception {
    gzippedFiles.create("main.css");
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/main.css"));
    Resource resource = getResource("main.css");
    EncodedResource gzipped = new EncodedResource(resource, "gzip", ".gz");
    StepVerifier.create(this.transformerChain.transform(exchange, gzipped)).expectNext(gzipped).expectComplete().verify();
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) EncodedResource(org.springframework.web.reactive.resource.EncodedResourceResolver.EncodedResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) EncodedResource(org.springframework.web.reactive.resource.EncodedResourceResolver.EncodedResource) Test(org.junit.jupiter.api.Test)

Example 30 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class CssLinkResourceTransformerTests method transformNoLinks.

@Test
public void transformNoLinks() {
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/foo.css"));
    Resource expected = getResource("foo.css");
    StepVerifier.create(this.transformerChain.transform(exchange, expected)).consumeNextWith(resource -> assertThat(resource).isSameAs(expected)).expectComplete().verify();
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) EncodedResource(org.springframework.web.reactive.resource.EncodedResourceResolver.EncodedResource) 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