Search in sources :

Example 26 with MessageCollector

use of org.springframework.cloud.stream.test.binder.MessageCollector in project spring-cloud-stream by spring-cloud.

the class AvroStubSchemaRegistryClientMessageConverterTests method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    ConfigurableApplicationContext sourceContext = SpringApplication.run(AvroSourceApplication.class, "--server.port=0", "--debug", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.output.contentType=application/*+avro", "--spring.cloud.stream.schema.avro.dynamicSchemaGenerationEnabled=true");
    Source source = sourceContext.getBean(Source.class);
    User1 firstOutboundFoo = new User1();
    firstOutboundFoo.setFavoriteColor("foo" + UUID.randomUUID().toString());
    firstOutboundFoo.setName("foo" + UUID.randomUUID().toString());
    source.output().send(MessageBuilder.withPayload(firstOutboundFoo).build());
    MessageCollector sourceMessageCollector = sourceContext.getBean(MessageCollector.class);
    Message<?> outboundMessage = sourceMessageCollector.forChannel(source.output()).poll(1000, TimeUnit.MILLISECONDS);
    ConfigurableApplicationContext barSourceContext = SpringApplication.run(AvroSourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.output.contentType=application/vnd.user1.v1+avro", "--spring.cloud.stream.schema.avro.dynamicSchemaGenerationEnabled=true");
    Source barSource = barSourceContext.getBean(Source.class);
    User2 firstOutboundUser2 = new User2();
    firstOutboundUser2.setFavoriteColor("foo" + UUID.randomUUID().toString());
    firstOutboundUser2.setName("foo" + UUID.randomUUID().toString());
    barSource.output().send(MessageBuilder.withPayload(firstOutboundUser2).build());
    MessageCollector barSourceMessageCollector = barSourceContext.getBean(MessageCollector.class);
    Message<?> barOutboundMessage = barSourceMessageCollector.forChannel(barSource.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(barOutboundMessage).isNotNull();
    User2 secondBarOutboundPojo = new User2();
    secondBarOutboundPojo.setFavoriteColor("foo" + UUID.randomUUID().toString());
    secondBarOutboundPojo.setName("foo" + UUID.randomUUID().toString());
    source.output().send(MessageBuilder.withPayload(secondBarOutboundPojo).build());
    Message<?> secondBarOutboundMessage = sourceMessageCollector.forChannel(source.output()).poll(1000, TimeUnit.MILLISECONDS);
    ConfigurableApplicationContext sinkContext = SpringApplication.run(AvroSinkApplication.class, "--server.port=0", "--spring.jmx.enabled=false");
    Sink sink = sinkContext.getBean(Sink.class);
    sink.input().send(outboundMessage);
    sink.input().send(barOutboundMessage);
    sink.input().send(secondBarOutboundMessage);
    List<User2> receivedPojos = sinkContext.getBean(AvroSinkApplication.class).receivedPojos;
    assertThat(receivedPojos).hasSize(3);
    assertThat(receivedPojos.get(0)).isNotSameAs(firstOutboundFoo);
    assertThat(receivedPojos.get(0).getFavoriteColor()).isEqualTo(firstOutboundFoo.getFavoriteColor());
    assertThat(receivedPojos.get(0).getName()).isEqualTo(firstOutboundFoo.getName());
    assertThat(receivedPojos.get(0).getFavoritePlace()).isEqualTo("NYC");
    assertThat(receivedPojos.get(1)).isNotSameAs(firstOutboundUser2);
    assertThat(receivedPojos.get(1).getFavoriteColor()).isEqualTo(firstOutboundUser2.getFavoriteColor());
    assertThat(receivedPojos.get(1).getName()).isEqualTo(firstOutboundUser2.getName());
    assertThat(receivedPojos.get(1).getFavoritePlace()).isEqualTo("Boston");
    assertThat(receivedPojos.get(2)).isNotSameAs(secondBarOutboundPojo);
    assertThat(receivedPojos.get(2).getFavoriteColor()).isEqualTo(secondBarOutboundPojo.getFavoriteColor());
    assertThat(receivedPojos.get(2).getName()).isEqualTo(secondBarOutboundPojo.getName());
    assertThat(receivedPojos.get(2).getFavoritePlace()).isEqualTo(secondBarOutboundPojo.getFavoritePlace());
    sourceContext.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Sink(org.springframework.cloud.stream.messaging.Sink) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector) Source(org.springframework.cloud.stream.messaging.Source) Test(org.junit.Test)

Example 27 with MessageCollector

use of org.springframework.cloud.stream.test.binder.MessageCollector in project spring-cloud-stream by spring-cloud.

the class SubjectNamingStrategyTest method testCustomNamingStrategy.

@Test
public void testCustomNamingStrategy() throws Exception {
    ConfigurableApplicationContext sourceContext = SpringApplication.run(AvroSourceApplication.class, "--server.port=0", "--debug", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.output.contentType=application/*+avro", "--spring.cloud.stream.schema.avro.subjectNamingStrategy=org.springframework.cloud.schema.avro.CustomSubjectNamingStrategy", "--spring.cloud.stream.schema.avro.dynamicSchemaGenerationEnabled=true");
    Source source = sourceContext.getBean(Source.class);
    User1 user1 = new User1();
    user1.setFavoriteColor("foo" + UUID.randomUUID().toString());
    user1.setName("foo" + UUID.randomUUID().toString());
    source.output().send(MessageBuilder.withPayload(user1).build());
    MessageCollector barSourceMessageCollector = sourceContext.getBean(MessageCollector.class);
    Message<?> message = barSourceMessageCollector.forChannel(source.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(message.getHeaders().get("contentType")).isEqualTo(MimeType.valueOf("application/vnd.org.springframework.cloud.schema.avro.User1.v1+avro"));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector) Source(org.springframework.cloud.stream.messaging.Source) Test(org.junit.Test)

Example 28 with MessageCollector

use of org.springframework.cloud.stream.test.binder.MessageCollector in project spring-cloud-stream by spring-cloud.

the class StreamListenerReactiveInputOutputArgsWithSenderAndFailureTests method sendMessageAndValidate.

@SuppressWarnings("unchecked")
private static void sendMessageAndValidate(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    String sentPayload = "hello " + UUID.randomUUID().toString();
    processor.input().send(MessageBuilder.withPayload(sentPayload).setHeader("contentType", "text/plain").build());
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(result).isNotNull();
    assertThat(result.getPayload()).isEqualTo(sentPayload.toUpperCase());
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector)

Example 29 with MessageCollector

use of org.springframework.cloud.stream.test.binder.MessageCollector in project spring-cloud-stream by spring-cloud.

the class StreamListenerReactiveInputOutputArgsWithSenderTests method sendMessageAndValidate.

@SuppressWarnings("unchecked")
private static void sendMessageAndValidate(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    String sentPayload = "hello " + UUID.randomUUID().toString();
    processor.input().send(MessageBuilder.withPayload(sentPayload).setHeader("contentType", "text/plain").build());
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(result).isNotNull();
    assertThat(result.getPayload()).isEqualTo(sentPayload.toUpperCase());
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector)

Example 30 with MessageCollector

use of org.springframework.cloud.stream.test.binder.MessageCollector in project spring-cloud-stream by spring-cloud.

the class StreamListenerReactiveReturnWithFailureTests method sendMessageAndValidate.

@SuppressWarnings("unchecked")
private static void sendMessageAndValidate(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    String sentPayload = "hello " + UUID.randomUUID().toString();
    processor.input().send(MessageBuilder.withPayload(sentPayload).setHeader("contentType", "text/plain").build());
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(result).isNotNull();
    assertThat(result.getPayload()).isEqualTo(sentPayload.toUpperCase());
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector)

Aggregations

MessageCollector (org.springframework.cloud.stream.test.binder.MessageCollector)38 Message (org.springframework.messaging.Message)30 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)25 Test (org.junit.Test)24 Processor (org.springframework.cloud.stream.messaging.Processor)19 Source (org.springframework.cloud.stream.messaging.Source)16 Sink (org.springframework.cloud.stream.messaging.Sink)5 ArrayList (java.util.ArrayList)3 AggregateApplication (org.springframework.cloud.stream.aggregate.AggregateApplication)1 AggregateApplicationBuilder (org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 MessageChannel (org.springframework.messaging.MessageChannel)1 Tuple (org.springframework.tuple.Tuple)1