use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageHeaderAccessorTests method copyHeaders.
@Test
public void copyHeaders() {
Map<String, Object> map1 = new HashMap<>();
map1.put("foo", "bar");
GenericMessage<String> message = new GenericMessage<>("payload", map1);
MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
Map<String, Object> map2 = new HashMap<>();
map2.put("foo", "BAR");
map2.put("bar", "baz");
accessor.copyHeaders(map2);
MessageHeaders actual = accessor.getMessageHeaders();
assertEquals(3, actual.size());
assertEquals("BAR", actual.get("foo"));
assertEquals("baz", actual.get("bar"));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageHeaderAccessorTests method leaveMutable.
@Test
public void leaveMutable() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setHeader("foo", "bar");
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
Message<?> message = MessageBuilder.createMessage("payload", headers);
accessor.setHeader("foo", "baz");
assertEquals("baz", headers.get("foo"));
assertSame(accessor, MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageHeaderAccessorTests method removeHeaders.
@Test
public void removeHeaders() {
Map<String, Object> map = new HashMap<>();
map.put("foo", "bar");
map.put("bar", "baz");
GenericMessage<String> message = new GenericMessage<>("payload", map);
MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
accessor.removeHeaders("fo*");
MessageHeaders actual = accessor.getMessageHeaders();
assertEquals(2, actual.size());
assertNull(actual.get("foo"));
assertEquals("baz", actual.get("bar"));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class StompBrokerRelayMessageHandlerTests method systemSubscription.
@Test
public void systemSubscription() throws Exception {
MessageHandler handler = mock(MessageHandler.class);
this.brokerRelay.setSystemSubscriptions(Collections.singletonMap("/topic/foo", handler));
this.brokerRelay.start();
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
this.tcpClient.handleMessage(MessageBuilder.createMessage(new byte[0], headers));
assertEquals(2, this.tcpClient.getSentMessages().size());
assertEquals(StompCommand.CONNECT, this.tcpClient.getSentHeaders(0).getCommand());
assertEquals(StompCommand.SUBSCRIBE, this.tcpClient.getSentHeaders(1).getCommand());
assertEquals("/topic/foo", this.tcpClient.getSentHeaders(1).getDestination());
Message<byte[]> message = message(StompCommand.MESSAGE, null, null, "/topic/foo");
this.tcpClient.handleMessage(message);
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(handler).handleMessage(captor.capture());
assertSame(message, captor.getValue());
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class UserRegistryMessageHandlerTests method broadcastRegistry.
@Test
public void broadcastRegistry() throws Exception {
TestSimpUser simpUser1 = new TestSimpUser("joe");
TestSimpUser simpUser2 = new TestSimpUser("jane");
simpUser1.addSessions(new TestSimpSession("123"));
simpUser1.addSessions(new TestSimpSession("456"));
HashSet<SimpUser> simpUsers = new HashSet<>(Arrays.asList(simpUser1, simpUser2));
when(this.localRegistry.getUsers()).thenReturn(simpUsers);
getUserRegistryTask().run();
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(this.brokerChannel).send(captor.capture());
Message<?> message = captor.getValue();
assertNotNull(message);
MessageHeaders headers = message.getHeaders();
assertEquals("/topic/simp-user-registry", SimpMessageHeaderAccessor.getDestination(headers));
MultiServerUserRegistry remoteRegistry = new MultiServerUserRegistry(mock(SimpUserRegistry.class));
remoteRegistry.addRemoteRegistryDto(message, this.converter, 20000);
assertEquals(2, remoteRegistry.getUserCount());
assertNotNull(remoteRegistry.getUser("joe"));
assertNotNull(remoteRegistry.getUser("jane"));
}
Aggregations