Java Code Examples for org.springframework.messaging.handler.invocation.InvocableHandlerMethod#invoke()
The following examples show how to use
org.springframework.messaging.handler.invocation.InvocableHandlerMethod#invoke() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void customValidation() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.setValidator(new Validator() { @Override public boolean supports(Class<?> clazz) { return String.class.isAssignableFrom(clazz); } @Override public void validate(Object target, Errors errors) { String value = (String) target; if ("failure".equals(value)) { errors.reject("not a valid value"); } } }); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); thrown.expect(MethodArgumentNotValidException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); }
Example 2
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void overrideArgumentResolvers() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setArgumentResolvers(customResolvers); instance.afterPropertiesSet(); Message<String> message = MessageBuilder.withPayload("sample").build(); // This will work as the local resolver is set InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(message); assertMethodInvocation(sample, "customArgumentResolver"); // This won't work as no resolver is known for the payload InvocableHandlerMethod invocableHandlerMethod2 = createInvocableHandlerMethod(instance, "simpleString", String.class); assertThatExceptionOfType(MethodArgumentResolutionException.class).isThrownBy(() -> invocableHandlerMethod2.invoke(message)).withMessageContaining("No suitable resolver"); }
Example 3
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void customConversion() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() { @Override public String convert(SampleBean source) { return "foo bar"; } }); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build()); assertMethodInvocation(sample, "simpleString"); }
Example 4
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void overrideArgumentResolvers() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setArgumentResolvers(customResolvers); instance.afterPropertiesSet(); Message<String> message = MessageBuilder.withPayload("sample").build(); // This will work as the local resolver is set InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(message); assertMethodInvocation(sample, "customArgumentResolver"); // This won't work as no resolver is known for the payload InvocableHandlerMethod invocableHandlerMethod2 = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(IllegalStateException.class); thrown.expectMessage("No suitable resolver for"); invocableHandlerMethod2.invoke(message); }
Example 5
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void overrideArgumentResolvers() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setArgumentResolvers(customResolvers); instance.afterPropertiesSet(); Message<String> message = MessageBuilder.withPayload("sample").build(); // This will work as the local resolver is set InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(message); assertMethodInvocation(sample, "customArgumentResolver"); // This won't work as no resolver is known for the payload InvocableHandlerMethod invocableHandlerMethod2 = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MethodArgumentResolutionException.class); thrown.expectMessage("No suitable resolver"); invocableHandlerMethod2.invoke(message); }
Example 6
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void customConversion() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() { @Override public String convert(SampleBean source) { return "foo bar"; } }); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build()); assertMethodInvocation(sample, "simpleString"); }
Example 7
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void customValidation() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.setValidator(new Validator() { @Override public boolean supports(Class<?> clazz) { return String.class.isAssignableFrom(clazz); } @Override public void validate(Object target, Errors errors) { String value = (String) target; if ("failure".equals(value)) { errors.reject("not a valid value"); } } }); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); thrown.expect(MethodArgumentNotValidException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); }
Example 8
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void customConversion() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() { @Override public String convert(SampleBean source) { return "foo bar"; } }); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(sample).build()); assertMethodInvocation(sample, "simpleString"); }
Example 9
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void noValidationByDefault() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); assertMethodInvocation(sample, "payloadValidation"); }
Example 10
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void noValidationByDefault() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); assertMethodInvocation(sample, "payloadValidation"); }
Example 11
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void customArgumentResolver() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setCustomArgumentResolvers(customResolvers); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); assertMethodInvocation(sample, "customArgumentResolver"); }
Example 12
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void customMessageConverterFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); MessageConverter messageConverter = new ByteArrayMessageConverter(); instance.setMessageConverter(messageConverter); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example 13
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void customConversionServiceFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); assertFalse("conversion service should fail to convert payload", conversionService.canConvert(Integer.class, String.class)); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example 14
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customArgumentResolver() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setCustomArgumentResolvers(customResolvers); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); assertMethodInvocation(sample, "customArgumentResolver"); }
Example 15
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customMessageConverterFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); MessageConverter messageConverter = new ByteArrayMessageConverter(); instance.setMessageConverter(messageConverter); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example 16
Source File: DefaultMessageHandlerMethodFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customConversionServiceFailure() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); GenericConversionService conversionService = new GenericConversionService(); assertFalse("conversion service should fail to convert payload", conversionService.canConvert(Integer.class, String.class)); instance.setConversionService(conversionService); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "simpleString", String.class); thrown.expect(MessageConversionException.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); }
Example 17
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void noValidationByDefault() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "payloadValidation", String.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload("failure").build()); assertMethodInvocation(sample, "payloadValidation"); }
Example 18
Source File: DefaultMessageHandlerMethodFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void customArgumentResolver() throws Exception { DefaultMessageHandlerMethodFactory instance = createInstance(); List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>(); customResolvers.add(new CustomHandlerMethodArgumentResolver()); instance.setCustomArgumentResolvers(customResolvers); instance.afterPropertiesSet(); InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class); invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build()); assertMethodInvocation(sample, "customArgumentResolver"); }