Search in sources :

Example 96 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.

the class RoutingFunctionTests method testPojoFunction.

@Test
public void testPojoFunction() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(RoutingFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.definition=" + RoutingFunction.FUNCTION_NAME)) {
        InputDestination inputDestination = context.getBean(InputDestination.class);
        OutputDestination outputDestination = context.getBean(OutputDestination.class);
        Message<byte[]> inputMessage = MessageBuilder.withPayload("{\"name\":\"bob\"}".getBytes()).setHeader("spring.cloud.function.definition", "pojoecho").build();
        inputDestination.send(inputMessage);
        Message<byte[]> outputMessage = outputDestination.receive();
        assertThat(outputMessage.getPayload()).isEqualTo("{\"name\":\"bob\"}".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 97 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.

the class StreamBridgeTests method testBridgeActivationWhenFunctionDefinitionIsPresent.

// see https://github.com/spring-cloud/spring-cloud-function/issues/573 for more details
@Test
public void testBridgeActivationWhenFunctionDefinitionIsPresent() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(SimpleConfiguration.class)).web(WebApplicationType.NONE).run("--spring.cloud.function.definition=echo;uppercase", "--spring.jmx.enabled=false")) {
        StreamBridge bridge = context.getBean(StreamBridge.class);
        bridge.send("echo-in-0", "hello foo");
        OutputDestination outputDestination = context.getBean(OutputDestination.class);
        assertThat(new String(outputDestination.receive(100, "echo-out-0").getPayload())).isEqualTo("hello foo");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test)

Example 98 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.

the class StreamBridgeTests method testBindingPropertiesAreHonored.

@Test
public void testBindingPropertiesAreHonored() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ConsumerConfiguration.class)).web(WebApplicationType.NONE).run("--spring.cloud.function.definition=consumer;function", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.foo.destination=function-in-0", "--spring.cloud.stream.bindings.foo.producer.partitionCount=5", "--spring.cloud.stream.bindings.foo.consumer.concurrency=2")) {
        BindingServiceProperties bsProperties = context.getBean(BindingServiceProperties.class);
        assertThat(bsProperties.getConsumerProperties("foo").getConcurrency()).isEqualTo(2);
        assertThat(bsProperties.getProducerProperties("foo").getPartitionCount()).isEqualTo(5);
        StreamBridge bridge = context.getBean(StreamBridge.class);
        bridge.send("consumer-in-0", "hello foo");
        OutputDestination outputDestination = context.getBean(OutputDestination.class);
        Message<byte[]> message = outputDestination.receive(100, "function-out-0");
        assertThat(new String(message.getPayload())).isEqualTo("hello foo");
        assertThat(message.getHeaders().get("concurrency")).isEqualTo(2);
        assertThat(message.getHeaders().get("partitionCount")).isEqualTo(5);
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) Test(org.junit.Test)

Example 99 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.

the class StreamBridgeTests method testWithIntegrationFlowBecauseMarcinSaidSo.

@Test
public void testWithIntegrationFlowBecauseMarcinSaidSo() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(IntegrationFlowConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
        StreamBridge bridge = context.getBean(StreamBridge.class);
        bridge.send("foo", "blah");
        OutputDestination outputDestination = context.getBean(OutputDestination.class);
        Message<byte[]> message = outputDestination.receive(100, "output");
        assertThat(new String(message.getPayload())).isEqualTo("BLAH");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test)

Example 100 with SpringApplicationBuilder

use of org.springframework.boot.builder.SpringApplicationBuilder in project spring-cloud-stream by spring-cloud.

the class StreamBridgeTests method testNoBridgeIfNoSourcePropertyDefined.

@Test(expected = NoSuchBeanDefinitionException.class)
public void testNoBridgeIfNoSourcePropertyDefined() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration()).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
        context.getBean(StreamBridge.class);
        fail();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) 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