Search in sources :

Example 1 with AggregateApplication

use of org.springframework.cloud.stream.aggregate.AggregateApplication in project spring-cloud-stream by spring-cloud.

the class AggregateWithMainTest method testAggregateApplication.

@SuppressWarnings("unchecked")
@Test
public void testAggregateApplication() throws InterruptedException {
    // emulate a main method
    ConfigurableApplicationContext context = new AggregateApplicationBuilder(MainConfiguration.class).web(false).from(UppercaseProcessor.class).namespace("upper").to(SuffixProcessor.class).namespace("suffix").run("--spring.cloud.stream.bindings.input.contentType=text/plain", "--spring.cloud.stream.bindings.output.contentType=text/plain");
    AggregateApplication aggregateAccessor = context.getBean(AggregateApplication.class);
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Processor uppercaseProcessor = aggregateAccessor.getBinding(Processor.class, "upper");
    Processor suffixProcessor = aggregateAccessor.getBinding(Processor.class, "suffix");
    uppercaseProcessor.input().send(MessageBuilder.withPayload("Hello").build());
    Message<String> receivedMessage = (Message<String>) messageCollector.forChannel(suffixProcessor.output()).poll(1, TimeUnit.SECONDS);
    assertThat(receivedMessage).isNotNull();
    assertThat(receivedMessage.getPayload()).isEqualTo("HELLO WORLD!");
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector) AggregateApplicationBuilder(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder) AggregateApplication(org.springframework.cloud.stream.aggregate.AggregateApplication) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 AggregateApplication (org.springframework.cloud.stream.aggregate.AggregateApplication)1 AggregateApplicationBuilder (org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder)1 Processor (org.springframework.cloud.stream.messaging.Processor)1 MessageCollector (org.springframework.cloud.stream.test.binder.MessageCollector)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Message (org.springframework.messaging.Message)1