Search in sources :

Example 36 with MessageCollector

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

the class ContentTypeTests method testSendJsonString.

@Test
public void testSendJsonString() 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);
        source.output().send(MessageBuilder.withPayload("foo").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.APPLICATION_JSON));
        assertThat("foo").isEqualTo(message.getPayload());
    }
}
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 37 with MessageCollector

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

the class ContentTypeTests method testSendJavaSerializable.

@Test
public void testSendJavaSerializable() throws Exception {
    try (ConfigurableApplicationContext context = SpringApplication.run(SourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.output.contentType=application/x-java-serialized-object")) {
        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<User> message = (Message<User>) collector.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
        assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class).includes(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT));
        User received = message.getPayload();
        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)

Example 38 with MessageCollector

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

the class ContentTypeTests method testSendKryoSerialized.

@Test
public void testSendKryoSerialized() throws Exception {
    try (ConfigurableApplicationContext context = SpringApplication.run(SourceApplication.class, "--server.port=0", "--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.output.contentType=application/x-java-object")) {
        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<User> message = (Message<User>) collector.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
        User received = message.getPayload();
        assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class).includes(MimeType.valueOf(KryoMessageConverter.KRYO_MIME_TYPE)));
        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