Java DSL: Fix EnricherSpec to prevent assertions

Fixes: https://github.com/spring-projects/spring-integration-extensions/issues/101
This commit is contained in:
Tim Ysewyn
2014-08-20 14:14:20 +02:00
committed by Artem Bilan
parent 501209384b
commit 1b1f95c004
2 changed files with 76 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.util.Assert;
/**
* @author Artem Bilan
* @author Tim Ysewyn
*/
public class EnricherSpec extends MessageHandlerSpec<EnricherSpec, ContentEnricher> {
@@ -128,8 +129,12 @@ public class EnricherSpec extends MessageHandlerSpec<EnricherSpec, ContentEnrich
@Override
protected ContentEnricher doGet() {
this.enricher.setPropertyExpressions(this.propertyExpressions);
this.enricher.setHeaderExpressions(this.headerExpressions);
if(!this.propertyExpressions.isEmpty()) {
this.enricher.setPropertyExpressions(this.propertyExpressions);
}
if(!this.headerExpressions.isEmpty()) {
this.enricher.setHeaderExpressions(this.headerExpressions);
}
return this.enricher;
}

View File

@@ -150,6 +150,7 @@ import de.flapdoodle.embed.process.runtime.Network;
/**
* @author Artem Bilan
* @author Tim Ysewyn
*/
@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
@RunWith(SpringJUnit4ClassRunner.class)
@@ -230,6 +231,14 @@ public class IntegrationFlowTests {
@Qualifier("enricherInput")
private FixedSubscriberChannel enricherInput;
@Autowired
@Qualifier("enricherInput2")
private FixedSubscriberChannel enricherInput2;
@Autowired
@Qualifier("enricherInput3")
private FixedSubscriberChannel enricherInput3;
@Autowired
@Qualifier("splitInput")
private MessageChannel splitInput;
@@ -562,6 +571,41 @@ public class IntegrationFlowTests {
assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate()));
}
@Test
public void testContentEnricher2() {
QueueChannel replyChannel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar"))
.setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel)
.build();
this.enricherInput2.send(message);
Message<?> receive = replyChannel.receive(5000);
assertNotNull(receive);
assertNull(receive.getHeaders().get("foo"));
Object payload = receive.getPayload();
assertThat(payload, instanceOf(TestPojo.class));
TestPojo result = (TestPojo) payload;
assertEquals("Bar Bar", result.getName());
assertNotNull(result.getDate());
assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate()));
}
@Test
public void testContentEnricher3() {
QueueChannel replyChannel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar"))
.setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel)
.build();
this.enricherInput3.send(message);
Message<?> receive = replyChannel.receive(5000);
assertNotNull(receive);
assertEquals("Bar Bar", receive.getHeaders().get("foo"));
Object payload = receive.getPayload();
assertThat(payload, instanceOf(TestPojo.class));
TestPojo result = (TestPojo) payload;
assertEquals("Bar", result.getName());
assertNull(result.getDate());
}
@Test
public void testSplitterResequencer() {
QueueChannel replyChannel = new QueueChannel();
@@ -1404,6 +1448,31 @@ public class IntegrationFlowTests {
.get();
}
@Bean
@DependsOn("enrichFlow")
public IntegrationFlow enricherFlow2() {
return IntegrationFlows.fromFixedMessageChannel("enricherInput2")
.enrich(e -> e.requestChannel("enrichChannel")
.requestPayloadExpression("payload")
.shouldClonePayload(false)
.propertyExpression("name", "payload['name']")
.propertyExpression("date", "new java.util.Date()")
)
.get();
}
@Bean
@DependsOn("enrichFlow")
public IntegrationFlow enricherFlow3() {
return IntegrationFlows.fromFixedMessageChannel("enricherInput3")
.enrich(e -> e.requestChannel("enrichChannel")
.requestPayloadExpression("payload")
.shouldClonePayload(false)
.headerExpression("foo", "payload['name']")
)
.get();
}
@Bean
public IntegrationFlow enrichFlow() {
return IntegrationFlows.from("enrichChannel")