INT-3981: Add a couple <chain> tests

JIRA: https://jira.spring.io/browse/INT-3981

Since the `MessageHandlerChain` uses a `ReplyForwardingMessageChannel` in the end of invocation,
we don't need to have add an extra `<bridge>` for shifting just populated `replyChannel` header.

* Add a couple tests to prove that
* Fix the typos in the `ChainParserTests`
* Remove unnecessary `DirectFieldAccessor` usage in the `MessageHandlerChain`
This commit is contained in:
Artem Bilan
2016-04-06 17:32:19 -04:00
committed by Gary Russell
parent 4abc7861f0
commit ba2a713c75
3 changed files with 38 additions and 7 deletions

View File

@@ -20,7 +20,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.Lifecycle;
import org.springframework.integration.core.MessageProducer;
import org.springframework.integration.filter.MessageFilter;
@@ -129,7 +128,7 @@ public class MessageHandlerChain extends AbstractMessageProducingHandler impleme
// If this 'handler' is a nested non-last &lt;chain&gt;, it is necessary
// to 'force' re-init it for check its configuration in conjunction with current MessageHandlerChain.
if (handler instanceof MessageHandlerChain) {
new DirectFieldAccessor(handler).setPropertyValue("initialized", false);
((MessageHandlerChain) handler).initialized = false;
((MessageHandlerChain) handler).afterPropertiesSet();
}
}

View File

@@ -153,8 +153,8 @@
</recipient-list-router>
</chain>
<chain id="chainReplayRequired" input-channel="chainReplayRequiredChannel">
<transformer id="transformerReplayRequired" expression="null"/>
<chain id="chainReplyRequired" input-channel="chainReplyRequiredChannel">
<transformer id="transformerReplyRequired" expression="null"/>
</chain>
<chain id="chainMessageRejectedException" input-channel="chainMessageRejectedExceptionChannel">
@@ -191,4 +191,14 @@
<beans:bean id="messageStore" class="org.springframework.integration.store.SimpleMessageStore"/>
<chain id="chainWithNoOutput" input-channel="chainWithNoOutputChannel">
<header-enricher>
<reply-channel expression="headers.myReplyChannel"/>
</header-enricher>
</chain>
<chain id="chainWithTransformNoOutput" input-channel="chainWithTransformNoOutputChannel">
<transformer expression="headers.myMessage"/>
</chain>
</beans:beans>

View File

@@ -50,6 +50,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
@@ -157,11 +158,17 @@ public class ChainParserTests {
private PollableChannel numbers;
@Autowired
private MessageChannel chainReplayRequiredChannel;
private MessageChannel chainReplyRequiredChannel;
@Autowired
private MessageChannel chainMessageRejectedExceptionChannel;
@Autowired
private MessageChannel chainWithNoOutputChannel;
@Autowired
private MessageChannel chainWithTransformNoOutputChannel;
public static Message<?> successMessage = MessageBuilder.withPayload("success").build();
@Factory
@@ -419,12 +426,12 @@ public class ChainParserTests {
public void testInt2755SubComponentException() {
GenericMessage<String> testMessage = new GenericMessage<String>("test");
try {
this.chainReplayRequiredChannel.send(testMessage);
this.chainReplyRequiredChannel.send(testMessage);
fail("Expected ReplyRequiredException");
}
catch (Exception e) {
assertTrue(e instanceof ReplyRequiredException);
assertTrue(e.getMessage().contains("'chainReplayRequired$child.transformerReplayRequired'"));
assertTrue(e.getMessage().contains("'chainReplyRequired$child.transformerReplyRequired'"));
}
try {
@@ -438,6 +445,21 @@ public class ChainParserTests {
}
@Test
public void testChainWithNoOutput() {
QueueChannel replyChannel = new QueueChannel();
Message<String> message = MessageBuilder.withPayload("foo").setHeader("myReplyChannel", replyChannel).build();
this.chainWithNoOutputChannel.send(message);
Message<?> receive = replyChannel.receive(10000);
assertNotNull(receive);
message = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build();
Message<String> message2 = MessageBuilder.withPayload("bar").setHeader("myMessage", message).build();
this.chainWithTransformNoOutputChannel.send(message2);
receive = replyChannel.receive(10000);
assertNotNull(receive);
}
public static class StubHandler extends AbstractReplyProducingMessageHandler {
@Override