use of org.springframework.cloud.stream.binder.test.InputDestination 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));
}
use of org.springframework.cloud.stream.binder.test.InputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method _toStringDefaultContentTypePropertyUnknownContentType.
@Test
public void _toStringDefaultContentTypePropertyUnknownContentType() {
ApplicationContext context = new SpringApplicationBuilder(StringToStringStreamListener.class).web(WebApplicationType.NONE).run("--spring.cloud.stream.default.contentType=foo/bar", "--spring.jmx.enabled=false");
InputDestination source = context.getBean(InputDestination.class);
TestChannelBinder binder = context.getBean(TestChannelBinder.class);
String jsonPayload = "{\"name\":\"oleg\"}";
source.send(new GenericMessage<>(jsonPayload.getBytes()));
assertTrue(binder.getLastError().getPayload() instanceof MessageConversionException);
}
use of org.springframework.cloud.stream.binder.test.InputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method byteArrayToPojoInboundContentTypeBinding.
@Test
public void byteArrayToPojoInboundContentTypeBinding() {
ApplicationContext context = new SpringApplicationBuilder(ByteArrayToPojoStreamListener.class).web(WebApplicationType.NONE).run("--spring.cloud.stream.bindings.input.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.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.InputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method pojoMessageToStringMessage.
@Test
public void pojoMessageToStringMessage() {
ApplicationContext context = new SpringApplicationBuilder(PojoMessageToStringMessageStreamListener.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));
}
use of org.springframework.cloud.stream.binder.test.InputDestination in project spring-cloud-stream by spring-cloud.
the class ContentTypeTckTests method kryo_pojoToPojo.
@Test
@SuppressWarnings("deprecation")
public void kryo_pojoToPojo() {
ApplicationContext context = new SpringApplicationBuilder(PojoToPojoStreamListener.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);
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(new GenericMessage<>(message.getPayload()));
Message<byte[]> outputMessage = target.receive();
assertNotNull(outputMessage);
MimeType contentType = (MimeType) outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE);
assertEquals("x-java-object", contentType.getSubtype());
assertEquals(Person.class.getName(), contentType.getParameters().get("type"));
}
Aggregations