Search in sources :

Example 26 with MockServerWebExchange

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

the class CssLinkResourceTransformerTests method transformNoLinks.

@Test
public void transformNoLinks() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/static/foo.css").toExchange();
    Resource expected = new ClassPathResource("test/foo.css", getClass());
    StepVerifier.create(this.transformerChain.transform(exchange, expected)).consumeNextWith(resource -> assertSame(expected, resource)).expectComplete().verify();
}
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 27 with MockServerWebExchange

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

the class HandlerResultHandlerTests method producibleMediaTypesRequestAttribute.

@Test
public void producibleMediaTypesRequestAttribute() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
    exchange.getAttributes().put(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(IMAGE_GIF));
    List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
    MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes);
    assertEquals(IMAGE_GIF, actual);
}
Also used : MediaType(org.springframework.http.MediaType) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 28 with MockServerWebExchange

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

the class HandlerResultHandlerTests method noConcreteMediaType.

// SPR-12894
@Test
public void noConcreteMediaType() throws Exception {
    List<MediaType> producible = Collections.singletonList(ALL);
    MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
    MediaType actual = this.resultHandler.selectMediaType(exchange, () -> producible);
    assertEquals(APPLICATION_OCTET_STREAM, actual);
}
Also used : MediaType(org.springframework.http.MediaType) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 29 with MockServerWebExchange

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

the class ResourceTransformerSupportTests method resolveUrlPathWithRelativePath.

@Test
public void resolveUrlPathWithRelativePath() throws Exception {
    Resource css = new ClassPathResource("test/main.css", getClass());
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    String actual = this.transformer.resolveUrlPath("bar.css", exchange, css, this.transformerChain).block(Duration.ofSeconds(5));
    assertEquals("bar-11e16cf79faee7ac698c805cf28248d2.css", 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 30 with MockServerWebExchange

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

the class ResourceWebHandlerTests method getResourceNoCache.

@Test
public void getResourceNoCache() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    setPathWithinHandlerMapping(exchange, "foo.css");
    this.handler.setCacheControl(CacheControl.noStore());
    this.handler.handle(exchange).block(TIMEOUT);
    MockServerHttpResponse response = exchange.getResponse();
    assertEquals("no-store", response.getHeaders().getCacheControl());
    assertTrue(response.getHeaders().containsKey("Last-Modified"));
    assertEquals(response.getHeaders().getLastModified() / 1000, resourceLastModifiedDate("test/foo.css") / 1000);
    assertEquals("bytes", response.getHeaders().getFirst("Accept-Ranges"));
    assertEquals(1, response.getHeaders().get("Accept-Ranges").size());
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MockServerHttpResponse(org.springframework.mock.http.server.reactive.test.MockServerHttpResponse) 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