use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toMessageJsonView.
@Test
public void toMessageJsonView() throws Exception {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
Map<String, Object> map = new HashMap<>();
Method method = getClass().getDeclaredMethod("jsonViewResponse");
MethodParameter returnType = new MethodParameter(method, -1);
Message<?> message = converter.toMessage(jsonViewResponse(), new MessageHeaders(map), returnType);
String actual = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
assertThat(actual, containsString("\"withView1\":\"with\""));
assertThat(actual, containsString("\"withView2\":\"with\""));
assertThat(actual, not(containsString("\"withoutView\":\"with\"")));
method = getClass().getDeclaredMethod("jsonViewPayload", JacksonViewBean.class);
MethodParameter param = new MethodParameter(method, 0);
JacksonViewBean back = (JacksonViewBean) converter.fromMessage(message, JacksonViewBean.class, param);
assertNull(back.getWithView1());
assertEquals("with", back.getWithView2());
assertNull(back.getWithoutView());
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method toMessageWithPayloadAndMutableHeaders.
@Test
public void toMessageWithPayloadAndMutableHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar");
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
Message<?> message = this.converter.toMessage("payload", headers);
assertEquals("payload", message.getPayload());
assertSame(headers, message.getHeaders());
assertEquals("bar", message.getHeaders().get("foo"));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class StringMessageConverterTests method toMessage.
@Test
public void toMessage() {
Map<String, Object> map = new HashMap<>();
map.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN);
MessageHeaders headers = new MessageHeaders(map);
Message<?> message = this.converter.toMessage("ABC", headers);
assertEquals("ABC", new String(((byte[]) message.getPayload())));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class TestMessagePostProcessor method convertAndSendPayloadAndMutableHeadersToDestination.
@Test
public void convertAndSendPayloadAndMutableHeadersToDestination() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar");
accessor.setLeaveMutable(true);
MessageHeaders messageHeaders = accessor.getMessageHeaders();
this.template.setMessageConverter(new StringMessageConverter());
this.template.convertAndSend("somewhere", "payload", messageHeaders);
MessageHeaders actual = this.template.message.getHeaders();
assertSame(messageHeaders, actual);
assertEquals(new MimeType("text", "plain", StandardCharsets.UTF_8), actual.get(MessageHeaders.CONTENT_TYPE));
assertEquals("bar", actual.get("foo"));
}
Aggregations