Search in sources :

Example 86 with SpringApplicationBuilder

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());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Example 87 with SpringApplicationBuilder

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());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Example 88 with SpringApplicationBuilder

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);
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.jupiter.api.Test)

Example 89 with SpringApplicationBuilder

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);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Example 90 with SpringApplicationBuilder

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();
}
Also used : Field(java.lang.reflect.Field) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)319 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)170 Test (org.junit.Test)156 OutputDestination (org.springframework.cloud.stream.binder.test.OutputDestination)105 InputDestination (org.springframework.cloud.stream.binder.test.InputDestination)100 Test (org.junit.jupiter.api.Test)82 ApplicationContext (org.springframework.context.ApplicationContext)55 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)26 Environment (org.springframework.cloud.config.environment.Environment)19 Before (org.junit.Before)8 SpringApplication (org.springframework.boot.SpringApplication)8 Map (java.util.Map)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 ConsulClient (com.ecwid.consul.v1.ConsulClient)6 Message (org.springframework.messaging.Message)6 MessageHeaders (org.springframework.messaging.MessageHeaders)6 GenericMessage (org.springframework.messaging.support.GenericMessage)6 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 CountDownLatch (java.util.concurrent.CountDownLatch)5