@ -74,7 +74,9 @@ public class SendToMethodReturnValueHandlerTests {
private MethodParameter sendToReturnType ;
private MethodParameter sendToDefaultDestReturnType ;
private MethodParameter sendToUserReturnType ;
private MethodParameter sendToUserSingleSessionReturnType ;
private MethodParameter sendToUserDefaultDestReturnType ;
private MethodParameter sendToUserSingleSessionDefaultDestReturnType ;
@Before
@ -101,8 +103,14 @@ public class SendToMethodReturnValueHandlerTests {
method = this . getClass ( ) . getDeclaredMethod ( "handleAndSendToUser" ) ;
this . sendToUserReturnType = new MethodParameter ( method , - 1 ) ;
method = this . getClass ( ) . getDeclaredMethod ( "handleAndSendToUserSingleSession" ) ;
this . sendToUserSingleSessionReturnType = new MethodParameter ( method , - 1 ) ;
method = this . getClass ( ) . getDeclaredMethod ( "handleAndSendToUserDefaultDestination" ) ;
this . sendToUserDefaultDestReturnType = new MethodParameter ( method , - 1 ) ;
method = this . getClass ( ) . getDeclaredMethod ( "handleAndSendToUserSingleSessionDefaultDestination" ) ;
this . sendToUserSingleSessionDefaultDestReturnType = new MethodParameter ( method , - 1 ) ;
}
@ -211,6 +219,31 @@ public class SendToMethodReturnValueHandlerTests {
verify ( this . messageChannel , times ( 2 ) ) . send ( this . messageCaptor . capture ( ) ) ;
Message < ? > message = this . messageCaptor . getAllValues ( ) . get ( 0 ) ;
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor . wrap ( message ) ;
assertNull ( headers . getSessionId ( ) ) ;
assertNull ( headers . getSubscriptionId ( ) ) ;
assertEquals ( "/user/" + user . getName ( ) + "/dest1" , headers . getDestination ( ) ) ;
message = this . messageCaptor . getAllValues ( ) . get ( 1 ) ;
headers = SimpMessageHeaderAccessor . wrap ( message ) ;
assertNull ( headers . getSessionId ( ) ) ;
assertNull ( headers . getSubscriptionId ( ) ) ;
assertEquals ( "/user/" + user . getName ( ) + "/dest2" , headers . getDestination ( ) ) ;
}
@Test
public void sendToUserSingleSession ( ) throws Exception {
when ( this . messageChannel . send ( any ( Message . class ) ) ) . thenReturn ( true ) ;
String sessionId = "sess1" ;
TestUser user = new TestUser ( ) ;
Message < ? > inputMessage = createInputMessage ( sessionId , "sub1" , null , user ) ;
this . handler . handleReturnValue ( payloadContent , this . sendToUserSingleSessionReturnType , inputMessage ) ;
verify ( this . messageChannel , times ( 2 ) ) . send ( this . messageCaptor . capture ( ) ) ;
Message < ? > message = this . messageCaptor . getAllValues ( ) . get ( 0 ) ;
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor . wrap ( message ) ;
assertEquals ( sessionId , headers . getSessionId ( ) ) ;
@ -257,6 +290,25 @@ public class SendToMethodReturnValueHandlerTests {
verify ( this . messageChannel , times ( 1 ) ) . send ( this . messageCaptor . capture ( ) ) ;
Message < ? > message = this . messageCaptor . getAllValues ( ) . get ( 0 ) ;
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor . wrap ( message ) ;
assertNull ( headers . getSessionId ( ) ) ;
assertNull ( headers . getSubscriptionId ( ) ) ;
assertEquals ( "/user/" + user . getName ( ) + "/queue/dest" , headers . getDestination ( ) ) ;
}
@Test
public void sendToUserDefaultDestinationSingleSession ( ) throws Exception {
when ( this . messageChannel . send ( any ( Message . class ) ) ) . thenReturn ( true ) ;
String sessionId = "sess1" ;
TestUser user = new TestUser ( ) ;
Message < ? > inputMessage = createInputMessage ( sessionId , "sub1" , "/dest" , user ) ;
this . handler . handleReturnValue ( payloadContent , this . sendToUserSingleSessionDefaultDestReturnType , inputMessage ) ;
verify ( this . messageChannel , times ( 1 ) ) . send ( this . messageCaptor . capture ( ) ) ;
Message < ? > message = this . messageCaptor . getAllValues ( ) . get ( 0 ) ;
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor . wrap ( message ) ;
assertEquals ( sessionId , headers . getSessionId ( ) ) ;
@ -343,9 +395,19 @@ public class SendToMethodReturnValueHandlerTests {
return PAYLOAD ;
}
@SendToUser ( singleSession = true )
public String handleAndSendToUserSingleSessionDefaultDestination ( ) {
return payloadContent ;
}
@SendToUser ( { "/dest1" , "/dest2" } )
public String handleAndSendToUser ( ) {
return PAYLOAD ;
}
@SendToUser ( value = { "/dest1" , "/dest2" } , singleSession = true )
public String handleAndSendToUserSingleSession ( ) {
return payloadContent ;
}
}