use of org.springframework.integration.channel.AbstractSubscribableChannel in project spring-cloud-stream by spring-cloud.
the class RoutingFunctionTests method testRoutingToConsumers.
@SuppressWarnings("unchecked")
@Test
public void testRoutingToConsumers() throws Exception {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(RoutingConsumerConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.routing-expression=headers['func_name']")) {
InputDestination inputDestination = context.getBean(InputDestination.class);
Message<byte[]> inputMessage = MessageBuilder.withPayload("foo".getBytes()).setHeader("func_name", "consume").build();
OutputDestination outputDestination = context.getBean(OutputDestination.class);
Field chField = ReflectionUtils.findField(outputDestination.getClass(), "channels");
chField.setAccessible(true);
List<AbstractSubscribableChannel> outputChannels = (List<AbstractSubscribableChannel>) chField.get(outputDestination);
assertThat(outputChannels.isEmpty());
inputDestination.send(inputMessage);
assertThat(outputChannels.isEmpty());
inputMessage = MessageBuilder.withPayload("foo".getBytes()).setHeader("func_name", "echo").build();
inputDestination.send(inputMessage);
assertThat(outputChannels.size()).isEqualTo(1);
}
}
Aggregations