Search in sources :

Example 81 with SpringApplicationBuilder

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

the class ValidatedProps method testValidatedValueValue.

@Test
public void testValidatedValueValue() {
    ValidatedProps validatedProps = new SpringApplicationBuilder(SampleConfiguration.class).web(WebApplicationType.NONE).run("--props.value=2", "--spring.jmx.enabled=false").getBean(ValidatedProps.class);
    assertThat(validatedProps.getValue()).isEqualTo(2);
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.Test)

Example 82 with SpringApplicationBuilder

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

the class RetryTemplateTests method testSpecificCustomRetryTemplate.

@SuppressWarnings("rawtypes")
@Test
public void testSpecificCustomRetryTemplate() throws Exception {
    ApplicationContext context = new SpringApplicationBuilder(SpecificCustomRetryTemplateConfiguration.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.processor-in-0.consumer.retry-template-name=retryTemplateTwo");
    RetryTemplate retryTemplateTwo = context.getBean("retryTemplateTwo", RetryTemplate.class);
    BindingServiceProperties bindingServiceProperties = context.getBean(BindingServiceProperties.class);
    ConsumerProperties consumerProperties = bindingServiceProperties.getConsumerProperties("processor-in-0");
    AbstractBinder binder = context.getBean(AbstractBinder.class);
    Method m = AbstractBinder.class.getDeclaredMethod("buildRetryTemplate", ConsumerProperties.class);
    m.setAccessible(true);
    RetryTemplate retryTemplate = (RetryTemplate) m.invoke(binder, consumerProperties);
    assertThat(retryTemplate).isEqualTo(retryTemplateTwo);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) StreamRetryTemplate(org.springframework.cloud.stream.annotation.StreamRetryTemplate) RetryTemplate(org.springframework.retry.support.RetryTemplate) AbstractBinder(org.springframework.cloud.stream.binder.AbstractBinder) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Method(java.lang.reflect.Method) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) Test(org.junit.Test)

Example 83 with SpringApplicationBuilder

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

the class MultipleInputOutputFunctionTests method testMultipleFunctionsWithComposition.

@Test
public void testMultipleFunctionsWithComposition() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ReactiveFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=uppercase|reverse;reverse|uppercase")) {
        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, "uppercasereverse-in-0");
        inputDestination.send(inputMessage, "reverseuppercase-in-0");
        Message<byte[]> outputMessage = outputDestination.receive(0, "uppercasereverse-out-0");
        System.out.println(new String(outputMessage.getPayload()));
        assertThat(outputMessage.getPayload()).isEqualTo("OLLEH".getBytes());
        outputMessage = outputDestination.receive(0, "reverseuppercase-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 84 with SpringApplicationBuilder

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

the class MultipleInputOutputFunctionTests method testMultiInputSingleOutput.

@Test
public void testMultiInputSingleOutput() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ReactiveFunctionConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=multiInputSingleOutput")) {
        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, "multiInputSingleOutput-in-0");
        inputDestination.send(integerInputMessage, "multiInputSingleOutput-in-1");
        Message<byte[]> outputMessage = outputDestination.receive();
        assertThat(outputMessage.getPayload()).isEqualTo("one".getBytes());
        outputMessage = outputDestination.receive(0, "multiInputSingleOutput-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 85 with SpringApplicationBuilder

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

the class MultipleInputOutputFunctionTests method testMultiInputSingleOutputWithCustomContentType2.

@Test
public void testMultiInputSingleOutputWithCustomContentType2() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(ContentTypeConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=multiInputSingleOutput2", "--spring.cloud.stream.bindings.multiInputSingleOutput2-in-0.content-type=string/person", "--spring.cloud.stream.bindings.multiInputSingleOutput2-in-1.content-type=string/employee", "--spring.cloud.stream.bindings.multiInputSingleOutput2-out-0.content-type=string/person")) {
        context.getBean(InputDestination.class);
        InputDestination inputDestination = context.getBean(InputDestination.class);
        OutputDestination outputDestination = context.getBean(OutputDestination.class);
        Message<byte[]> stringInputMessage = MessageBuilder.withPayload("ricky".getBytes()).build();
        Message<byte[]> integerInputMessage = MessageBuilder.withPayload("bobby".getBytes()).build();
        inputDestination.send(stringInputMessage, "multiInputSingleOutput2-in-0");
        inputDestination.send(integerInputMessage, "multiInputSingleOutput2-in-1");
        Message<byte[]> outputMessage = outputDestination.receive(1000, "multiInputSingleOutput2-out-0");
        assertThat(outputMessage.getPayload()).isEqualTo("rickybobby".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)

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