use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class RequestHeaderMethodArgumentResolverTests method resolveDefaultValue.
@Test
public void resolveDefaultValue() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedDefaultValueStringHeader, this.bindingContext, exchange);
Object result = mono.block();
assertTrue(result instanceof String);
assertEquals("bar", result);
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method modelWithAsyncAttributes.
@Test
public void modelWithAsyncAttributes() throws Exception {
this.bindingContext.getModel().addAttribute("attr1", Mono.just(new TestBean("Bean1"))).addAttribute("attr2", Flux.just(new TestBean("Bean1"), new TestBean("Bean2"))).addAttribute("attr3", Single.just(new TestBean("Bean2"))).addAttribute("attr4", Observable.just(new TestBean("Bean1"), new TestBean("Bean2"))).addAttribute("attr5", Mono.empty());
MethodParameter returnType = on(TestController.class).resolveReturnType(void.class);
HandlerResult result = new HandlerResult(new Object(), null, returnType, this.bindingContext);
ViewResolutionResultHandler handler = resultHandler(new TestViewResolver("account"));
MockServerWebExchange exchange = get("/account").toExchange();
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
assertResponseBody(exchange, "account: {" + "attr1=TestBean[name=Bean1], " + "attr2=[TestBean[name=Bean1], TestBean[name=Bean2]], " + "attr3=TestBean[name=Bean2], " + "attr4=[TestBean[name=Bean1], TestBean[name=Bean2]], " + "org.springframework.validation.BindingResult.attr1=" + "org.springframework.validation.BeanPropertyBindingResult: 0 errors, " + "org.springframework.validation.BindingResult.attr3=" + "org.springframework.validation.BeanPropertyBindingResult: 0 errors" + "}");
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method contentNegotiationWith406.
@Test
public void contentNegotiationWith406() throws Exception {
TestBean value = new TestBean("Joe");
MethodParameter returnType = on(TestController.class).resolveReturnType(TestBean.class);
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
MockServerWebExchange exchange = get("/account").accept(APPLICATION_JSON).toExchange();
ViewResolutionResultHandler resultHandler = resultHandler(new TestViewResolver("account"));
Mono<Void> mono = resultHandler.handleResult(exchange, handlerResult);
StepVerifier.create(mono).expectNextCount(0).expectError(NotAcceptableStatusException.class).verify();
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method statusCode.
@Test
public void statusCode() throws Exception {
ResponseEntity<Void> value = ResponseEntity.noContent().build();
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
HandlerResult result = handlerResult(value, returnType);
MockServerWebExchange exchange = get("/path").toExchange();
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.NO_CONTENT, exchange.getResponse().getStatusCode());
assertEquals(0, exchange.getResponse().getHeaders().size());
assertResponseBodyIsEmpty(exchange);
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class HttpMessageWriterViewTests method render.
@Test
public void render() throws Exception {
Map<String, String> pojoData = new LinkedHashMap<>();
pojoData.put("foo", "f");
pojoData.put("bar", "b");
this.model.addAttribute("pojoData", pojoData);
this.view.setModelKeys(Collections.singleton("pojoData"));
MockServerWebExchange exchange = MockServerHttpRequest.get("/path").toExchange();
this.view.render(this.model, MediaType.APPLICATION_JSON, exchange).block(Duration.ofSeconds(5));
StepVerifier.create(exchange.getResponse().getBody()).consumeNextWith(buf -> assertEquals("{\"foo\":\"f\",\"bar\":\"b\"}", DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8))).expectComplete().verify();
}
Aggregations