use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method illegalArgumentExceptionIsWrappedWithInvocationDetails.
@Test
public void illegalArgumentExceptionIsWrappedWithInvocationDetails() throws Exception {
Mono<Object> resolvedValue = Mono.just(1);
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
try {
mono.block();
fail("Expected IllegalStateException");
} catch (IllegalStateException ex) {
assertThat(ex.getMessage(), is("Failed to invoke handler method with resolved arguments: " + "[0][type=java.lang.Integer][value=1] " + "on " + method.toGenericString()));
}
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method resolverThrowsException.
@Test
public void resolverThrowsException() throws Exception {
Mono<Object> resolvedValue = Mono.error(new UnsupportedMediaTypeStatusException("boo"));
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
try {
mono.block();
fail("Expected UnsupportedMediaTypeStatusException");
} catch (UnsupportedMediaTypeStatusException ex) {
assertThat(ex.getMessage(), is("Request failure [status: 415, reason: \"boo\"]"));
}
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method noMatchingResolver.
@Test
public void noMatchingResolver() throws Exception {
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method);
try {
mono.block();
fail("Expected IllegalStateException");
} catch (IllegalStateException ex) {
assertThat(ex.getMessage(), is("No suitable resolver for argument 0 of type 'java.lang.String' " + "on " + method.toGenericString()));
}
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method invokeMethodWithNoValue.
@Test
public void invokeMethodWithNoValue() throws Exception {
Mono<Object> resolvedValue = Mono.empty();
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
assertHandlerResultValue(mono, "success:null");
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class FormHttpMessageWriter method write.
@Override
public Mono<Void> write(Publisher<? extends MultiValueMap<String, String>> inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage outputMessage, Map<String, Object> hints) {
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType == null) {
contentType = MediaType.APPLICATION_FORM_URLENCODED;
outputMessage.getHeaders().setContentType(contentType);
}
Charset charset = getMediaTypeCharset(contentType);
return Flux.from(inputStream).single().map(form -> generateForm(form, charset)).then(value -> {
ByteBuffer byteBuffer = charset.encode(value);
DataBuffer buffer = outputMessage.bufferFactory().wrap(byteBuffer);
outputMessage.getHeaders().setContentLength(byteBuffer.remaining());
return outputMessage.writeWith(Mono.just(buffer));
});
}
Aggregations