Search in sources :

Example 66 with MockServerWebExchange

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

the class JythonScriptTemplateTests method renderViewWithModel.

private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model) throws Exception {
    ScriptTemplateView view = createViewWithUrl(viewUrl);
    MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
    return exchange.getResponse();
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange)

Example 67 with MockServerWebExchange

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

the class NashornScriptTemplateTests method renderViewWithModel.

private MockServerHttpResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Class<?> configuration) throws Exception {
    ScriptTemplateView view = createViewWithUrl(viewUrl, configuration);
    MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    view.renderInternal(model, MediaType.TEXT_HTML, exchange).block();
    return exchange.getResponse();
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange)

Example 68 with MockServerWebExchange

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

the class ResourceHandlerRegistryTests method mapPathToLocation.

@Test
public void mapPathToLocation() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/testStylesheet.css");
    ResourceWebHandler handler = getHandler("/resources/**");
    handler.handle(exchange).block(Duration.ofSeconds(5));
    StepVerifier.create(exchange.getResponse().getBody()).consumeNextWith(buf -> assertEquals("test stylesheet content", DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8))).expectComplete().verify();
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) Test(org.junit.Test)

Example 69 with MockServerWebExchange

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

the class ResourceTransformerSupportTests method resolveUrlPath.

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

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

the class ResourceWebHandlerTests method getResourceFromSubDirectory.

@Test
public void getResourceFromSubDirectory() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("").toExchange();
    setPathWithinHandlerMapping(exchange, "js/foo.js");
    this.handler.handle(exchange).block(TIMEOUT);
    assertEquals(MediaType.parseMediaType("text/javascript"), exchange.getResponse().getHeaders().getContentType());
    assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }");
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) 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