use of org.springframework.cloud.stream.binder.test.OutputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method kryo_pojoToPojoContentTypeHeader.
@Test
@SuppressWarnings("deprecation")
public void kryo_pojoToPojoContentTypeHeader() {
ApplicationContext context = new SpringApplicationBuilder(PojoToPojoStreamListener.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.bindings.output.contentType=application/x-java-object");
InputDestination source = context.getBean(InputDestination.class);
OutputDestination target = context.getBean(OutputDestination.class);
KryoMessageConverter converter = new KryoMessageConverter(null, true);
@SuppressWarnings("unchecked") Message<byte[]> message = (Message<byte[]>) converter.toMessage(new Person("oleg"), new MessageHeaders(Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_OBJECT)));
source.send(message);
Message<byte[]> outputMessage = target.receive();
assertNotNull(outputMessage);
MimeType contentType = (MimeType) outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE);
assertEquals("x-java-object", contentType.getSubtype());
}
use of org.springframework.cloud.stream.binder.test.OutputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method overrideMessageConverter_defaultContentTypeBinding.
/**
* This test simply demonstrates how one can override an existing MessageConverter for a given contentType.
* In this case we are demonstrating how Kryo converter can be overriden ('application/x-java-object' maps to Kryo).
*/
@Test
public void overrideMessageConverter_defaultContentTypeBinding() {
ApplicationContext context = new SpringApplicationBuilder(StringToStringStreamListener.class, CustomConverters.class).web(WebApplicationType.NONE).run("--spring.cloud.stream.default.contentType=application/x-java-object", "--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();
assertNotNull(outputMessage);
System.out.println(new String(outputMessage.getPayload(), StandardCharsets.UTF_8));
assertEquals("AlwaysStringKryoMessageConverter", new String(outputMessage.getPayload(), StandardCharsets.UTF_8));
assertEquals(MimeType.valueOf("application/x-java-object"), outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
use of org.springframework.cloud.stream.binder.test.OutputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method toCollectionWithParameterizedType.
@Test
public void toCollectionWithParameterizedType() {
ApplicationContext context = new SpringApplicationBuilder(CollectionWithParameterizedTypes.class).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false");
InputDestination source = context.getBean(InputDestination.class);
OutputDestination target = context.getBean(OutputDestination.class);
String jsonPayload = "[{\"person\":{\"name\":\"jon\"},\"id\":123},{\"person\":{\"name\":\"jane\"},\"id\":456}]";
source.send(new GenericMessage<>(jsonPayload.getBytes()));
Message<byte[]> outputMessage = target.receive();
assertThat(outputMessage.getPayload()).isEqualTo(jsonPayload.getBytes());
}
use of org.springframework.cloud.stream.binder.test.OutputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method pojoToPojo.
@Test
public void pojoToPojo() {
ApplicationContext context = new SpringApplicationBuilder(PojoToPojoStreamListener.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.APPLICATION_JSON, outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertEquals(jsonPayload, new String(outputMessage.getPayload(), StandardCharsets.UTF_8));
}
use of org.springframework.cloud.stream.binder.test.OutputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method byteArrayMessageToStringJsonMessageStreamListener.
@Test
public void byteArrayMessageToStringJsonMessageStreamListener() {
ApplicationContext context = new SpringApplicationBuilder(ByteArrayMessageToStringJsonMessageStreamListener.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.APPLICATION_JSON, outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertEquals("{\"name\":\"bob\"}", new String(outputMessage.getPayload(), StandardCharsets.UTF_8));
}
Aggregations