tested optional response flows
This commit is contained in:
@@ -97,8 +97,7 @@ public class FlowMessageHandlerFactoryBean extends AbstractSimpleMessageHandlerF
|
||||
this.flowConfiguration = this.flow.getFlowConfiguration().getConfigurationForInputPort(
|
||||
this.inputPortName);
|
||||
}
|
||||
Assert.notEmpty(this.flowConfiguration.getOutputPortNames(), "flow [" + this.flow.getBeanName()
|
||||
+ "] has no configured output ports");
|
||||
|
||||
|
||||
|
||||
bridgeMessagingPorts();
|
||||
|
||||
@@ -12,11 +12,14 @@ import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.core.SubscribableChannel;
|
||||
import org.springframework.integration.flow.config.FlowUtils;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public class FlowUtilsTest {
|
||||
@Test
|
||||
public void buildBridge(){
|
||||
|
||||
|
||||
SubscribableChannel inputChannel = new DirectChannel();
|
||||
SubscribableChannel outputChannel = new PublishSubscribeChannel();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.springframework.integration.flow.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.SubscribableChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/FlowWithOptionalResponseTest-context.xml")
|
||||
public class FlowWithOptionalResponseTest {
|
||||
@Autowired
|
||||
@Qualifier("inputC")
|
||||
MessageChannel input;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inputCO")
|
||||
MessageChannel inputForOptionalResponse;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("outputC")
|
||||
SubscribableChannel output;
|
||||
|
||||
@Test
|
||||
public void testOneWay() {
|
||||
|
||||
input.send(new GenericMessage<String>("hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionResponse() {
|
||||
TestMessageHandler counter = new TestMessageHandler();
|
||||
|
||||
output.subscribe(counter);
|
||||
|
||||
for (int i=0; i< 100; i++){
|
||||
inputForOptionalResponse.send(new GenericMessage<String>("hello"));
|
||||
}
|
||||
|
||||
assertTrue(String.valueOf(counter.count), counter.count >1 && counter.count < 100);
|
||||
}
|
||||
|
||||
static class TestMessageHandler implements MessageHandler {
|
||||
int count = 0;
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
24
src/test/resources/FlowWithOptionalResponseTest-context.xml
Normal file
24
src/test/resources/FlowWithOptionalResponseTest-context.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
|
||||
|
||||
<!-- Instantiate the flow -->
|
||||
<int-flow:flow id="no-response"/>
|
||||
<int-flow:flow id="optional-response"/>
|
||||
|
||||
<int-flow:outbound-gateway
|
||||
flow="no-response" input-channel="inputC"/>
|
||||
|
||||
<int-flow:outbound-gateway
|
||||
flow="optional-response" input-channel="inputCO" output-channel="outputC"/>
|
||||
|
||||
<int:channel id="outputC"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
|
||||
|
||||
<int-flow:flow-configuration>
|
||||
<int-flow:port-mapping>
|
||||
<int-flow:input-port name="input" channel="flow-input"/>
|
||||
</int-flow:port-mapping>
|
||||
</int-flow:flow-configuration>
|
||||
|
||||
<int:bridge input-channel="flow-input" output-channel="nullChannel"/>
|
||||
|
||||
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
|
||||
|
||||
<int-flow:flow-configuration>
|
||||
<int-flow:port-mapping>
|
||||
<int-flow:input-port name="input" channel="flow-input"/>
|
||||
<int-flow:output-port name="output" channel="flow-output"/>
|
||||
</int-flow:port-mapping>
|
||||
</int-flow:flow-configuration>
|
||||
|
||||
<int:filter input-channel="flow-input"
|
||||
output-channel="flow-output"
|
||||
expression="@random.nextInt(2)==0">
|
||||
</int:filter>
|
||||
|
||||
<bean id="random" class="java.util.Random"/>
|
||||
|
||||
<int:channel id="flow-output"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user