Search in sources :

Example 56 with MockServerHttpResponse

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.

the class KotlinScriptTemplateTests method renderTemplateWithEnglishLocale.

@Test
public void renderTemplateWithEnglishLocale() throws Exception {
    Map<String, Object> model = new HashMap<>();
    model.put("foo", "Foo");
    String url = "org/springframework/web/reactive/result/view/script/kotlin/template.kts";
    MockServerHttpResponse response = render(url, model, Locale.ENGLISH, ScriptTemplatingConfiguration.class);
    assertThat(response.getBodyAsString().block()).isEqualTo("<html><body>\n<p>Hello Foo</p>\n</body></html>");
}
Also used : HashMap(java.util.HashMap) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 57 with MockServerHttpResponse

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.

the class KotlinScriptTemplateTests method renderTemplateWithFrenchLocale.

@Test
public void renderTemplateWithFrenchLocale() throws Exception {
    Map<String, Object> model = new HashMap<>();
    model.put("foo", "Foo");
    String url = "org/springframework/web/reactive/result/view/script/kotlin/template.kts";
    MockServerHttpResponse response = render(url, model, Locale.FRENCH, ScriptTemplatingConfiguration.class);
    assertThat(response.getBodyAsString().block()).isEqualTo("<html><body>\n<p>Bonjour Foo</p>\n</body></html>");
}
Also used : HashMap(java.util.HashMap) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 58 with MockServerHttpResponse

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.

the class KotlinScriptTemplateTests method renderTemplateWithoutRenderFunction.

@Test
public void renderTemplateWithoutRenderFunction() throws Exception {
    Map<String, Object> model = new HashMap<>();
    model.put("header", "<html><body>");
    model.put("hello", "Hello");
    model.put("foo", "Foo");
    model.put("footer", "</body></html>");
    String url = "org/springframework/web/reactive/result/view/script/kotlin/eval.kts";
    Class<?> configClass = ScriptTemplatingConfigurationWithoutRenderFunction.class;
    MockServerHttpResponse response = render(url, model, Locale.ENGLISH, configClass);
    assertThat(response.getBodyAsString().block()).isEqualTo("<html><body>\n<p>Hello Foo</p>\n</body></html>");
}
Also used : HashMap(java.util.HashMap) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 59 with MockServerHttpResponse

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.

the class ViewResolutionResultHandlerTests method contentNegotiationWithRedirect.

// SPR-15291
@Test
public void contentNegotiationWithRedirect() {
    HandlerResult handlerResult = new HandlerResult(new Object(), "redirect:/", on(Handler.class).annotNotPresent(ModelAttribute.class).resolveReturnType(String.class), this.bindingContext);
    UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
    viewResolver.setApplicationContext(new StaticApplicationContext());
    ViewResolutionResultHandler resultHandler = resultHandler(viewResolver);
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON));
    resultHandler.handleResult(exchange, handlerResult).block(Duration.ZERO);
    MockServerHttpResponse response = exchange.getResponse();
    assertThat(response.getStatusCode().value()).isEqualTo(303);
    assertThat(response.getHeaders().getLocation().toString()).isEqualTo("/");
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) HandlerResult(org.springframework.web.reactive.HandlerResult) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 60 with MockServerHttpResponse

use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.

the class NashornScriptTemplateTests method renderTemplateWithUrl.

// SPR-13453
@Test
public void renderTemplateWithUrl() throws Exception {
    String url = "org/springframework/web/reactive/result/view/script/nashorn/template.html";
    Class<?> configClass = ScriptTemplatingWithUrlConfiguration.class;
    MockServerHttpResponse response = render(url, null, configClass);
    assertThat(response.getBodyAsString().block()).isEqualTo(("<html><head><title>Check url parameter</title></head><body><p>" + url + "</p></body></html>"));
}
Also used : MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)64 Test (org.junit.jupiter.api.Test)55 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)28 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)24 HttpHandler (org.springframework.http.server.reactive.HttpHandler)14 HttpHeaders (org.springframework.http.HttpHeaders)13 Flux (reactor.core.publisher.Flux)13 Mono (reactor.core.publisher.Mono)13 Collections (java.util.Collections)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 DataBuffer (org.springframework.core.io.buffer.DataBuffer)11 MultiValueMap (org.springframework.util.MultiValueMap)11 StandardCharsets (java.nio.charset.StandardCharsets)10 HttpStatus (org.springframework.http.HttpStatus)10 ResponseCookie (org.springframework.http.ResponseCookie)10 ServerWebExchange (org.springframework.web.server.ServerWebExchange)10 WebFilter (org.springframework.web.server.WebFilter)10 StepVerifier (reactor.test.StepVerifier)10