Search in sources :

Example 1 with AbstractSubscribableChannel

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);
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Field(java.lang.reflect.Field) AbstractSubscribableChannel(org.springframework.integration.channel.AbstractSubscribableChannel) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) List(java.util.List) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 List (java.util.List)1 Test (org.junit.Test)1 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)1 InputDestination (org.springframework.cloud.stream.binder.test.InputDestination)1 OutputDestination (org.springframework.cloud.stream.binder.test.OutputDestination)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 AbstractSubscribableChannel (org.springframework.integration.channel.AbstractSubscribableChannel)1