INTSAMPLES-19 Add Filter Discard Example
This commit is contained in:
@@ -16,4 +16,15 @@
|
||||
|
||||
<channel id="outputChannel"/>
|
||||
|
||||
<channel id="inputChannel2"/>
|
||||
|
||||
<filter input-channel="inputChannel2"
|
||||
output-channel="outputChannel"
|
||||
discard-channel="discardChannel2">
|
||||
<beans:bean class="org.springframework.integration.samples.testing.filter.PetFilter"/>
|
||||
</filter>
|
||||
|
||||
<channel id="outputChannel2"/>
|
||||
<channel id="discardChannel2"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -16,4 +16,18 @@
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<bridge input-channel="outputChannel2"
|
||||
output-channel="testChannel2"/>
|
||||
|
||||
<channel id="testChannel2">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<bridge input-channel="discardChannel2"
|
||||
output-channel="testDiscardChannel2"/>
|
||||
|
||||
<channel id="testDiscardChannel2">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
</beans:beans>
|
||||
@@ -41,6 +41,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* in this test case, we bridge it to a {@link QueueChannel} to
|
||||
* facilitate easy testing.
|
||||
*
|
||||
* Similarly, we bridge the discard channel which is configured on the second
|
||||
* filter instance.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 2.0.2
|
||||
*/
|
||||
@@ -51,9 +54,18 @@ public class PetFilterTests {
|
||||
@Autowired
|
||||
MessageChannel inputChannel;
|
||||
|
||||
@Autowired
|
||||
MessageChannel inputChannel2;
|
||||
|
||||
@Autowired
|
||||
QueueChannel testChannel;
|
||||
|
||||
@Autowired
|
||||
QueueChannel testChannel2;
|
||||
|
||||
@Autowired
|
||||
QueueChannel testDiscardChannel2;
|
||||
|
||||
@Test
|
||||
public void unitTestClassCat() {
|
||||
String payload = "CAT:Fluffy";
|
||||
@@ -100,4 +112,39 @@ public class PetFilterTests {
|
||||
assertNull("Expected no output message", outMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCatDiscard() {
|
||||
String payload = "CAT:Fluffy";
|
||||
Message<String> message = MessageBuilder.withPayload(payload).build();
|
||||
inputChannel2.send(message);
|
||||
Message<?> outMessage = testChannel2.receive(0);
|
||||
assertNull("Expected no output message", outMessage);
|
||||
outMessage = testDiscardChannel2.receive(0);
|
||||
assertNotNull("Expected discard message", outMessage);
|
||||
assertEquals(payload, message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDogDiscard() {
|
||||
String payload = "DOG:Fido";
|
||||
Message<String> message = MessageBuilder.withPayload(payload).build();
|
||||
inputChannel2.send(message);
|
||||
Message<?> outMessage = testChannel.receive(0);
|
||||
assertNotNull("Expected an output message", outMessage);
|
||||
assertEquals(payload, outMessage.getPayload());
|
||||
outMessage = testDiscardChannel2.receive(0);
|
||||
assertNull("Expected no discard message", outMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLizardDiscard() {
|
||||
String payload = "LIZARD:Scaly";
|
||||
Message<String> message = MessageBuilder.withPayload(payload).build();
|
||||
inputChannel2.send(message);
|
||||
Message<?> outMessage = testChannel.receive(0);
|
||||
assertNull("Expected no output message", outMessage);
|
||||
outMessage = testDiscardChannel2.receive(0);
|
||||
assertNotNull("Expected discard message", outMessage);
|
||||
assertEquals(payload, message.getPayload());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user