@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2017 the original author or authors .
* Copyright 2002 - 2018 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -50,6 +50,7 @@ import org.springframework.messaging.simp.SimpAttributes;
@@ -50,6 +50,7 @@ import org.springframework.messaging.simp.SimpAttributes;
import org.springframework.messaging.simp.SimpAttributesContextHolder ;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor ;
import org.springframework.messaging.simp.SimpMessageSendingOperations ;
import org.springframework.messaging.simp.SimpMessageType ;
import org.springframework.messaging.simp.SimpMessagingTemplate ;
import org.springframework.messaging.simp.annotation.SubscribeMapping ;
import org.springframework.messaging.support.MessageBuilder ;
@ -73,7 +74,6 @@ import static org.mockito.BDDMockito.*;
@@ -73,7 +74,6 @@ import static org.mockito.BDDMockito.*;
* @author Brian Clozel
* @author Sebastien Deleuze
* /
@SuppressWarnings ( "unused" )
public class SimpAnnotationMethodMessageHandlerTests {
private static final String TEST_INVALID_VALUE = "invalidValue" ;
@ -158,7 +158,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
@@ -158,7 +158,7 @@ public class SimpAnnotationMethodMessageHandlerTests {
@Test
public void subscribeEventDestinationVariableResolution ( ) {
Message < ? > message = createMessage ( "/pre/sub/bar/value" ) ;
Message < ? > message = createMessage ( SimpMessageType . SUBSCRIBE , "/pre/sub/bar/value" , null ) ;
this . messageHandler . registerHandler ( this . testController ) ;
this . messageHandler . handleMessage ( message ) ;
@ -199,6 +199,30 @@ public class SimpAnnotationMethodMessageHandlerTests {
@@ -199,6 +199,30 @@ public class SimpAnnotationMethodMessageHandlerTests {
assertEquals ( "illegalState" , handlerMethod . getMethod ( ) . getName ( ) ) ;
}
@Test
public void exceptionAsCause ( ) {
Message < ? > message = createMessage ( "/pre/illegalStateCause" ) ;
this . messageHandler . registerHandler ( this . testController ) ;
this . messageHandler . handleMessage ( message ) ;
assertEquals ( "handleExceptionWithHandlerMethodArg" , this . testController . method ) ;
HandlerMethod handlerMethod = ( HandlerMethod ) this . testController . arguments . get ( "handlerMethod" ) ;
assertNotNull ( handlerMethod ) ;
assertEquals ( "illegalStateCause" , handlerMethod . getMethod ( ) . getName ( ) ) ;
}
@Test
public void errorAsMessageHandlingException ( ) {
Message < ? > message = createMessage ( "/pre/error" ) ;
this . messageHandler . registerHandler ( this . testController ) ;
this . messageHandler . handleMessage ( message ) ;
assertEquals ( "handleErrorWithHandlerMethodArg" , this . testController . method ) ;
HandlerMethod handlerMethod = ( HandlerMethod ) this . testController . arguments . get ( "handlerMethod" ) ;
assertNotNull ( handlerMethod ) ;
assertEquals ( "errorAsThrowable" , handlerMethod . getMethod ( ) . getName ( ) ) ;
}
@Test
public void simpScope ( ) {
Map < String , Object > sessionAttributes = new ConcurrentHashMap < > ( ) ;
@ -327,7 +351,11 @@ public class SimpAnnotationMethodMessageHandlerTests {
@@ -327,7 +351,11 @@ public class SimpAnnotationMethodMessageHandlerTests {
}
private Message < ? > createMessage ( String destination , Map < String , Object > headers ) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor . create ( ) ;
return createMessage ( SimpMessageType . MESSAGE , destination , headers ) ;
}
private Message < ? > createMessage ( SimpMessageType messageType , String destination , Map < String , Object > headers ) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor . create ( messageType ) ;
accessor . setSessionId ( "session1" ) ;
accessor . setSessionAttributes ( new HashMap < > ( ) ) ;
accessor . setDestination ( destination ) ;
@ -406,7 +434,17 @@ public class SimpAnnotationMethodMessageHandlerTests {
@@ -406,7 +434,17 @@ public class SimpAnnotationMethodMessageHandlerTests {
@MessageMapping ( "/illegalState" )
public void illegalState ( ) {
throw new IllegalStateException ( ) ;
throw new IllegalStateException ( "my cause" ) ;
}
@MessageMapping ( "/illegalStateCause" )
public void illegalStateCause ( ) {
throw new RuntimeException ( new IllegalStateException ( "my cause" ) ) ;
}
@MessageMapping ( "/error" )
public void errorAsThrowable ( ) {
throw new Error ( "my cause" ) ;
}
@MessageExceptionHandler ( MethodArgumentNotValidException . class )
@ -414,10 +452,18 @@ public class SimpAnnotationMethodMessageHandlerTests {
@@ -414,10 +452,18 @@ public class SimpAnnotationMethodMessageHandlerTests {
this . method = "handleValidationException" ;
}
@MessageExceptionHandler ( IllegalStateException . class )
public void handleExceptionWithHandlerMethodArg ( HandlerMethod handlerMethod ) {
@MessageExceptionHandler
public void handleExceptionWithHandlerMethodArg ( IllegalStateException ex , HandlerMethod handlerMethod ) {
this . method = "handleExceptionWithHandlerMethodArg" ;
this . arguments . put ( "handlerMethod" , handlerMethod ) ;
assertEquals ( "my cause" , ex . getMessage ( ) ) ;
}
@MessageExceptionHandler
public void handleErrorWithHandlerMethodArg ( Error ex , HandlerMethod handlerMethod ) {
this . method = "handleErrorWithHandlerMethodArg" ;
this . arguments . put ( "handlerMethod" , handlerMethod ) ;
assertEquals ( "my cause" , ex . getMessage ( ) ) ;
}
@MessageMapping ( "/scope" )
@ -440,7 +486,6 @@ public class SimpAnnotationMethodMessageHandlerTests {
@@ -440,7 +486,6 @@ public class SimpAnnotationMethodMessageHandlerTests {
private String method ;
@MessageMapping ( "foo" )
public void handleFoo ( ) {
this . method = "handleFoo" ;