Search in sources :

Example 6 with AggregateApplicationBuilder

use of org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder 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)

Example 7 with AggregateApplicationBuilder

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

the class AggregationTest method aggregation.

@Test
public void aggregation() {
    aggregatedApplicationContext = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class, "--server.port=0", "--debug=true").web(false).from(TestSource.class).to(TestProcessor.class).run();
    SharedBindingTargetRegistry sharedBindingTargetRegistry = aggregatedApplicationContext.getBean(SharedBindingTargetRegistry.class);
    BindingTargetFactory channelFactory = aggregatedApplicationContext.getBean(SubscribableChannelBindingTargetFactory.class);
    assertThat(channelFactory).isNotNull();
    assertThat(sharedBindingTargetRegistry.getAll().keySet()).hasSize(2);
    aggregatedApplicationContext.close();
}
Also used : AggregateApplicationBuilder(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder) MockBinderRegistryConfiguration(org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration) SharedBindingTargetRegistry(org.springframework.cloud.stream.aggregate.SharedBindingTargetRegistry) BindingTargetFactory(org.springframework.cloud.stream.binding.BindingTargetFactory) SubscribableChannelBindingTargetFactory(org.springframework.cloud.stream.binding.SubscribableChannelBindingTargetFactory) Test(org.junit.Test)

Example 8 with AggregateApplicationBuilder

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

the class AggregationTest method testNamespaces.

@Test
public void testNamespaces() {
    aggregatedApplicationContext = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class, "--server.port=0").web(false).from(TestSource.class).namespace("foo").to(TestProcessor.class).namespace("bar").run();
    SharedBindingTargetRegistry sharedChannelRegistry = aggregatedApplicationContext.getBean(SharedBindingTargetRegistry.class);
    BindingTargetFactory channelFactory = aggregatedApplicationContext.getBean(SubscribableChannelBindingTargetFactory.class);
    MessageChannel fooOutput = sharedChannelRegistry.get("foo.output", MessageChannel.class);
    assertThat(fooOutput).isNotNull();
    Object barInput = sharedChannelRegistry.get("bar.input", MessageChannel.class);
    assertThat(barInput).isNotNull();
    assertThat(channelFactory).isNotNull();
    assertThat(sharedChannelRegistry.getAll().keySet()).hasSize(2);
    aggregatedApplicationContext.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) AggregateApplicationBuilder(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder) MockBinderRegistryConfiguration(org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration) SharedBindingTargetRegistry(org.springframework.cloud.stream.aggregate.SharedBindingTargetRegistry) BindingTargetFactory(org.springframework.cloud.stream.binding.BindingTargetFactory) SubscribableChannelBindingTargetFactory(org.springframework.cloud.stream.binding.SubscribableChannelBindingTargetFactory) Test(org.junit.Test)

Example 9 with AggregateApplicationBuilder

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

the class AggregationTest method testNamespacePrefixesWithoutCmdLinePropertySource.

@Test
@SuppressWarnings("unchecked")
public void testNamespacePrefixesWithoutCmdLinePropertySource() {
    AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class);
    System.setProperty("a.foo-value", "sysbara");
    System.setProperty("c.fooValue", "sysbarc");
    System.setProperty("server.port", "0");
    aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class).namespace("a").args("--foo-value=bar").via(TestProcessor.class).namespace("b").args("--fooValue=argbarb").via(TestProcessor.class).namespace("c").args("--foo-value=argbarc").run();
    DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder);
    assertTrue(Arrays.equals(((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--foo-value=sysbara" }));
    for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : ((List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor.getPropertyValue("processorConfigurers"))) {
        if (processorConfigurer.getNamespace().equals("b")) {
            assertTrue(Arrays.equals(processorConfigurer.getArgs(), new String[] { "--fooValue=argbarb" }));
        }
        if (processorConfigurer.getNamespace().equals("c")) {
            assertTrue(Arrays.equals(processorConfigurer.getArgs(), new String[] { "--fooValue=sysbarc" }));
        }
    }
    aggregatedApplicationContext.close();
}
Also used : SourceConfigurer(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder.SourceConfigurer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AggregateApplicationBuilder(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder) Test(org.junit.Test)

Example 10 with AggregateApplicationBuilder

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

the class AggregationTest method testNamespacePrefixesFromCmdLineVsArgs.

@Test
@SuppressWarnings("unchecked")
public void testNamespacePrefixesFromCmdLineVsArgs() {
    AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class);
    aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class).namespace("a").args("--fooValue=bar").via(TestProcessor.class).namespace("b").args("--foo1=argbarb").via(TestProcessor.class).namespace("c").run("--a.fooValue=bara", "--c.foo1=barc");
    DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder);
    assertTrue(Arrays.equals(((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--fooValue=bara" }));
    final List<AggregateApplicationBuilder.ProcessorConfigurer> processorConfigurers = (List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor.getPropertyValue("processorConfigurers");
    for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) {
        if (processorConfigurer.getNamespace().equals("b")) {
            assertTrue(Arrays.equals(processorConfigurer.getArgs(), new String[] { "--foo1=argbarb" }));
        }
        if (processorConfigurer.getNamespace().equals("c")) {
            assertTrue(Arrays.equals(processorConfigurer.getArgs(), new String[] { "--foo1=barc" }));
        }
    }
    aggregatedApplicationContext.close();
}
Also used : SourceConfigurer(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder.SourceConfigurer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AggregateApplicationBuilder(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 AggregateApplicationBuilder (org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder)13 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 SourceConfigurer (org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder.SourceConfigurer)6 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 SharedBindingTargetRegistry (org.springframework.cloud.stream.aggregate.SharedBindingTargetRegistry)3 BindingTargetFactory (org.springframework.cloud.stream.binding.BindingTargetFactory)3 SubscribableChannelBindingTargetFactory (org.springframework.cloud.stream.binding.SubscribableChannelBindingTargetFactory)3 MockBinderRegistryConfiguration (org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration)3 Message (org.springframework.messaging.Message)2 MessageChannel (org.springframework.messaging.MessageChannel)2 AggregateApplication (org.springframework.cloud.stream.aggregate.AggregateApplication)1 TestProcessor (org.springframework.cloud.stream.config.aggregate.processor.TestProcessor)1 Processor (org.springframework.cloud.stream.messaging.Processor)1 MessageCollector (org.springframework.cloud.stream.test.binder.MessageCollector)1 TestSupportBinder (org.springframework.cloud.stream.test.binder.TestSupportBinder)1