Search in sources :

Example 91 with SpringApplicationBuilder

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

Example 92 with SpringApplicationBuilder

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());
    }
}
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 93 with SpringApplicationBuilder

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());
    }
}
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 94 with SpringApplicationBuilder

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());
    }
}
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 95 with SpringApplicationBuilder

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);
    }
}
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

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