@Test public void testCorrelationStrategyAdapterObjectMethod() { MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new SimpleMessageCorrelator(), ReflectionUtils.findMethod(SimpleMessageCorrelator.class, "getKey", Message.class)); adapter.setBeanFactory(mock(BeanFactory.class)); assertEquals("b", adapter.getCorrelationKey(message)); }
@Override public void afterPropertiesSet() throws Exception { if (this.target instanceof CorrelationStrategy && !StringUtils.hasText(this.methodName)) { this.strategy = (CorrelationStrategy) this.target; return; } if (this.target != null) { if (StringUtils.hasText(this.methodName)) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, this.methodName); } else { Method method = MessagingAnnotationUtils.findAnnotatedMethod(this.target, org.springframework.integration.annotation.CorrelationStrategy.class); if (method != null) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, method); } } } }
@Test public void testCorrelationStrategyRefAndMethod() throws Exception { EventDrivenConsumer endpoint = (EventDrivenConsumer) context .getBean("resequencerWithCorrelationStrategyRefAndMethod"); ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class); Object correlationStrategy = getPropertyValue(resequencer, "correlationStrategy"); assertEquals("The ResequencerEndpoint is not configured with a CorrelationStrategy adapter", MethodInvokingCorrelationStrategy.class, correlationStrategy.getClass()); MethodInvokingCorrelationStrategy adapter = (MethodInvokingCorrelationStrategy) correlationStrategy; assertEquals("foo", adapter.getCorrelationKey(MessageBuilder.withPayload("not important").build())); }
Method correlationStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, CorrelationStrategy.class); if (correlationStrategyMethod != null) { correlationStrategy = new MethodInvokingCorrelationStrategy(bean, correlationStrategyMethod);
@Test public void testHeadersPojoMethod() { MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new MultiHeaderCorrelator(), ReflectionUtils.findMethod(MultiHeaderCorrelator.class, "getKey", String.class, String.class)); adapter.setBeanFactory(mock(BeanFactory.class)); assertEquals("bd", adapter.getCorrelationKey(message)); }
@Override public void afterPropertiesSet() throws Exception { if (this.target instanceof CorrelationStrategy && !StringUtils.hasText(this.methodName)) { this.strategy = (CorrelationStrategy) this.target; return; } if (this.target != null) { if (StringUtils.hasText(this.methodName)) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, this.methodName); } else { Method method = MessagingAnnotationUtils.findAnnotatedMethod(this.target, org.springframework.integration.annotation.CorrelationStrategy.class); if (method != null) { this.strategy = new MethodInvokingCorrelationStrategy(this.target, method); } } } }
@Test public void testMethodName() { MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new SimpleMessageCorrelator(), "getKey"); adapter.setBeanFactory(mock(BeanFactory.class)); assertEquals("b", adapter.getCorrelationKey(message)); }
Method correlationStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, CorrelationStrategy.class); if (correlationStrategyMethod != null) { correlationStrategy = new MethodInvokingCorrelationStrategy(bean, correlationStrategyMethod);
@Test public void testHeaderPojoMethod() { MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new SimpleHeaderCorrelator(), "getKey"); adapter.setBeanFactory(mock(BeanFactory.class)); assertEquals("b", adapter.getCorrelationKey(message)); }
@Test public void testCorrelationStrategyAdapterPojoMethod() { MethodInvokingCorrelationStrategy adapter = new MethodInvokingCorrelationStrategy(new SimplePojoCorrelator(), "getKey"); adapter.setBeanFactory(mock(BeanFactory.class)); assertEquals("foo", adapter.getCorrelationKey(message)); }