Search in sources :

Example 21 with Processor

use of org.springframework.cloud.stream.messaging.Processor 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)

Example 22 with Processor

use of org.springframework.cloud.stream.messaging.Processor 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 23 with Processor

use of org.springframework.cloud.stream.messaging.Processor 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 24 with Processor

use of org.springframework.cloud.stream.messaging.Processor 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 25 with Processor

use of org.springframework.cloud.stream.messaging.Processor in project spring-cloud-stream by spring-cloud.

the class AggregateWithBeanTest method testAggregateApplication.

@Test
@SuppressWarnings("unchecked")
public void testAggregateApplication() throws InterruptedException {
    Processor uppercaseProcessor = aggregateApplication.getBinding(Processor.class, "upper");
    Processor suffixProcessor = aggregateApplication.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!");
}
Also used : Processor(org.springframework.cloud.stream.messaging.Processor) Message(org.springframework.messaging.Message) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Processor (org.springframework.cloud.stream.messaging.Processor)26 Message (org.springframework.messaging.Message)20 MessageCollector (org.springframework.cloud.stream.test.binder.MessageCollector)19 Test (org.junit.Test)14 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)12 CountDownLatch (java.util.concurrent.CountDownLatch)2 MessageHandler (org.springframework.messaging.MessageHandler)2 MessagingException (org.springframework.messaging.MessagingException)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 AggregateApplication (org.springframework.cloud.stream.aggregate.AggregateApplication)1 AggregateApplicationBuilder (org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder)1 BindableProxyFactory (org.springframework.cloud.stream.binding.BindableProxyFactory)1 Source (org.springframework.cloud.stream.messaging.Source)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1