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"));
}
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();
}
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();
}
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();
}
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();
}
Aggregations