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