Search in sources :

Example 1 with AggregateApplicationBuilder

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

the class AggregateApplicationTests method testAggregateApplication.

@Test
@SuppressWarnings("unchecked")
public void testAggregateApplication() throws Exception {
    ConfigurableApplicationContext context = new AggregateApplicationBuilder(TestSupportBinderAutoConfiguration.class).web(false).from(TestSource.class).to(TestProcessor.class).run();
    TestSupportBinder testSupportBinder = (TestSupportBinder) context.getBean(BinderFactory.class).getBinder(null, MessageChannel.class);
    MessageChannel processorOutput = testSupportBinder.getChannelForName("output");
    Message<String> received = (Message<String>) (testSupportBinder.messageCollector().forChannel(processorOutput).poll(5, TimeUnit.SECONDS));
    Assert.assertThat(received, notNullValue());
    Assert.assertTrue(received.getPayload().endsWith("processed"));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) TestSupportBinder(org.springframework.cloud.stream.test.binder.TestSupportBinder) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) AggregateApplicationBuilder(org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder) TestProcessor(org.springframework.cloud.stream.config.aggregate.processor.TestProcessor) Test(org.junit.Test)

Example 2 with AggregateApplicationBuilder

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

the class AggregationTest method testNamespacePrefixesFromCmdLineWithRelaxedNames.

@Test
@SuppressWarnings("unchecked")
public void testNamespacePrefixesFromCmdLineWithRelaxedNames() {
    AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class);
    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").run("--a.fooValue=bara", "--b.foo-value=barb", "--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[] { "--foo-value=barb" }));
        }
        if (processorConfigurer.getNamespace().equals("c")) {
            assertThat(processorConfigurer.getArgs(), is(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)

Example 3 with AggregateApplicationBuilder

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

the class AggregationTest method testNamespacePrefixesWithCAPSProperties.

@Test
@SuppressWarnings("unchecked")
public void testNamespacePrefixesWithCAPSProperties() {
    AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class);
    System.setProperty("a.fooValue", "sysbara");
    System.setProperty("c.fooValue", "sysbarc");
    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("--a.fooValue=highest");
    DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder);
    assertThat(((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")).getArgs()).containsExactly(new String[] { "--fooValue=highest" });
    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[] { "--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) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with AggregateApplicationBuilder

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

the class AggregationTest method testModuleAggregationUsingSharedChannelRegistry.

@Test
public void testModuleAggregationUsingSharedChannelRegistry() {
    // test backward compatibility
    aggregatedApplicationContext = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class, "--server.port=0").web(false).from(TestSource.class).to(TestProcessor.class).run();
    SharedBindingTargetRegistry sharedChannelRegistry = aggregatedApplicationContext.getBean(SharedBindingTargetRegistry.class);
    BindingTargetFactory channelFactory = aggregatedApplicationContext.getBean(SubscribableChannelBindingTargetFactory.class);
    assertThat(channelFactory).isNotNull();
    assertThat(sharedChannelRegistry.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 5 with AggregateApplicationBuilder

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

the class AggregationTest method testParentArgsAndSources.

@Test
@SuppressWarnings("unchecked")
public void testParentArgsAndSources() {
    List<String> argsToVerify = new ArrayList<>();
    argsToVerify.add("--foo1=bar1");
    argsToVerify.add("--foo2=bar2");
    argsToVerify.add("--foo3=bar3");
    argsToVerify.add("--server.port=0");
    AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class, "--foo1=bar1");
    final ConfigurableApplicationContext context = aggregateApplicationBuilder.parent(DummyConfig.class, "--foo2=bar2").web(false).from(TestSource.class).namespace("foo").to(TestProcessor.class).namespace("bar").run("--foo3=bar3", "--server.port=0");
    DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder);
    final List<String> parentArgs = (List<String>) aggregateApplicationBuilderAccessor.getPropertyValue("parentArgs");
    assertThat(parentArgs).containsExactlyInAnyOrder(argsToVerify.toArray(new String[argsToVerify.size()]));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ArrayList(java.util.ArrayList) 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