INT-4180: RecipientListRouterSpec Fix
JIRA: https://jira.spring.io/browse/INT-4180 Use `if...else` for `null` in `recipient()` with `Expression`. Add test.
This commit is contained in:
committed by
Artem Bilan
parent
7a78db8db5
commit
295d609eb3
@@ -32,6 +32,7 @@ import org.springframework.util.StringUtils;
|
||||
* An {@link AbstractRouterSpec} for a {@link RecipientListRouter}.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@@ -142,9 +143,14 @@ public class RecipientListRouterSpec extends AbstractRouterSpec<RecipientListRou
|
||||
* @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();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@@ -441,6 +442,10 @@ public class RouterTests {
|
||||
@Qualifier("recipientListOrderResult")
|
||||
private PollableChannel recipientListOrderResult;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("alwaysRecipient")
|
||||
private QueueChannel alwaysRecipient;
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRecipientListRouterOrder() {
|
||||
@@ -455,6 +460,8 @@ public class RouterTests {
|
||||
assertNotNull(receive);
|
||||
result = (AtomicReference<String>) receive.getPayload();
|
||||
assertEquals("Hello World", result.get());
|
||||
|
||||
assertEquals(1, this.alwaysRecipient.getQueueSize());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -582,7 +589,6 @@ public class RouterTests {
|
||||
.get();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public RoutingTestBean routingTestBean() {
|
||||
return new RoutingTestBean();
|
||||
@@ -646,6 +652,7 @@ public class RouterTests {
|
||||
public IntegrationFlow recipientListOrderFlow() {
|
||||
return f -> f
|
||||
.routeToRecipients(r -> r
|
||||
.recipient(alwaysRecipient())
|
||||
.recipient("recipient2.input")
|
||||
.recipient("recipient1.input"));
|
||||
}
|
||||
@@ -675,6 +682,11 @@ public class RouterTests {
|
||||
return new QueueChannel();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public QueueChannel alwaysRecipient() {
|
||||
return new QueueChannel();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow scatterGatherFlow() {
|
||||
return f -> f
|
||||
|
||||
Reference in New Issue
Block a user