use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MessageWriterResultHandlerTests method unsupportedReturnType.
// SPR-13135
@Test
public void unsupportedReturnType() throws Exception {
ByteArrayOutputStream body = new ByteArrayOutputStream();
MethodParameter type = on(TestController.class).resolveReturnType(OutputStream.class);
HttpMessageWriter<?> writer = new EncoderHttpMessageWriter<>(new ByteBufferEncoder());
Mono<Void> mono = initResultHandler(writer).writeBody(body, type, this.exchange);
StepVerifier.create(mono).expectError(IllegalStateException.class).verify();
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ModelAttributeMethodArgumentResolverTests method supportsWithDefaultResolution.
@Test
public void supportsWithDefaultResolution() throws Exception {
ModelAttributeMethodArgumentResolver resolver = new ModelAttributeMethodArgumentResolver(new ReactiveAdapterRegistry(), true);
MethodParameter param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(String.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, String.class);
assertFalse(resolver.supportsParameter(param));
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ModelAttributeMethodArgumentResolverTests method supports.
@Test
public void supports() throws Exception {
ModelAttributeMethodArgumentResolver resolver = new ModelAttributeMethodArgumentResolver(new ReactiveAdapterRegistry(), false);
MethodParameter param = this.testMethod.annotPresent(ModelAttribute.class).arg(Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Foo.class);
assertFalse(resolver.supportsParameter(param));
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ModelAttributeMethodArgumentResolverTests method testValidationError.
private void testValidationError(MethodParameter param, Function<Mono<?>, Mono<?>> valueMonoExtractor) throws URISyntaxException {
ServerWebExchange exchange = postForm("age=invalid");
Mono<?> mono = createResolver().resolveArgument(param, this.bindContext, exchange);
mono = valueMonoExtractor.apply(mono);
StepVerifier.create(mono).consumeErrorWith(ex -> {
assertTrue(ex instanceof WebExchangeBindException);
WebExchangeBindException bindException = (WebExchangeBindException) ex;
assertEquals(1, bindException.getErrorCount());
assertTrue(bindException.hasFieldErrors("age"));
}).verify();
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ModelAttributeMethodArgumentResolverTests method createAndBindToMono.
@Test
public void createAndBindToMono() throws Exception {
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;
});
}
Aggregations