Search in sources :

Example 26 with MethodParameter

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

the class MessageMethodArgumentResolverTests method resolveWithConversionEmptyPayloadButNoConverter.

@Test
public void resolveWithConversionEmptyPayloadButNoConverter() throws Exception {
    this.resolver = new MessageMethodArgumentResolver();
    Message<String> message = MessageBuilder.withPayload("").build();
    MethodParameter parameter = new MethodParameter(this.method, 1);
    assertTrue(this.resolver.supportsParameter(parameter));
    thrown.expect(MessageConversionException.class);
    thrown.expectMessage("payload is empty");
    thrown.expectMessage(Integer.class.getName());
    thrown.expectMessage(String.class.getName());
    this.resolver.resolveArgument(parameter, message);
}
Also used : MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 27 with MethodParameter

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

the class MessageMethodArgumentResolverTests method resolveWithMessageSubclassAndPayloadWildcard.

@Test
public void resolveWithMessageSubclassAndPayloadWildcard() throws Exception {
    ErrorMessage message = new ErrorMessage(new UnsupportedOperationException());
    MethodParameter parameter = new MethodParameter(this.method, 0);
    assertTrue(this.resolver.supportsParameter(parameter));
    assertSame(message, this.resolver.resolveArgument(parameter, message));
}
Also used : ErrorMessage(org.springframework.messaging.support.ErrorMessage) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 28 with MethodParameter

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

the class MessageMethodArgumentResolverTests method resolveWithPayloadTypeAsWildcardAndNoConverter.

@Test
public void resolveWithPayloadTypeAsWildcardAndNoConverter() throws Exception {
    this.resolver = new MessageMethodArgumentResolver();
    Message<String> message = MessageBuilder.withPayload("test").build();
    MethodParameter parameter = new MethodParameter(this.method, 0);
    assertTrue(this.resolver.supportsParameter(parameter));
    assertSame(message, this.resolver.resolveArgument(parameter, message));
}
Also used : MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 29 with MethodParameter

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

the class MessageMethodArgumentResolverTests method resolveWithPayloadTypeUpperBound.

@Test
public void resolveWithPayloadTypeUpperBound() throws Exception {
    Message<Integer> message = MessageBuilder.withPayload(123).build();
    MethodParameter parameter = new MethodParameter(this.method, 3);
    assertTrue(this.resolver.supportsParameter(parameter));
    assertSame(message, this.resolver.resolveArgument(parameter, message));
}
Also used : MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 30 with MethodParameter

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

the class SendToMethodReturnValueHandlerTests method sendToUserWithSendToDefaultOverride.

// SPR-14238
@Test
public void sendToUserWithSendToDefaultOverride() throws Exception {
    given(this.messageChannel.send(any(Message.class))).willReturn(true);
    Class<?> clazz = SendToUserWithSendToOverrideTestBean.class;
    Method method = clazz.getDeclaredMethod("handleAndSendToDefaultDestination");
    MethodParameter parameter = new SynthesizingMethodParameter(method, -1);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, parameter, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    assertResponse(parameter, sessionId, 0, "/user/sess1/dest-default");
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) Message(org.springframework.messaging.Message) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) 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