Search in sources :

Example 6 with OutputDestination

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

the class ContentTypeTckTests method byteArrayMessageToStringMessageStreamListener.

@Test
public void byteArrayMessageToStringMessageStreamListener() {
    ApplicationContext context = new SpringApplicationBuilder(StringMessageToStringMessageStreamListener.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false");
    InputDestination source = context.getBean(InputDestination.class);
    OutputDestination target = context.getBean(OutputDestination.class);
    String jsonPayload = "{\"name\":\"oleg\"}";
    source.send(new GenericMessage<>(jsonPayload.getBytes()));
    Message<byte[]> outputMessage = target.receive();
    assertEquals(MimeTypeUtils.TEXT_PLAIN, outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    assertEquals("oleg", new String(outputMessage.getPayload(), StandardCharsets.UTF_8));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Example 7 with OutputDestination

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

the class ContentTypeTckTests method pojoMessageToStringMessageServiceActivator.

@Test
public void pojoMessageToStringMessageServiceActivator() {
    ApplicationContext context = new SpringApplicationBuilder(PojoMessageToStringMessageServiceActivator.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false");
    InputDestination source = context.getBean(InputDestination.class);
    OutputDestination target = context.getBean(OutputDestination.class);
    String jsonPayload = "{\"name\":\"oleg\"}";
    source.send(new GenericMessage<>(jsonPayload.getBytes()));
    Message<byte[]> outputMessage = target.receive();
    assertEquals(MimeTypeUtils.TEXT_PLAIN, outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    assertEquals("oleg", new String(outputMessage.getPayload(), StandardCharsets.UTF_8));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Example 8 with OutputDestination

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

the class ContentTypeTckTests method withInternalPipeline.

@Test
public void withInternalPipeline() {
    ApplicationContext context = new SpringApplicationBuilder(InternalPipeLine.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false");
    InputDestination source = context.getBean(InputDestination.class);
    OutputDestination target = context.getBean(OutputDestination.class);
    String jsonPayload = "{\"name\":\"oleg\"}";
    source.send(new GenericMessage<>(jsonPayload.getBytes()));
    Message<byte[]> outputMessage = target.receive();
    assertEquals("OLEG", new String(outputMessage.getPayload()));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Example 9 with OutputDestination

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

the class ContentTypeTckTests method stringToMapMessageStreamListener.

@Test
public void stringToMapMessageStreamListener() {
    ApplicationContext context = new SpringApplicationBuilder(StringToMapMessageStreamListener.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false");
    InputDestination source = context.getBean(InputDestination.class);
    OutputDestination target = context.getBean(OutputDestination.class);
    String jsonPayload = "{\"name\":\"oleg\"}";
    source.send(new GenericMessage<>(jsonPayload.getBytes()));
    Message<byte[]> outputMessage = target.receive();
    assertEquals("oleg", new String(outputMessage.getPayload()));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Example 10 with OutputDestination

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

the class ContentTypeTckTests method byteArrayToByteArrayInboundOutboundContentTypeBinding.

@Test
public void byteArrayToByteArrayInboundOutboundContentTypeBinding() {
    ApplicationContext context = new SpringApplicationBuilder(ByteArrayToByteArrayStreamListener.class).web(WebApplicationType.NONE).run("--spring.cloud.stream.bindings.input.contentType=text/plain", "--spring.cloud.stream.bindings.output.contentType=text/plain", "--spring.jmx.enabled=false");
    InputDestination source = context.getBean(InputDestination.class);
    OutputDestination target = context.getBean(OutputDestination.class);
    String jsonPayload = "{\"name\":\"oleg\"}";
    source.send(new GenericMessage<>(jsonPayload.getBytes()));
    Message<byte[]> outputMessage = target.receive();
    assertEquals(MimeTypeUtils.TEXT_PLAIN, outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    assertEquals(jsonPayload, new String(outputMessage.getPayload(), StandardCharsets.UTF_8));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) OutputDestination(org.springframework.cloud.stream.binder.test.OutputDestination) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) InputDestination(org.springframework.cloud.stream.binder.test.InputDestination) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)24 InputDestination (org.springframework.cloud.stream.binder.test.InputDestination)24 OutputDestination (org.springframework.cloud.stream.binder.test.OutputDestination)24 ApplicationContext (org.springframework.context.ApplicationContext)24 MessageHeaders (org.springframework.messaging.MessageHeaders)4 KryoMessageConverter (org.springframework.cloud.stream.converter.KryoMessageConverter)2 Message (org.springframework.messaging.Message)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 MimeType (org.springframework.util.MimeType)2