1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import java .lang .reflect .Method ;
20
20
import java .nio .charset .Charset ;
21
- import java .nio .charset .StandardCharsets ;
22
21
import java .security .Principal ;
23
22
import java .util .LinkedHashMap ;
24
23
import java .util .Map ;
42
41
import org .springframework .messaging .converter .StringMessageConverter ;
43
42
import org .springframework .messaging .handler .DestinationPatternsMessageCondition ;
44
43
import org .springframework .messaging .handler .annotation .SendTo ;
44
+ import org .springframework .messaging .handler .annotation .support .DestinationVariableMethodArgumentResolver ;
45
45
import org .springframework .messaging .simp .SimpMessageHeaderAccessor ;
46
46
import org .springframework .messaging .simp .SimpMessageSendingOperations ;
47
47
import org .springframework .messaging .simp .SimpMessagingTemplate ;
53
53
54
54
import static org .junit .Assert .*;
55
55
import static org .mockito .BDDMockito .*;
56
- import static org .springframework .messaging .handler .annotation .support .DestinationVariableMethodArgumentResolver .*;
57
- import static org .springframework .messaging .support .MessageHeaderAccessor .*;
58
56
59
57
/**
60
58
* Test fixture for {@link SendToMethodReturnValueHandlerTests}.
@@ -103,31 +101,31 @@ public void setup() throws Exception {
103
101
jsonMessagingTemplate .setMessageConverter (new MappingJackson2MessageConverter ());
104
102
this .jsonHandler = new SendToMethodReturnValueHandler (jsonMessagingTemplate , true );
105
103
106
- Method method = this . getClass ().getDeclaredMethod ("handleNoAnnotations" );
104
+ Method method = getClass ().getDeclaredMethod ("handleNoAnnotations" );
107
105
this .noAnnotationsReturnType = new SynthesizingMethodParameter (method , -1 );
108
106
109
- method = this . getClass ().getDeclaredMethod ("handleAndSendToDefaultDestination" );
107
+ method = getClass ().getDeclaredMethod ("handleAndSendToDefaultDestination" );
110
108
this .sendToDefaultDestReturnType = new SynthesizingMethodParameter (method , -1 );
111
109
112
- method = this . getClass ().getDeclaredMethod ("handleAndSendTo" );
110
+ method = getClass ().getDeclaredMethod ("handleAndSendTo" );
113
111
this .sendToReturnType = new SynthesizingMethodParameter (method , -1 );
114
112
115
- method = this . getClass ().getDeclaredMethod ("handleAndSendToWithPlaceholders" );
113
+ method = getClass ().getDeclaredMethod ("handleAndSendToWithPlaceholders" );
116
114
this .sendToWithPlaceholdersReturnType = new SynthesizingMethodParameter (method , -1 );
117
115
118
- method = this . getClass ().getDeclaredMethod ("handleAndSendToUser" );
116
+ method = getClass ().getDeclaredMethod ("handleAndSendToUser" );
119
117
this .sendToUserReturnType = new SynthesizingMethodParameter (method , -1 );
120
118
121
- method = this . getClass ().getDeclaredMethod ("handleAndSendToUserSingleSession" );
119
+ method = getClass ().getDeclaredMethod ("handleAndSendToUserSingleSession" );
122
120
this .sendToUserSingleSessionReturnType = new SynthesizingMethodParameter (method , -1 );
123
121
124
- method = this . getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestination" );
122
+ method = getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestination" );
125
123
this .sendToUserDefaultDestReturnType = new SynthesizingMethodParameter (method , -1 );
126
124
127
- method = this . getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestinationSingleSession" );
125
+ method = getClass ().getDeclaredMethod ("handleAndSendToUserDefaultDestinationSingleSession" );
128
126
this .sendToUserSingleSessionDefaultDestReturnType = new SynthesizingMethodParameter (method , -1 );
129
127
130
- method = this . getClass ().getDeclaredMethod ("handleAndSendToJsonView" );
128
+ method = getClass ().getDeclaredMethod ("handleAndSendToJsonView" );
131
129
this .jsonViewReturnType = new SynthesizingMethodParameter (method , -1 );
132
130
}
133
131
@@ -226,7 +224,8 @@ public void testHeadersToSend() throws Exception {
226
224
verify (messagingTemplate ).convertAndSend (eq ("/topic/dest" ), eq (PAYLOAD ), captor .capture ());
227
225
228
226
MessageHeaders messageHeaders = captor .getValue ();
229
- SimpMessageHeaderAccessor accessor = getAccessor (messageHeaders , SimpMessageHeaderAccessor .class );
227
+ SimpMessageHeaderAccessor accessor =
228
+ MessageHeaderAccessor .getAccessor (messageHeaders , SimpMessageHeaderAccessor .class );
230
229
assertNotNull (accessor );
231
230
assertTrue (accessor .isMutable ());
232
231
assertEquals ("sess1" , accessor .getSessionId ());
@@ -267,7 +266,7 @@ public void sendToWithDestinationPlaceholders() throws Exception {
267
266
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor .create ();
268
267
accessor .setSessionId (sessionId );
269
268
accessor .setSubscriptionId ("sub1" );
270
- accessor .setHeader (DESTINATION_TEMPLATE_VARIABLES_HEADER , vars );
269
+ accessor .setHeader (DestinationVariableMethodArgumentResolver . DESTINATION_TEMPLATE_VARIABLES_HEADER , vars );
271
270
Message <?> message = MessageBuilder .createMessage (PAYLOAD , accessor .getMessageHeaders ());
272
271
this .handler .handleReturnValue (PAYLOAD , this .sendToWithPlaceholdersReturnType , message );
273
272
@@ -403,7 +402,7 @@ public void jsonView() throws Exception {
403
402
Message <?> message = this .messageCaptor .getValue ();
404
403
assertNotNull (message );
405
404
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" ) ));
407
406
}
408
407
409
408
@@ -429,25 +428,6 @@ private SimpMessageHeaderAccessor getCapturedAccessor(int index) {
429
428
}
430
429
431
430
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
-
451
431
public String handleNoAnnotations () {
452
432
return PAYLOAD ;
453
433
}
@@ -498,9 +478,32 @@ public JacksonViewBean handleAndSendToJsonView() {
498
478
}
499
479
500
480
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
+
501
502
private interface MyJacksonView1 {}
503
+
502
504
private interface MyJacksonView2 {}
503
505
506
+
504
507
@ SuppressWarnings ("unused" )
505
508
private static class JacksonViewBean {
506
509
@@ -516,23 +519,23 @@ public String getWithView1() {
516
519
return withView1 ;
517
520
}
518
521
519
- public void setWithView1 (String withView1 ) {
522
+ void setWithView1 (String withView1 ) {
520
523
this .withView1 = withView1 ;
521
524
}
522
525
523
- public String getWithView2 () {
526
+ String getWithView2 () {
524
527
return withView2 ;
525
528
}
526
529
527
- public void setWithView2 (String withView2 ) {
530
+ void setWithView2 (String withView2 ) {
528
531
this .withView2 = withView2 ;
529
532
}
530
533
531
- public String getWithoutView () {
534
+ String getWithoutView () {
532
535
return withoutView ;
533
536
}
534
537
535
- public void setWithoutView (String withoutView ) {
538
+ void setWithoutView (String withoutView ) {
536
539
this .withoutView = withoutView ;
537
540
}
538
541
}
0 commit comments