11/*
2- * Copyright 2002-2015 the original author or authors.
2+ * Copyright 2002-2016 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1818
1919import java .lang .reflect .Method ;
2020import java .nio .charset .Charset ;
21- import java .nio .charset .StandardCharsets ;
2221import java .security .Principal ;
2322import java .util .LinkedHashMap ;
2423import java .util .Map ;
4241import org .springframework .messaging .converter .StringMessageConverter ;
4342import org .springframework .messaging .handler .DestinationPatternsMessageCondition ;
4443import org .springframework .messaging .handler .annotation .SendTo ;
44+ import org .springframework .messaging .handler .annotation .support .DestinationVariableMethodArgumentResolver ;
4545import org .springframework .messaging .simp .SimpMessageHeaderAccessor ;
4646import org .springframework .messaging .simp .SimpMessageSendingOperations ;
4747import org .springframework .messaging .simp .SimpMessagingTemplate ;
5353
5454import static org .junit .Assert .*;
5555import static org .mockito .BDDMockito .*;
56- import static org .springframework .messaging .handler .annotation .support .DestinationVariableMethodArgumentResolver .*;
57- import static org .springframework .messaging .support .MessageHeaderAccessor .*;
5856
5957/**
6058 * Test fixture for {@link SendToMethodReturnValueHandlerTests}.
@@ -103,31 +101,31 @@ public void setup() throws Exception {
103101 jsonMessagingTemplate .setMessageConverter (new MappingJackson2MessageConverter ());
104102 this .jsonHandler = new SendToMethodReturnValueHandler (jsonMessagingTemplate , true );
105103
106- Method method = this . getClass ().getDeclaredMethod ("handleNoAnnotations" );
104+ Method method = getClass ().getDeclaredMethod ("handleNoAnnotations" );
107105 this .noAnnotationsReturnType = new SynthesizingMethodParameter (method , -1 );
108106
109- method = this . getClass ().getDeclaredMethod ("handleAndSendToDefaultDestination" );
107+ method = getClass ().getDeclaredMethod ("handleAndSendToDefaultDestination" );
110108 this .sendToDefaultDestReturnType = new SynthesizingMethodParameter (method , -1 );
111109
112- method = this . getClass ().getDeclaredMethod ("handleAndSendTo" );
110+ method = getClass ().getDeclaredMethod ("handleAndSendTo" );
113111 this .sendToReturnType = new SynthesizingMethodParameter (method , -1 );
114112
115- method = this . getClass ().getDeclaredMethod ("handleAndSendToWithPlaceholders" );
113+ method = getClass ().getDeclaredMethod ("handleAndSendToWithPlaceholders" );
116114 this .sendToWithPlaceholdersReturnType = new SynthesizingMethodParameter (method , -1 );
117115
118- method = this . getClass ().getDeclaredMethod ("handleAndSendToUser" );
116+ method = getClass ().getDeclaredMethod ("handleAndSendToUser" );
119117 this .sendToUserReturnType = new SynthesizingMethodParameter (method , -1 );
120118
121- method = this . getClass ().getDeclaredMethod ("handleAndSendToUserSingleSession" );
119+ method = getClass ().getDeclaredMethod ("handleAndSendToUserSingleSession" );
122120 this .sendToUserSingleSessionReturnType = new SynthesizingMethodParameter (method , -1 );
123121
124- method = this . getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestination" );
122+ method = getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestination" );
125123 this .sendToUserDefaultDestReturnType = new SynthesizingMethodParameter (method , -1 );
126124
127- method = this . getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestinationSingleSession" );
125+ method = getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestinationSingleSession" );
128126 this .sendToUserSingleSessionDefaultDestReturnType = new SynthesizingMethodParameter (method , -1 );
129127
130- method = this . getClass ().getDeclaredMethod ("handleAndSendToJsonView" );
128+ method = getClass ().getDeclaredMethod ("handleAndSendToJsonView" );
131129 this .jsonViewReturnType = new SynthesizingMethodParameter (method , -1 );
132130 }
133131
@@ -226,7 +224,8 @@ public void testHeadersToSend() throws Exception {
226224 verify (messagingTemplate ).convertAndSend (eq ("/topic/dest" ), eq (PAYLOAD ), captor .capture ());
227225
228226 MessageHeaders messageHeaders = captor .getValue ();
229- SimpMessageHeaderAccessor accessor = getAccessor (messageHeaders , SimpMessageHeaderAccessor .class );
227+ SimpMessageHeaderAccessor accessor =
228+ MessageHeaderAccessor .getAccessor (messageHeaders , SimpMessageHeaderAccessor .class );
230229 assertNotNull (accessor );
231230 assertTrue (accessor .isMutable ());
232231 assertEquals ("sess1" , accessor .getSessionId ());
@@ -267,7 +266,7 @@ public void sendToWithDestinationPlaceholders() throws Exception {
267266 SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor .create ();
268267 accessor .setSessionId (sessionId );
269268 accessor .setSubscriptionId ("sub1" );
270- accessor .setHeader (DESTINATION_TEMPLATE_VARIABLES_HEADER , vars );
269+ accessor .setHeader (DestinationVariableMethodArgumentResolver . DESTINATION_TEMPLATE_VARIABLES_HEADER , vars );
271270 Message <?> message = MessageBuilder .createMessage (PAYLOAD , accessor .getMessageHeaders ());
272271 this .handler .handleReturnValue (PAYLOAD , this .sendToWithPlaceholdersReturnType , message );
273272
@@ -403,7 +402,7 @@ public void jsonView() throws Exception {
403402 Message <?> message = this .messageCaptor .getValue ();
404403 assertNotNull (message );
405404
406- assertEquals ("{\" withView1\" :\" with\" }" , new String ((byte []) message .getPayload (), StandardCharsets . UTF_8 ));
405+ assertEquals ("{\" withView1\" :\" with\" }" , new String ((byte []) message .getPayload (), Charset . forName ( "UTF-8" ) ));
407406 }
408407
409408
@@ -429,25 +428,6 @@ private SimpMessageHeaderAccessor getCapturedAccessor(int index) {
429428 }
430429
431430
432- private static class TestUser implements Principal {
433-
434- public String getName () {
435- return "joe" ;
436- }
437-
438- public boolean implies (Subject subject ) {
439- return false ;
440- }
441- }
442-
443- private static class UniqueUser extends TestUser implements DestinationUserNameProvider {
444-
445- @ Override
446- public String getDestinationUserName () {
447- return "Me myself and I" ;
448- }
449- }
450-
451431 public String handleNoAnnotations () {
452432 return PAYLOAD ;
453433 }
@@ -498,9 +478,32 @@ public JacksonViewBean handleAndSendToJsonView() {
498478 }
499479
500480
481+ private static class TestUser implements Principal {
482+
483+ public String getName () {
484+ return "joe" ;
485+ }
486+
487+ public boolean implies (Subject subject ) {
488+ return false ;
489+ }
490+ }
491+
492+
493+ private static class UniqueUser extends TestUser implements DestinationUserNameProvider {
494+
495+ @ Override
496+ public String getDestinationUserName () {
497+ return "Me myself and I" ;
498+ }
499+ }
500+
501+
501502 private interface MyJacksonView1 {}
503+
502504 private interface MyJacksonView2 {}
503505
506+
504507 @ SuppressWarnings ("unused" )
505508 private static class JacksonViewBean {
506509
@@ -516,23 +519,23 @@ public String getWithView1() {
516519 return withView1 ;
517520 }
518521
519- public void setWithView1 (String withView1 ) {
522+ void setWithView1 (String withView1 ) {
520523 this .withView1 = withView1 ;
521524 }
522525
523- public String getWithView2 () {
526+ String getWithView2 () {
524527 return withView2 ;
525528 }
526529
527- public void setWithView2 (String withView2 ) {
530+ void setWithView2 (String withView2 ) {
528531 this .withView2 = withView2 ;
529532 }
530533
531- public String getWithoutView () {
534+ String getWithoutView () {
532535 return withoutView ;
533536 }
534537
535- public void setWithoutView (String withoutView ) {
538+ void setWithoutView (String withoutView ) {
536539 this .withoutView = withoutView ;
537540 }
538541 }
0 commit comments