use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class ExplicitBindingTests method testExplicitBindingsWithExistingConsumer.
@Test
public void testExplicitBindingsWithExistingConsumer() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ConsumerConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.output-bindings=consume")) {
assertThat(context.getBean("consume-in-0", MessageChannel.class)).isNotNull();
assertThat(context.getBean("consume-out-0", MessageChannel.class)).isNotNull();
}
}
use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class RoutingFunctionTests method testRoutingViaExplicitDefinitionAndDefinitionHeader.
@Test
public void testRoutingViaExplicitDefinitionAndDefinitionHeader() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(RoutingFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=" + RoutingFunction.FUNCTION_NAME)) {
InputDestination inputDestination = context.getBean(InputDestination.class);
OutputDestination outputDestination = context.getBean(OutputDestination.class);
Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).setHeader("spring.cloud.function.definition", "echo|uppercase").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build();
inputDestination.send(inputMessage);
Message<byte[]> outputMessage = outputDestination.receive();
assertThat(outputMessage.getPayload()).isEqualTo("HELLO".getBytes());
}
}
use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class RoutingFunctionTests method testRoutingViaExplicitEnablingAndRoutingExpressionHeader.
@Test
public void testRoutingViaExplicitEnablingAndRoutingExpressionHeader() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(RoutingFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.routing.enabled=true")) {
InputDestination inputDestination = context.getBean(InputDestination.class);
OutputDestination outputDestination = context.getBean(OutputDestination.class);
Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).setHeader("spring.cloud.function.routing-expression", "'echo'").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN).build();
inputDestination.send(inputMessage);
Message<byte[]> outputMessage = outputDestination.receive();
assertThat(outputMessage.getPayload()).isEqualTo("Hello".getBytes());
}
}
use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class RoutingFunctionTests method testExplicitRoutingFunctionBindingWithCompositionAndRoutingEnabledExplicitly.
@Test
public void testExplicitRoutingFunctionBindingWithCompositionAndRoutingEnabledExplicitly() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(RoutingFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.definition=enrich|" + RoutingFunction.FUNCTION_NAME, "--spring.cloud.stream.function.routing.enabled=true")) {
InputDestination inputDestination = context.getBean(InputDestination.class);
OutputDestination outputDestination = context.getBean(OutputDestination.class);
Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build();
inputDestination.send(inputMessage);
Message<byte[]> outputMessage = outputDestination.receive();
assertThat(outputMessage.getPayload()).isEqualTo("HELLO".getBytes());
}
}
use of org.springframework.boot.builder.SpringApplicationBuilder 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