@Test public void optionalAndRequiredWithAnnotatedMethod() throws Exception { AnnotatedTestService service = new AnnotatedTestService(); Method method = service.getClass().getMethod("optionalAndRequiredHeader", String.class, Integer.class); MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method); processor.setUseSpelInvoker(true); optionalAndRequiredWithAnnotatedMethodGuts(processor, false); }
@Test public void optionalAndRequiredDottedWithAnnotatedMethod() throws Exception { AnnotatedTestService service = new AnnotatedTestService(); Method method = service.getClass().getMethod("optionalAndRequiredDottedHeader", String.class, Integer.class); MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method); processor.setUseSpelInvoker(true); optionalAndRequiredDottedWithAnnotatedMethodGuts(processor, false); }
@Test public void testProcessMessageMethodNotFound() throws Exception { expected.expect(new ExceptionCauseMatcher(SpelEvaluationException.class)); TestDifferentErrorService service = new TestDifferentErrorService(); Method method = TestErrorService.class.getMethod("checked", String.class); MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method); processor.setUseSpelInvoker(true); processor.setBeanFactory(mock(BeanFactory.class)); processor.processMessage(new GenericMessage<>("foo")); }
@Test public void compiledOptionalAndRequiredWithAnnotatedMethod() throws Exception { AnnotatedTestService service = new AnnotatedTestService(); Method method = service.getClass().getMethod("optionalAndRequiredHeader", String.class, Integer.class); MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method); processor.setUseSpelInvoker(true); DirectFieldAccessor compilerConfigAccessor = compileImmediate(processor); optionalAndRequiredWithAnnotatedMethodGuts(processor, true); assertNotNull(TestUtils.getPropertyValue(processor, "delegate.handlerMethod.expression.compiledAst")); optionalAndRequiredWithAnnotatedMethodGuts(processor, true); compilerConfigAccessor.setPropertyValue("compilerMode", SpelCompilerMode.OFF); }
@Test public void compiledOptionalAndRequiredDottedWithAnnotatedMethod() throws Exception { AnnotatedTestService service = new AnnotatedTestService(); Method method = service.getClass().getMethod("optionalAndRequiredDottedHeader", String.class, Integer.class); MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method); processor.setUseSpelInvoker(true); DirectFieldAccessor compilerConfigAccessor = compileImmediate(processor); optionalAndRequiredDottedWithAnnotatedMethodGuts(processor, true); assertNotNull(TestUtils.getPropertyValue(processor, "delegate.handlerMethod.expression.compiledAst")); optionalAndRequiredDottedWithAnnotatedMethodGuts(processor, true); compilerConfigAccessor.setPropertyValue("compilerMode", SpelCompilerMode.OFF); }
MethodInvokingMessageProcessor<Service> processor = new MethodInvokingMessageProcessor<>(service, "handle"); processor.setConversionService(conversionService); processor.setUseSpelInvoker(true); processor.setBeanFactory(beanFactory); ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
@Test public void testCollectionIsConverted() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); DefaultConversionService conversionService = new DefaultConversionService(); conversionService.addConverter(new Converter<Foo, Bar>() { // Must be explicit type with generics @Override public Bar convert(Foo source) { return new Bar(); } }); BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter(conversionService); beanFactory.setConversionService(conversionService); typeConverter.setBeanFactory(beanFactory); Service service = new Service(); MethodInvokingMessageProcessor<Service> processor = new MethodInvokingMessageProcessor<>(service, "handle"); processor.setConversionService(conversionService); processor.setUseSpelInvoker(true); processor.setBeanFactory(beanFactory); ServiceActivatingHandler handler = new ServiceActivatingHandler(processor); QueueChannel replyChannel = new QueueChannel(); handler.setOutputChannel(replyChannel); handler.handleMessage(new GenericMessage<Collection<Foo>>(Collections.singletonList(new Foo()))); Message<?> message = replyChannel.receive(10000); assertNotNull(message); assertEquals("baz", message.getPayload()); }