use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageConverterTests method toMessageWithHeaders.
@Test
public void toMessageWithHeaders() {
Map<String, Object> map = new HashMap<>();
map.put("foo", "bar");
MessageHeaders headers = new MessageHeaders(map);
Message<?> message = this.converter.toMessage("ABC", headers);
assertNotNull(message.getHeaders().getId());
assertNotNull(message.getHeaders().getTimestamp());
assertEquals(MimeTypeUtils.TEXT_PLAIN, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
assertEquals("bar", message.getHeaders().get("foo"));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageConverterTests method toMessageWithMutableMessageHeaders.
@Test
public void toMessageWithMutableMessageHeaders() {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
accessor.setHeader("foo", "bar");
accessor.setNativeHeader("fooNative", "barNative");
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
Message<?> message = this.converter.toMessage("ABC", headers);
assertSame(headers, message.getHeaders());
assertNull(message.getHeaders().getId());
assertNull(message.getHeaders().getTimestamp());
assertEquals(MimeTypeUtils.TEXT_PLAIN, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class SimpleMessageConverterTests method toMessageWithPayloadAndHeaders.
@Test
public void toMessageWithPayloadAndHeaders() {
MessageHeaders headers = new MessageHeaders(Collections.<String, Object>singletonMap("foo", "bar"));
Message<?> message = this.converter.toMessage("payload", headers);
assertEquals("payload", message.getPayload());
assertEquals("bar", message.getHeaders().get("foo"));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class GenericMessagingTemplateTests method convertAndSendWithSimpMessageHeaders.
@Test
public void convertAndSendWithSimpMessageHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("key", "value");
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
this.template.convertAndSend("channel", "data", headers);
List<Message<byte[]>> messages = this.messageChannel.getMessages();
Message<byte[]> message = messages.get(0);
assertSame(headers, message.getHeaders());
assertFalse(accessor.isMutable());
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class DefaultContentTypeResolverTests method resolveInvalidStringContentType.
@Test(expected = InvalidMimeTypeException.class)
public void resolveInvalidStringContentType() {
Map<String, Object> map = new HashMap<>();
map.put(MessageHeaders.CONTENT_TYPE, "invalidContentType");
MessageHeaders headers = new MessageHeaders(map);
this.resolver.resolve(headers);
}
Aggregations