42
42
import org .springframework .messaging .MessageHeaders ;
43
43
import org .springframework .messaging .converter .MappingJackson2MessageConverter ;
44
44
import org .springframework .messaging .converter .StringMessageConverter ;
45
+ import org .springframework .messaging .handler .DestinationPatternsMessageCondition ;
45
46
import org .springframework .messaging .handler .annotation .SendTo ;
47
+ import org .springframework .messaging .handler .annotation .support .DestinationVariableMethodArgumentResolver ;
46
48
import org .springframework .messaging .simp .SimpMessageHeaderAccessor ;
47
49
import org .springframework .messaging .simp .SimpMessageSendingOperations ;
48
50
import org .springframework .messaging .simp .SimpMessagingTemplate ;
54
56
55
57
import static org .junit .Assert .*;
56
58
import static org .mockito .BDDMockito .*;
57
- import static org .springframework .messaging .handler .DestinationPatternsMessageCondition .*;
58
- import static org .springframework .messaging .handler .annotation .support .DestinationVariableMethodArgumentResolver .*;
59
- import static org .springframework .messaging .support .MessageHeaderAccessor .*;
60
59
61
60
/**
62
61
* Test fixture for {@link SendToMethodReturnValueHandlerTests}.
@@ -357,7 +356,8 @@ public void testHeadersToSend() throws Exception {
357
356
verify (messagingTemplate ).convertAndSend (eq ("/topic/dest" ), eq (PAYLOAD ), captor .capture ());
358
357
359
358
MessageHeaders headers = captor .getValue ();
360
- SimpMessageHeaderAccessor accessor = getAccessor (headers , SimpMessageHeaderAccessor .class );
359
+ SimpMessageHeaderAccessor accessor =
360
+ MessageHeaderAccessor .getAccessor (headers , SimpMessageHeaderAccessor .class );
361
361
assertNotNull (accessor );
362
362
assertTrue (accessor .isMutable ());
363
363
assertEquals ("sess1" , accessor .getSessionId ());
@@ -399,7 +399,7 @@ public void sendToWithDestinationPlaceholders() throws Exception {
399
399
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor .create ();
400
400
accessor .setSessionId (sessionId );
401
401
accessor .setSubscriptionId ("sub1" );
402
- accessor .setHeader (DESTINATION_TEMPLATE_VARIABLES_HEADER , vars );
402
+ accessor .setHeader (DestinationVariableMethodArgumentResolver . DESTINATION_TEMPLATE_VARIABLES_HEADER , vars );
403
403
Message <?> message = MessageBuilder .createMessage (PAYLOAD , accessor .getMessageHeaders ());
404
404
this .handler .handleReturnValue (PAYLOAD , this .sendToWithPlaceholdersReturnType , message );
405
405
@@ -549,7 +549,7 @@ private Message<?> createMessage(String sessId, String subsId, String destPrefix
549
549
headerAccessor .setSubscriptionId (subsId );
550
550
if (dest != null && destPrefix != null ) {
551
551
headerAccessor .setDestination (destPrefix + dest );
552
- headerAccessor .setHeader (LOOKUP_DESTINATION_HEADER , dest );
552
+ headerAccessor .setHeader (DestinationPatternsMessageCondition . LOOKUP_DESTINATION_HEADER , dest );
553
553
}
554
554
if (user != null ) {
555
555
headerAccessor .setUser (user );
@@ -563,83 +563,55 @@ private SimpMessageHeaderAccessor getCapturedAccessor(int index) {
563
563
}
564
564
565
565
566
- private static class TestUser implements Principal {
567
-
568
- public String getName () {
569
- return "joe" ;
570
- }
571
-
572
- public boolean implies (Subject subject ) {
573
- return false ;
574
- }
575
- }
576
-
577
- private static class UniqueUser extends TestUser implements DestinationUserNameProvider {
578
-
579
- @ Override
580
- public String getDestinationUserName () {
581
- return "Me myself and I" ;
582
- }
583
- }
584
-
585
- @ SendTo
586
- @ Retention (RetentionPolicy .RUNTIME )
587
- @interface MySendTo {
588
-
589
- @ AliasFor (annotation = SendTo .class , attribute = "value" )
590
- String [] dest ();
591
- }
592
-
593
- @ SendToUser
594
- @ Retention (RetentionPolicy .RUNTIME )
595
- @interface MySendToUser {
596
-
597
- @ AliasFor (annotation = SendToUser .class , attribute = "destinations" )
598
- String [] dest ();
599
- }
600
-
601
-
602
566
@ SuppressWarnings ("unused" )
603
567
String handleNoAnnotations () {
604
568
return PAYLOAD ;
605
569
}
606
570
607
- @ SendTo @ SuppressWarnings ("unused" )
571
+ @ SendTo
572
+ @ SuppressWarnings ("unused" )
608
573
String handleAndSendToDefaultDestination () {
609
574
return PAYLOAD ;
610
575
}
611
576
612
- @ SendTo ({"/dest1" , "/dest2" }) @ SuppressWarnings ("unused" )
577
+ @ SendTo ({"/dest1" , "/dest2" })
578
+ @ SuppressWarnings ("unused" )
613
579
String handleAndSendTo () {
614
580
return PAYLOAD ;
615
581
}
616
582
617
- @ SendTo ("/topic/chat.message.filtered.{roomName}" ) @ SuppressWarnings ("unused" )
583
+ @ SendTo ("/topic/chat.message.filtered.{roomName}" )
584
+ @ SuppressWarnings ("unused" )
618
585
String handleAndSendToWithPlaceholders () {
619
586
return PAYLOAD ;
620
587
}
621
588
622
- @ SendToUser @ SuppressWarnings ("unused" )
589
+ @ SendToUser
590
+ @ SuppressWarnings ("unused" )
623
591
String handleAndSendToUserDefaultDestination () {
624
592
return PAYLOAD ;
625
593
}
626
594
627
- @ SendToUser (broadcast = false ) @ SuppressWarnings ("unused" )
595
+ @ SendToUser (broadcast = false )
596
+ @ SuppressWarnings ("unused" )
628
597
String handleAndSendToUserDefaultDestinationSingleSession () {
629
598
return PAYLOAD ;
630
599
}
631
600
632
- @ SendToUser ({"/dest1" , "/dest2" }) @ SuppressWarnings ("unused" )
601
+ @ SendToUser ({"/dest1" , "/dest2" })
602
+ @ SuppressWarnings ("unused" )
633
603
String handleAndSendToUser () {
634
604
return PAYLOAD ;
635
605
}
636
606
637
- @ SendToUser (destinations = { "/dest1" , "/dest2" }, broadcast = false ) @ SuppressWarnings ("unused" )
607
+ @ SendToUser (destinations = { "/dest1" , "/dest2" }, broadcast = false )
608
+ @ SuppressWarnings ("unused" )
638
609
String handleAndSendToUserSingleSession () {
639
610
return PAYLOAD ;
640
611
}
641
612
642
- @ JsonView (MyJacksonView1 .class ) @ SuppressWarnings ("unused" )
613
+ @ JsonView (MyJacksonView1 .class )
614
+ @ SuppressWarnings ("unused" )
643
615
JacksonViewBean handleAndSendToJsonView () {
644
616
JacksonViewBean payload = new JacksonViewBean ();
645
617
payload .setWithView1 ("with" );
@@ -649,6 +621,45 @@ JacksonViewBean handleAndSendToJsonView() {
649
621
}
650
622
651
623
624
+ private static class TestUser implements Principal {
625
+
626
+ public String getName () {
627
+ return "joe" ;
628
+ }
629
+
630
+ public boolean implies (Subject subject ) {
631
+ return false ;
632
+ }
633
+ }
634
+
635
+
636
+ private static class UniqueUser extends TestUser implements DestinationUserNameProvider {
637
+
638
+ @ Override
639
+ public String getDestinationUserName () {
640
+ return "Me myself and I" ;
641
+ }
642
+ }
643
+
644
+
645
+ @ SendTo
646
+ @ Retention (RetentionPolicy .RUNTIME )
647
+ @interface MySendTo {
648
+
649
+ @ AliasFor (annotation = SendTo .class , attribute = "value" )
650
+ String [] dest ();
651
+ }
652
+
653
+
654
+ @ SendToUser
655
+ @ Retention (RetentionPolicy .RUNTIME )
656
+ @interface MySendToUser {
657
+
658
+ @ AliasFor (annotation = SendToUser .class , attribute = "destinations" )
659
+ String [] dest ();
660
+ }
661
+
662
+
652
663
@ MySendTo (dest = "/dest-default" ) @ SuppressWarnings ("unused" )
653
664
private static class SendToTestBean {
654
665
@@ -667,6 +678,7 @@ String handleAndSendToOverride() {
667
678
}
668
679
}
669
680
681
+
670
682
@ MySendToUser (dest = "/dest-default" ) @ SuppressWarnings ("unused" )
671
683
private static class SendToUserTestBean {
672
684
@@ -685,6 +697,7 @@ String handleAndSendToOverride() {
685
697
}
686
698
}
687
699
700
+
688
701
@ MySendToUser (dest = "/dest-default" ) @ SuppressWarnings ("unused" )
689
702
private static class SendToUserWithSendToOverrideTestBean {
690
703
@@ -701,8 +714,10 @@ String handleAndSendToOverride() {
701
714
702
715
703
716
private interface MyJacksonView1 {}
717
+
704
718
private interface MyJacksonView2 {}
705
719
720
+
706
721
@ SuppressWarnings ("unused" )
707
722
private static class JacksonViewBean {
708
723
0 commit comments