use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class ModelAttributeMethodArgumentResolverTests method bindExistingMonoToMono.
@Test
public void bindExistingMonoToMono() throws Exception {
Foo foo = new Foo();
foo.setName("Jim");
this.bindContext.getModel().addAttribute("foo", Mono.just(foo));
MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
testBindFoo(parameter, mono -> {
assertTrue(mono.getClass().getName(), mono instanceof Mono);
Object value = ((Mono<?>) mono).block(Duration.ofSeconds(5));
assertEquals(Foo.class, value.getClass());
return (Foo) value;
});
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class ModelInitializerTests method basic.
@SuppressWarnings("unchecked")
@Test
public void basic() throws Exception {
TestController controller = new TestController();
Validator validator = mock(Validator.class);
controller.setValidator(validator);
List<SyncInvocableHandlerMethod> binderMethods = getBinderMethods(controller);
List<InvocableHandlerMethod> attributeMethods = getAttributeMethods(controller);
WebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
BindingContext bindingContext = new InitBinderBindingContext(bindingInitializer, binderMethods);
this.modelInitializer.initModel(bindingContext, attributeMethods, this.exchange).block(Duration.ofMillis(5000));
WebExchangeDataBinder binder = bindingContext.createDataBinder(this.exchange, "name");
assertEquals(Collections.singletonList(validator), binder.getValidators());
Map<String, Object> model = bindingContext.getModel().asMap();
assertEquals(5, model.size());
Object value = model.get("bean");
assertEquals("Bean", ((TestBean) value).getName());
value = model.get("monoBean");
assertEquals("Mono Bean", ((Mono<TestBean>) value).block(Duration.ofMillis(5000)).getName());
value = model.get("singleBean");
assertEquals("Single Bean", ((Single<TestBean>) value).toBlocking().value().getName());
value = model.get("voidMethodBean");
assertEquals("Void Method Bean", ((TestBean) value).getName());
value = model.get("voidMonoMethodBean");
assertEquals("Void Mono Method Bean", ((TestBean) value).getName());
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class RequestBodyArgumentResolverTests method emptyBodyWithMono.
@Test
@SuppressWarnings("unchecked")
public void emptyBodyWithMono() throws Exception {
MethodParameter param = this.testMethod.annot(requestBody()).arg(Mono.class, String.class);
StepVerifier.create((Mono<Void>) resolveValueWithEmptyBody(param)).expectNextCount(0).expectError(ServerWebInputException.class).verify();
param = this.testMethod.annot(requestBody().notRequired()).arg(Mono.class, String.class);
StepVerifier.create((Mono<Void>) resolveValueWithEmptyBody(param)).expectNextCount(0).expectComplete().verify();
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method invokeMethodWithValue.
@Test
public void invokeMethodWithValue() throws Exception {
Mono<Object> resolvedValue = Mono.just("value1");
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
assertHandlerResultValue(mono, "success:value1");
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class HttpEntityArgumentResolverTests method httpEntityWithMonoBody.
@Test
public void httpEntityWithMonoBody() throws Exception {
ServerWebExchange exchange = postExchange("line1");
ResolvableType type = httpEntityType(Mono.class, String.class);
HttpEntity<Mono<String>> httpEntity = resolveValue(exchange, type);
assertEquals(exchange.getRequest().getHeaders(), httpEntity.getHeaders());
assertEquals("line1", httpEntity.getBody().block());
}
Aggregations