Search in sources :

Example 86 with MethodParameter

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

the class ModelAttributeMethodArgumentResolverTests method bindExistingSingle.

@Test
public void bindExistingSingle() throws Exception {
    Foo foo = new Foo();
    foo.setName("Jim");
    this.bindContext.getModel().addAttribute("foo", Single.just(foo));
    MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
    testBindFoo(parameter, value -> {
        assertEquals(Foo.class, value.getClass());
        return (Foo) value;
    });
    assertSame(foo, this.bindContext.getModel().asMap().get("foo"));
}
Also used : ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 87 with MethodParameter

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

the class ModelAttributeMethodArgumentResolverTests method createAndBindToSingle.

@Test
public void createAndBindToSingle() throws Exception {
    MethodParameter parameter = this.testMethod.annotPresent(ModelAttribute.class).arg(Single.class, Foo.class);
    testBindFoo(parameter, single -> {
        assertTrue(single.getClass().getName(), single instanceof Single);
        Object value = ((Single<?>) single).toBlocking().value();
        assertEquals(Foo.class, value.getClass());
        return (Foo) value;
    });
}
Also used : Single(rx.Single) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 88 with MethodParameter

use of org.springframework.core.MethodParameter 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;
    });
}
Also used : Mono(reactor.core.publisher.Mono) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 89 with MethodParameter

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

the class ModelAttributeMethodArgumentResolverTests method bindExisting.

@Test
public void bindExisting() throws Exception {
    Foo foo = new Foo();
    foo.setName("Jim");
    this.bindContext.getModel().addAttribute(foo);
    MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
    testBindFoo(parameter, value -> {
        assertEquals(Foo.class, value.getClass());
        return (Foo) value;
    });
    assertSame(foo, this.bindContext.getModel().asMap().get("foo"));
}
Also used : ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 90 with MethodParameter

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

the class ModelAttributeMethodArgumentResolverTests method validationError.

@Test
public void validationError() throws Exception {
    MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Foo.class);
    testValidationError(parameter, Function.identity());
}
Also used : ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Aggregations

MethodParameter (org.springframework.core.MethodParameter)322 Test (org.junit.Test)251 Method (java.lang.reflect.Method)65 ArrayList (java.util.ArrayList)35 RequestParam (org.springframework.web.bind.annotation.RequestParam)30 HandlerMethod (org.springframework.web.method.HandlerMethod)28 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)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