use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class RouterFunctionsTests method toHttpHandlerNormal.
@Test
public void toHttpHandlerNormal() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.accepted().build();
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.ACCEPTED, httpResponse.getStatusCode());
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class RouterFunctionsTests method toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo.
@Test
public void toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = // Mono.<ServerResponse> is required for compilation in Eclipse
request -> Mono.<ServerResponse>just(new ServerResponse() {
@Override
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@Override
public HttpHeaders headers() {
return new HttpHeaders();
}
@Override
public Mono<Void> writeTo(ServerWebExchange exchange, HandlerStrategies strategies) {
return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found"));
}
});
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.NOT_FOUND, httpResponse.getStatusCode());
}
use of org.springframework.mock.http.server.reactive.test.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");
MockServerHttpResponse response = renderViewWithModel("org/springframework/web/reactive/result/view/script/kotlin/template.kts", model, Locale.FRENCH, ScriptTemplatingConfiguration.class);
assertEquals("<html><body>\n<p>Bonjour Foo</p>\n</body></html>", response.getBodyAsString().block());
}
use of org.springframework.mock.http.server.reactive.test.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");
MockServerHttpResponse response = renderViewWithModel("org/springframework/web/reactive/result/view/script/kotlin/template.kts", model, Locale.ENGLISH, ScriptTemplatingConfiguration.class);
assertEquals("<html><body>\n<p>Hello Foo</p>\n</body></html>", response.getBodyAsString().block());
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpResponse in project spring-framework by spring-projects.
the class NashornScriptTemplateTests method renderTemplateWithUrl.
// SPR-13453
@Test
public void renderTemplateWithUrl() throws Exception {
MockServerHttpResponse response = renderViewWithModel("org/springframework/web/reactive/result/view/script/nashorn/template.html", null, ScriptTemplatingWithUrlConfiguration.class);
assertEquals("<html><head><title>Check url parameter</title></head><body><p>org/springframework/web/reactive/result/view/script/nashorn/template.html</p></body></html>", response.getBodyAsString().block());
}
Aggregations