use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method sendToDefaultDestinationWhenUsingDotPathSeparator.
@Test
public void sendToDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
Message<?> inputMessage = createMessage("sess1", "sub1", "/app/", "dest.foo.bar", null);
this.handler.handleReturnValue(PAYLOAD, this.sendToDefaultDestReturnType, inputMessage);
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
assertEquals("/topic/dest.foo.bar", accessor.getDestination());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method sendToUserDefaultDestinationWhenUsingDotPathSeparator.
@Test
public void sendToUserDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
TestUser user = new TestUser();
Message<?> inputMessage = createMessage("sess1", "sub1", "/app/", "dest.foo.bar", user);
this.handler.handleReturnValue(PAYLOAD, this.sendToUserDefaultDestReturnType, inputMessage);
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
assertEquals("/user/" + user.getName() + "/queue/dest.foo.bar", accessor.getDestination());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class SendToMethodReturnValueHandlerTests method sendToUserSessionWithoutUserName.
@Test
public void sendToUserSessionWithoutUserName() throws Exception {
given(this.messageChannel.send(any(Message.class))).willReturn(true);
String sessionId = "sess1";
Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
this.handler.handleReturnValue(PAYLOAD, this.sendToUserReturnType, inputMessage);
verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
assertEquals("/user/sess1/dest1", accessor.getDestination());
assertEquals("sess1", accessor.getSessionId());
accessor = getCapturedAccessor(1);
assertEquals("/user/sess1/dest2", accessor.getDestination());
assertEquals("sess1", accessor.getSessionId());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class SimpAnnotationMethodMessageHandlerTests method createMessage.
private Message<?> createMessage(String destination, Map<String, Object> headers) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setSessionId("session1");
accessor.setSessionAttributes(new HashMap<>());
accessor.setDestination(destination);
if (headers != null) {
for (Map.Entry<String, Object> entry : headers.entrySet()) {
accessor.setHeader(entry.getKey(), entry.getValue());
}
}
return MessageBuilder.withPayload(new byte[0]).setHeaders(accessor).build();
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework by spring-projects.
the class SubscriptionMethodReturnValueHandlerTests method createInputMessage.
private Message<?> createInputMessage(String sessId, String subsId, String dest, Principal principal) {
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
headers.setSessionId(sessId);
headers.setSubscriptionId(subsId);
headers.setDestination(dest);
headers.setUser(principal);
return MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build();
}
Aggregations