use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class MultipleInputOutputFunctionTests method testMultiInputMessageSingleOutput.
@Test
public void testMultiInputMessageSingleOutput() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ReactiveFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=multiInputSingleOutputMessage")) {
context.getBean(InputDestination.class);
InputDestination inputDestination = context.getBean(InputDestination.class);
OutputDestination outputDestination = context.getBean(OutputDestination.class);
Message<byte[]> stringInputMessage = MessageBuilder.withPayload("one".getBytes()).build();
Message<byte[]> integerInputMessage = MessageBuilder.withPayload("1".getBytes()).build();
inputDestination.send(stringInputMessage, "multiInputSingleOutputMessage-in-0");
inputDestination.send(integerInputMessage, "multiInputSingleOutputMessage-in-1");
Message<byte[]> outputMessage = outputDestination.receive();
assertThat(outputMessage.getPayload()).isEqualTo("one".getBytes());
outputMessage = outputDestination.receive(0, "multiInputSingleOutputMessage-out-0");
assertThat(outputMessage.getPayload()).isEqualTo("1".getBytes());
}
}
use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class MultipleInputOutputFunctionTests method testMultipleFunctions.
@Test
public void testMultipleFunctions() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ReactiveFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=uppercase;reverse")) {
context.getBean(InputDestination.class);
InputDestination inputDestination = context.getBean(InputDestination.class);
OutputDestination outputDestination = context.getBean(OutputDestination.class);
Message<byte[]> inputMessage = MessageBuilder.withPayload("Hello".getBytes()).build();
inputDestination.send(inputMessage, "uppercase-in-0");
inputDestination.send(inputMessage, "reverse-in-0");
Message<byte[]> outputMessage = outputDestination.receive(0, "uppercase-out-0");
assertThat(outputMessage.getPayload()).isEqualTo("HELLO".getBytes());
outputMessage = outputDestination.receive(0, "reverse-out-0");
assertThat(outputMessage.getPayload()).isEqualTo("olleH".getBytes());
}
}
use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class FluxMessageChannelBindingTests method testFluxMessageChannelBindingWhenReactiveOptIn.
@Test
public void testFluxMessageChannelBindingWhenReactiveOptIn() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ReactiveFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.reactive.uppercase=true")) {
assertThat(context.getBean("uppercase-in-0", MessageChannel.class)).isInstanceOf(FluxMessageChannel.class);
assertThat(context.getBean("uppercase-out-0", MessageChannel.class)).isInstanceOf(FluxMessageChannel.class);
}
}
use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method testWithMapInputParameter.
// ======
@Test
public void testWithMapInputParameter() {
ApplicationContext context = new SpringApplicationBuilder(MapInputConfiguration.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false");
InputDestination source = context.getBean(InputDestination.class);
OutputDestination target = context.getBean(OutputDestination.class);
String jsonPayload = "{\"name\":\"oleg\"}";
source.send(new GenericMessage<>(jsonPayload.getBytes()));
Message<byte[]> outputMessage = target.receive();
assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8)).isEqualTo(jsonPayload);
}
use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.
the class BindingServiceTests method testBindingAutostartup.
@SuppressWarnings("unchecked")
@Test
public void testBindingAutostartup() throws Exception {
ApplicationContext context = new SpringApplicationBuilder(FooConfiguration.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.input-in-0.consumer.auto-startup=false");
BindingService bindingService = context.getBean(BindingService.class);
Field cbField = ReflectionUtils.findField(BindingService.class, "consumerBindings");
cbField.setAccessible(true);
Map<String, Object> cbMap = (Map<String, Object>) cbField.get(bindingService);
Binding<?> inputBinding = ((List<Binding<?>>) cbMap.get("input-in-0")).get(0);
assertThat(inputBinding.isRunning()).isFalse();
}
Aggregations