Search in sources :

Example 81 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class CompositeRequestConditionTests method match.

@Test
public void match() {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/path?param1=paramValue1").toExchange();
    RequestCondition<?> condition1 = new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST);
    RequestCondition<?> condition2 = new RequestMethodsRequestCondition(RequestMethod.GET);
    CompositeRequestCondition composite1 = new CompositeRequestCondition(this.param1, condition1);
    CompositeRequestCondition composite2 = new CompositeRequestCondition(this.param1, condition2);
    assertEquals(composite2, composite1.getMatchingCondition(exchange));
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 82 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class CachingResourceResolverTests method resolveResourceInternalNoMatch.

@Test
public void resolveResourceInternalNoMatch() {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    assertNull(this.chain.resolveResource(exchange, "invalid.css", this.locations).block(TIMEOUT));
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 83 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class CachingResourceResolverTests method resolveResourceAcceptEncodingInCacheKey.

@Test
public void resolveResourceAcceptEncodingInCacheKey() {
    String file = "bar.css";
    MockServerWebExchange exchange = MockServerHttpRequest.get(file).header("Accept-Encoding", "gzip").toExchange();
    Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
    String cacheKey = CachingResourceResolver.RESOLVED_RESOURCE_CACHE_KEY_PREFIX + file + "+encoding=gzip";
    assertEquals(expected, this.cache.get(cacheKey).get());
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 84 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class CachingResourceResolverTests method resolveResourceInternal.

@Test
public void resolveResourceInternal() {
    String file = "bar.css";
    Resource expected = new ClassPathResource("test/" + file, getClass());
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    Resource actual = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
    assertEquals(expected, actual);
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 85 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class CssLinkResourceTransformerTests method transformExtLinksNotAllowed.

@Test
public void transformExtLinksNotAllowed() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/static/external.css").toExchange();
    ResourceResolverChain resolverChain = Mockito.mock(DefaultResourceResolverChain.class);
    ResourceTransformerChain transformerChain = new DefaultResourceTransformerChain(resolverChain, Collections.singletonList(new CssLinkResourceTransformer()));
    Resource externalCss = new ClassPathResource("test/external.css", getClass());
    StepVerifier.create(transformerChain.transform(exchange, externalCss).cast(TransformedResource.class)).consumeNextWith(resource -> {
        String expected = "@import url(\"http://example.org/fonts/css\");\n" + "body { background: url(\"file:///home/spring/image.png\") }\n" + "figure { background: url(\"//example.org/style.css\")}";
        String result = new String(resource.getByteArray(), StandardCharsets.UTF_8);
        result = StringUtils.deleteAny(result, "\r");
        assertEquals(expected, result);
    }).expectComplete().verify();
    Mockito.verify(resolverChain, Mockito.never()).resolveUrlPath("http://example.org/fonts/css", Collections.singletonList(externalCss));
    Mockito.verify(resolverChain, Mockito.never()).resolveUrlPath("file:///home/spring/image.png", Collections.singletonList(externalCss));
    Mockito.verify(resolverChain, Mockito.never()).resolveUrlPath("//example.org/style.css", Collections.singletonList(externalCss));
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)135 Test (org.junit.Test)127 ClassPathResource (org.springframework.core.io.ClassPathResource)19 Resource (org.springframework.core.io.Resource)19 HandlerResult (org.springframework.web.reactive.HandlerResult)17 MethodParameter (org.springframework.core.MethodParameter)15 MediaType (org.springframework.http.MediaType)8 Instant (java.time.Instant)7 HttpHeaders (org.springframework.http.HttpHeaders)5 MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)5 FileSystemResource (org.springframework.core.io.FileSystemResource)3 UrlResource (org.springframework.core.io.UrlResource)3 DataBuffer (org.springframework.core.io.buffer.DataBuffer)3 CompositeContentTypeResolver (org.springframework.web.reactive.accept.CompositeContentTypeResolver)3 RequestedContentTypeResolverBuilder (org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Assert.assertSame (org.junit.Assert.assertSame)2 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)2