Skip to content

Commit

Permalink
INT-4180: RecipientListRouterSpec Fix
Browse files Browse the repository at this point in the history
JIRA: https://jira.spring.io/browse/INT-4180

Use `if...else` for `null` in `recipient()` with `Expression`.

Add test.
  • Loading branch information
garyrussell authored and artembilan committed Dec 5, 2016
1 parent 7a78db8 commit 295d609
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Expand Up @@ -32,6 +32,7 @@
* An {@link AbstractRouterSpec} for a {@link RecipientListRouter}.
*
* @author Artem Bilan
* @author Gary Russell
*
* @since 5.0
*/
Expand Down Expand Up @@ -142,9 +143,14 @@ public RecipientListRouterSpec recipient(MessageChannel channel, String expressi
* @return the router spec.
*/
public RecipientListRouterSpec recipient(MessageChannel channel, Expression expression) {
ExpressionEvaluatingSelector selector = new ExpressionEvaluatingSelector(expression);
this.target.addRecipient(channel, selector);
this.componentsToRegister.add(selector);
if (expression != null) {
ExpressionEvaluatingSelector selector = new ExpressionEvaluatingSelector(expression);
this.target.addRecipient(channel, selector);
this.componentsToRegister.add(selector);
}
else {
this.target.addRecipient(channel);
}
return _this();
}

Expand Down
Expand Up @@ -61,6 +61,7 @@

/**
* @author Artem Bilan
* @author Gary Russell
*
* @since 5.0
*/
Expand Down Expand Up @@ -441,6 +442,10 @@ public void testPayloadTypeRouteFlow() {
@Qualifier("recipientListOrderResult")
private PollableChannel recipientListOrderResult;

@Autowired
@Qualifier("alwaysRecipient")
private QueueChannel alwaysRecipient;

@Test
@SuppressWarnings("unchecked")
public void testRecipientListRouterOrder() {
Expand All @@ -455,6 +460,8 @@ public void testRecipientListRouterOrder() {
assertNotNull(receive);
result = (AtomicReference<String>) receive.getPayload();
assertEquals("Hello World", result.get());

assertEquals(1, this.alwaysRecipient.getQueueSize());
}

@Autowired
Expand Down Expand Up @@ -582,7 +589,6 @@ public IntegrationFlow recipientListFlow() {
.get();
}


@Bean
public RoutingTestBean routingTestBean() {
return new RoutingTestBean();
Expand Down Expand Up @@ -646,6 +652,7 @@ public IntegrationFlow routerAsNonLastFlow() {
public IntegrationFlow recipientListOrderFlow() {
return f -> f
.routeToRecipients(r -> r
.recipient(alwaysRecipient())
.recipient("recipient2.input")
.recipient("recipient1.input"));
}
Expand Down Expand Up @@ -675,6 +682,11 @@ public PollableChannel recipientListOrderResult() {
return new QueueChannel();
}

@Bean
public QueueChannel alwaysRecipient() {
return new QueueChannel();
}

@Bean
public IntegrationFlow scatterGatherFlow() {
return f -> f
Expand Down

0 comments on commit 295d609

Please sign in to comment.