Skip to content

Commit 9f6457f

Browse files
committed
INT-4383: Add test for EnricherSpec.errorChannel
JIRA: https://jira.spring.io/browse/INT-4383
1 parent 061dcb1 commit 9f6457f

File tree

1 file changed

+23
-5
lines changed
  • spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers

1 file changed

+23
-5
lines changed

spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.springframework.integration.handler.advice.IdempotentReceiverInterceptor;
5555
import org.springframework.integration.selector.MetadataStoreSelector;
5656
import org.springframework.integration.support.MessageBuilder;
57-
import org.springframework.integration.transformer.DecodingTransformer;
5857
import org.springframework.messaging.Message;
5958
import org.springframework.messaging.MessageChannel;
6059
import org.springframework.messaging.MessageHeaders;
@@ -87,6 +86,11 @@ public class TransformerTests {
8786
@Qualifier("enricherInput3")
8887
private FixedSubscriberChannel enricherInput3;
8988

89+
@Autowired
90+
@Qualifier("enricherErrorChannel")
91+
private PollableChannel enricherErrorChannel;
92+
93+
9094

9195
@Test
9296
public void testContentEnricher() {
@@ -104,6 +108,11 @@ public void testContentEnricher() {
104108
assertEquals("Bar Bar", result.getName());
105109
assertNotNull(result.getDate());
106110
assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate()));
111+
112+
this.enricherInput.send(new GenericMessage<>(new TestPojo("junk")));
113+
114+
Message<?> errorMessage = this.enricherErrorChannel.receive(10_000);
115+
assertNotNull(errorMessage);
107116
}
108117

109118
@Test
@@ -237,10 +246,16 @@ public void transformWithHeader() {
237246
@EnableIntegration
238247
public static class ContextConfiguration {
239248

249+
@Bean
250+
public PollableChannel enricherErrorChannel() {
251+
return new QueueChannel();
252+
}
253+
240254
@Bean
241255
public IntegrationFlow enricherFlow() {
242256
return IntegrationFlows.from("enricherInput", true)
243257
.enrich(e -> e.requestChannel("enrichChannel")
258+
.errorChannel(enricherErrorChannel())
244259
.requestPayloadExpression("payload")
245260
.shouldClonePayload(false)
246261
.propertyExpression("name", "payload['name']")
@@ -275,7 +290,12 @@ public IntegrationFlow enricherFlow3() {
275290
@Bean
276291
public IntegrationFlow enrichFlow() {
277292
return IntegrationFlows.from("enrichChannel")
278-
.<TestPojo, Map<?, ?>>transform(p -> Collections.singletonMap("name", p.getName() + " Bar"))
293+
.<TestPojo, Map<?, ?>>transform(p -> {
294+
if ("junk".equals(p.getName())) {
295+
throw new RuntimeException("intentional");
296+
}
297+
return Collections.singletonMap("name", p.getName() + " Bar");
298+
})
279299
.get();
280300
}
281301

@@ -298,10 +318,8 @@ public IntegrationFlow encodingFlow() {
298318

299319
@Bean
300320
public IntegrationFlow decodingFlow() {
301-
// TODO: Stored in an unnecessary variable to work around an eclipse type inference issue.
302-
DecodingTransformer<Integer> transformer = Transformers.decoding(new MyCodec(), m -> Integer.class);
303321
return f -> f
304-
.transform(transformer)
322+
.transform(Transformers.decoding(new MyCodec(), m -> Integer.class))
305323
.channel("codecReplyChannel");
306324
}
307325

0 commit comments

Comments
 (0)