Search in sources :

Example 31 with MessageCollector

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

the class StreamListenerReactiveReturnWithPojoTests method testReturnWithPojo.

@Test
@SuppressWarnings("unchecked")
public void testReturnWithPojo() throws Exception {
    ConfigurableApplicationContext context = SpringApplication.run(this.configClass, "--server.port=0", "--spring.jmx.enabled=false");
    Processor processor = context.getBean(Processor.class);
    processor.input().send(MessageBuilder.withPayload("{\"message\":\"helloPojo\"}").setHeader("contentType", "application/json").build());
    MessageCollector messageCollector = context.getBean(MessageCollector.class);
    Message<String> result = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
    assertThat(result).isNotNull();
    BarPojo barPojo = mapper.readValue(result.getPayload(), BarPojo.class);
    assertThat(barPojo.getBarMessage()).isEqualTo("helloPojo");
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector) Test(org.junit.Test)

Example 32 with MessageCollector

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

the class StreamListenerWildCardFluxInputOutputArgsWithMessageTests 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 33 with MessageCollector

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

the class StreamListenerWithAnnotatedInputOutputArgsTests method sendMessageAndValidate.

@SuppressWarnings("unchecked")
private void sendMessageAndValidate(ConfigurableApplicationContext context) throws InterruptedException {
    Processor processor = context.getBean(Processor.class);
    processor.input().send(MessageBuilder.withPayload("hello").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("HELLO");
    context.close();
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector)

Example 34 with MessageCollector

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

the class ContentTypeTests method testSendStringType.

@Test
public void testSendStringType() throws Exception {
    try (ConfigurableApplicationContext context = SpringApplication.run(SourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.output.contentType=text/plain")) {
        MessageCollector collector = context.getBean(MessageCollector.class);
        Source source = context.getBean(Source.class);
        User user = new User("Alice");
        source.output().send(MessageBuilder.withPayload(user).build());
        Message<String> message = (Message<String>) collector.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
        assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class).includes(MimeTypeUtils.TEXT_PLAIN));
        assertThat(message.getPayload()).isEqualTo(user.toString());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector) Source(org.springframework.cloud.stream.messaging.Source) Test(org.junit.Test)

Example 35 with MessageCollector

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

the class ContentTypeTests method testSendWithDefaultContentType.

@Test
public void testSendWithDefaultContentType() throws Exception {
    try (ConfigurableApplicationContext context = SpringApplication.run(SourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false")) {
        MessageCollector collector = context.getBean(MessageCollector.class);
        Source source = context.getBean(Source.class);
        User user = new User("Alice");
        source.output().send(MessageBuilder.withPayload(user).build());
        Message<String> message = (Message<String>) collector.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
        User received = mapper.readValue(message.getPayload(), User.class);
        assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class).includes(MimeTypeUtils.APPLICATION_JSON));
        assertThat(user.getName()).isEqualTo(received.getName());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Message(org.springframework.messaging.Message) MessageCollector(org.springframework.cloud.stream.test.binder.MessageCollector) Source(org.springframework.cloud.stream.messaging.Source) Test(org.junit.Test)

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