Search in sources :

Example 11 with Message

use of org.springframework.messaging.Message in project spring-framework by spring-projects.

the class SendToMethodReturnValueHandlerTests method sendToUser.

@Test
public void sendToUser() throws Exception {
    given(this.messageChannel.send(any(Message.class))).willReturn(true);
    String sessionId = "sess1";
    TestUser user = new TestUser();
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, user);
    this.handler.handleReturnValue(PAYLOAD, this.sendToUserReturnType, inputMessage);
    verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
    SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
    assertNull(accessor.getSessionId());
    assertNull(accessor.getSubscriptionId());
    assertEquals("/user/" + user.getName() + "/dest1", accessor.getDestination());
    accessor = getCapturedAccessor(1);
    assertNull(accessor.getSessionId());
    assertNull(accessor.getSubscriptionId());
    assertEquals("/user/" + user.getName() + "/dest2", accessor.getDestination());
}
Also used : Message(org.springframework.messaging.Message) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 12 with Message

use of org.springframework.messaging.Message in project spring-framework by spring-projects.

the class SendToMethodReturnValueHandlerTests method sendToUserDefaultDestinationSingleSession.

@Test
public void sendToUserDefaultDestinationSingleSession() throws Exception {
    given(this.messageChannel.send(any(Message.class))).willReturn(true);
    String sessionId = "sess1";
    TestUser user = new TestUser();
    Message<?> message = createMessage(sessionId, "sub1", "/app", "/dest", user);
    this.handler.handleReturnValue(PAYLOAD, this.sendToUserSingleSessionDefaultDestReturnType, message);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
    assertEquals(sessionId, accessor.getSessionId());
    assertEquals("/user/" + user.getName() + "/queue/dest", accessor.getDestination());
    assertEquals(MIME_TYPE, accessor.getContentType());
    assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
    assertEquals(this.sendToUserSingleSessionDefaultDestReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
Also used : Message(org.springframework.messaging.Message) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 13 with Message

use of org.springframework.messaging.Message in project spring-framework by spring-projects.

the class SendToMethodReturnValueHandlerTests method sendToUserWithSendToOverride.

// SPR-14238
@Test
public void sendToUserWithSendToOverride() throws Exception {
    given(this.messageChannel.send(any(Message.class))).willReturn(true);
    Class<?> clazz = SendToUserWithSendToOverrideTestBean.class;
    Method method = clazz.getDeclaredMethod("handleAndSendToOverride");
    MethodParameter parameter = new SynthesizingMethodParameter(method, -1);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, parameter, inputMessage);
    verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
    assertResponse(parameter, sessionId, 0, "/dest3");
    assertResponse(parameter, sessionId, 1, "/dest4");
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) Message(org.springframework.messaging.Message) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) Test(org.junit.Test)

Example 14 with Message

use of org.springframework.messaging.Message 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());
}
Also used : Message(org.springframework.messaging.Message) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 15 with Message

use of org.springframework.messaging.Message 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());
}
Also used : Message(org.springframework.messaging.Message) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Aggregations

Message (org.springframework.messaging.Message)51 Test (org.junit.Test)41 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)16 MessageHeaders (org.springframework.messaging.MessageHeaders)14 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)9 BinaryMessage (org.springframework.web.socket.BinaryMessage)9 TextMessage (org.springframework.web.socket.TextMessage)9 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)6 ByteBuffer (java.nio.ByteBuffer)5 MessageChannel (org.springframework.messaging.MessageChannel)4 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)4 Method (java.lang.reflect.Method)3 MethodParameter (org.springframework.core.MethodParameter)3 TestPrincipal (org.springframework.messaging.simp.TestPrincipal)3 Principal (java.security.Principal)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 TextMessage (javax.jms.TextMessage)2 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)2 StubTextMessage (org.springframework.jms.StubTextMessage)2 MessagingException (org.springframework.messaging.MessagingException)2