use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class SubscriptionMethodReturnValueHandlerTests method testMessageSentToChannel.
@Test
public void testMessageSentToChannel() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1";
String subscriptionId = "subs1";
String destination = "/dest";
Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);
this.handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);
verify(this.messageChannel).send(this.messageCaptor.capture());
assertNotNull(this.messageCaptor.getValue());
Message<?> message = this.messageCaptor.getValue();
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.wrap(message);
assertNull("SimpMessageHeaderAccessor should have disabled id", headerAccessor.getId());
assertNull("SimpMessageHeaderAccessor should have disabled timestamp", headerAccessor.getTimestamp());
assertEquals(sessionId, headerAccessor.getSessionId());
assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
assertEquals(destination, headerAccessor.getDestination());
assertEquals(MIME_TYPE, headerAccessor.getContentType());
assertEquals(this.subscribeEventReturnType, headerAccessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class DefaultSubscriptionRegistryTests method createMessage.
private Message<?> createMessage(String destination) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setDestination(destination);
return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class DefaultSubscriptionRegistryTests method unsubscribeMessage.
private Message<?> unsubscribeMessage(String sessionId, String subscriptionId) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.UNSUBSCRIBE);
accessor.setSessionId(sessionId);
accessor.setSubscriptionId(subscriptionId);
return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class DefaultSubscriptionRegistryTests method registerSubscriptionWithSelector.
@Test
public void registerSubscriptionWithSelector() throws Exception {
String sessionId = "sess01";
String subscriptionId = "subs01";
String destination = "/foo";
String selector = "headers.foo == 'bar'";
this.registry.registerSubscription(subscribeMessage(sessionId, subscriptionId, destination, selector));
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setDestination(destination);
accessor.setNativeHeader("foo", "bar");
Message<?> message = MessageBuilder.createMessage("", accessor.getMessageHeaders());
MultiValueMap<String, String> actual = this.registry.findSubscriptions(message);
assertNotNull(actual);
assertEquals(1, actual.size());
assertEquals(Collections.singletonList(subscriptionId), actual.get(sessionId));
actual = this.registry.findSubscriptions(createMessage(destination));
assertNotNull(actual);
assertEquals(0, actual.size());
}
Aggregations