From 9f6457fc313d84948cd4b70e6e41d559bdb691e8 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 23 Jan 2018 12:42:38 -0500 Subject: [PATCH] INT-4383: Add test for EnricherSpec.errorChannel JIRA: https://jira.spring.io/browse/INT-4383 --- .../dsl/transformers/TransformerTests.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java index 4f4c12a26d..da17e3b4d5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java @@ -54,7 +54,6 @@ import org.springframework.integration.dsl.channel.MessageChannels; import org.springframework.integration.handler.advice.IdempotentReceiverInterceptor; import org.springframework.integration.selector.MetadataStoreSelector; import org.springframework.integration.support.MessageBuilder; -import org.springframework.integration.transformer.DecodingTransformer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; @@ -87,6 +86,11 @@ public class TransformerTests { @Qualifier("enricherInput3") private FixedSubscriberChannel enricherInput3; + @Autowired + @Qualifier("enricherErrorChannel") + private PollableChannel enricherErrorChannel; + + @Test public void testContentEnricher() { @@ -104,6 +108,11 @@ public class TransformerTests { assertEquals("Bar Bar", result.getName()); assertNotNull(result.getDate()); assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate())); + + this.enricherInput.send(new GenericMessage<>(new TestPojo("junk"))); + + Message errorMessage = this.enricherErrorChannel.receive(10_000); + assertNotNull(errorMessage); } @Test @@ -237,10 +246,16 @@ public class TransformerTests { @EnableIntegration public static class ContextConfiguration { + @Bean + public PollableChannel enricherErrorChannel() { + return new QueueChannel(); + } + @Bean public IntegrationFlow enricherFlow() { return IntegrationFlows.from("enricherInput", true) .enrich(e -> e.requestChannel("enrichChannel") + .errorChannel(enricherErrorChannel()) .requestPayloadExpression("payload") .shouldClonePayload(false) .propertyExpression("name", "payload['name']") @@ -275,7 +290,12 @@ public class TransformerTests { @Bean public IntegrationFlow enrichFlow() { return IntegrationFlows.from("enrichChannel") - .>transform(p -> Collections.singletonMap("name", p.getName() + " Bar")) + .>transform(p -> { + if ("junk".equals(p.getName())) { + throw new RuntimeException("intentional"); + } + return Collections.singletonMap("name", p.getName() + " Bar"); + }) .get(); } @@ -298,10 +318,8 @@ public class TransformerTests { @Bean public IntegrationFlow decodingFlow() { - // TODO: Stored in an unnecessary variable to work around an eclipse type inference issue. - DecodingTransformer transformer = Transformers.decoding(new MyCodec(), m -> Integer.class); return f -> f - .transform(transformer) + .transform(Transformers.decoding(new MyCodec(), m -> Integer.class)) .channel("codecReplyChannel"); }