Search in sources :

Example 96 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method monoTestBean.

@Test
public void monoTestBean() throws Exception {
    String body = "{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}";
    ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
    MethodParameter param = this.testMethod.arg(type);
    Mono<Object> mono = resolveValue(param, body);
    assertEquals(new TestBean("FOOFOO", "BARBAR"), mono.block());
}
Also used : ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 97 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method validateFluxTestBean.

@Test
@SuppressWarnings("unchecked")
public void validateFluxTestBean() throws Exception {
    String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\"}]";
    ResolvableType type = forClassWithGenerics(Flux.class, TestBean.class);
    MethodParameter param = this.testMethod.arg(type);
    Flux<TestBean> flux = resolveValue(param, body);
    StepVerifier.create(flux).expectNext(new TestBean("f1", "b1")).expectError(ServerWebInputException.class).verify();
}
Also used : ServerWebInputException(org.springframework.web.server.ServerWebInputException) ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 98 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method validateMonoTestBean.

@Test
@SuppressWarnings("unchecked")
public void validateMonoTestBean() throws Exception {
    String body = "{\"bar\":\"b1\"}";
    ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
    MethodParameter param = this.testMethod.arg(type);
    Mono<TestBean> mono = resolveValue(param, body);
    StepVerifier.create(mono).expectNextCount(0).expectError(ServerWebInputException.class).verify();
}
Also used : ServerWebInputException(org.springframework.web.server.ServerWebInputException) ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 99 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class ErrorsArgumentResolverTests method supports.

@Test
public void supports() throws Exception {
    MethodParameter parameter = this.testMethod.arg(Errors.class);
    assertTrue(this.resolver.supportsParameter(parameter));
    parameter = this.testMethod.arg(BindingResult.class);
    assertTrue(this.resolver.supportsParameter(parameter));
}
Also used : BindingResult(org.springframework.validation.BindingResult) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 100 with MethodParameter

use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.

the class ErrorsArgumentResolverTests method doesNotSupport.

@Test
public void doesNotSupport() throws Exception {
    MethodParameter parameter = this.testMethod.arg(String.class);
    assertFalse(this.resolver.supportsParameter(parameter));
    try {
        parameter = this.testMethod.arg(ResolvableType.forClassWithGenerics(Mono.class, Errors.class));
        assertFalse(this.resolver.supportsParameter(parameter));
        fail();
    } catch (IllegalStateException ex) {
        assertTrue("Unexpected error message:\n" + ex.getMessage(), ex.getMessage().startsWith("ErrorsMethodArgumentResolver doesn't support reactive type wrapper"));
    }
}
Also used : MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Aggregations

MethodParameter (org.springframework.core.MethodParameter)320 Test (org.junit.Test)251 Method (java.lang.reflect.Method)64 ArrayList (java.util.ArrayList)35 RequestParam (org.springframework.web.bind.annotation.RequestParam)30 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)27 HandlerMethod (org.springframework.web.method.HandlerMethod)27 Before (org.junit.Before)25 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)25 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)23 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)23 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)23 ResolvableType (org.springframework.core.ResolvableType)21 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)21 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)20 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)20 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)20 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)20 Mono (reactor.core.publisher.Mono)19