Search in sources :

Example 11 with AggregateApplicationBuilder

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

the class AggregationTest method testNamespacePrefixesFromCmdLineWithRelaxedNamesAndMorePropertySources.

@Test
@SuppressWarnings("unchecked")
public void testNamespacePrefixesFromCmdLineWithRelaxedNamesAndMorePropertySources() {
    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("--a.fooValue=bara");
    DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder);
    assertTrue(Arrays.equals(((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--fooValue=bara", "--foo-value=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[] { "--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 12 with AggregateApplicationBuilder

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

the class AggregationTest method testParentArgsAndSourcesWithWebDisabled.

@Test
@SuppressWarnings("unchecked")
public void testParentArgsAndSourcesWithWebDisabled() {
    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("--server.port=0");
    DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder);
    List<Object> sources = (List<Object>) aggregateApplicationBuilderAccessor.getPropertyValue("parentSources");
    assertThat(sources).containsExactlyInAnyOrder(AggregateApplicationBuilder.ParentConfiguration.class, AggregateApplicationBuilder.ParentActuatorConfiguration.class, MockBinderRegistryConfiguration.class, DummyConfig.class);
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) 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 13 with AggregateApplicationBuilder

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

the class AggregationTest method testNamespacePrefixesFromCmdLine.

@Test
@SuppressWarnings("unchecked")
public void testNamespacePrefixesFromCmdLine() {
    AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(MockBinderRegistryConfiguration.class);
    aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class).namespace("a").via(TestProcessor.class).namespace("b").via(TestProcessor.class).namespace("c").run("--a.foo1=bar1", "--b.foo1=bar2", "--c.foo1=bar3");
    DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(aggregateApplicationBuilder);
    assertTrue(Arrays.equals(((SourceConfigurer) aggregateApplicationBuilderAccessor.getPropertyValue("sourceConfigurer")).getArgs(), new String[] { "--foo1=bar1" }));
    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=bar2" }));
        }
        if (processorConfigurer.getNamespace().equals("c")) {
            assertTrue(Arrays.equals(processorConfigurer.getArgs(), new String[] { "--foo1=bar3" }));
        }
    }
    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