1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2024 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.
16
16
17
17
package org .springframework .integration .endpoint ;
18
18
19
- import org .junit .Test ;
19
+ import org .junit .jupiter . api . Test ;
20
20
21
- import org .springframework .context .support .ClassPathXmlApplicationContext ;
21
+ import org .springframework .beans .factory .annotation .Autowired ;
22
+ import org .springframework .context .ApplicationContext ;
22
23
import org .springframework .integration .support .MessageBuilder ;
23
24
import org .springframework .messaging .Message ;
24
25
import org .springframework .messaging .MessageChannel ;
25
26
import org .springframework .messaging .MessagingException ;
26
27
import org .springframework .messaging .PollableChannel ;
27
28
import org .springframework .messaging .core .DestinationResolutionException ;
28
29
import org .springframework .messaging .support .GenericMessage ;
30
+ import org .springframework .test .annotation .DirtiesContext ;
31
+ import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
29
32
30
33
import static org .assertj .core .api .Assertions .assertThat ;
34
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
31
35
32
36
/**
33
37
* @author Mark Fisher
34
38
* @author Gary Russell
39
+ * @author Artem Bilan
35
40
*/
41
+ @ SpringJUnitConfig
42
+ @ DirtiesContext
36
43
public class ReturnAddressTests {
37
44
45
+ @ Autowired
46
+ ApplicationContext context ;
47
+
38
48
@ Test
39
49
public void returnAddressFallbackWithChannelReference () {
40
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
41
- "returnAddressTests.xml" , this .getClass ());
42
50
MessageChannel channel3 = (MessageChannel ) context .getBean ("channel3" );
43
51
PollableChannel channel5 = (PollableChannel ) context .getBean ("channel5" );
44
- context .start ();
45
52
Message <String > message = MessageBuilder .withPayload ("*" )
46
53
.setReplyChannel (channel5 ).build ();
47
54
channel3 .send (message );
48
55
Message <?> response = channel5 .receive (3000 );
49
56
assertThat (response ).isNotNull ();
50
57
assertThat (response .getPayload ()).isEqualTo ("**" );
51
- context .close ();
52
58
}
53
59
54
60
@ Test
55
61
public void returnAddressFallbackWithChannelName () {
56
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
57
- "returnAddressTests.xml" , this .getClass ());
58
62
MessageChannel channel3 = (MessageChannel ) context .getBean ("channel3" );
59
63
PollableChannel channel5 = (PollableChannel ) context .getBean ("channel5" );
60
- context .start ();
61
64
Message <String > message = MessageBuilder .withPayload ("*" )
62
65
.setReplyChannelName ("channel5" ).build ();
63
66
channel3 .send (message );
64
67
Message <?> response = channel5 .receive (3000 );
65
68
assertThat (response ).isNotNull ();
66
69
assertThat (response .getPayload ()).isEqualTo ("**" );
67
- context .close ();
68
70
}
69
71
70
72
@ Test
71
73
public void returnAddressWithChannelReferenceAfterMultipleEndpoints () {
72
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
73
- "returnAddressTests.xml" , this .getClass ());
74
74
MessageChannel channel1 = (MessageChannel ) context .getBean ("channel1" );
75
75
PollableChannel replyChannel = (PollableChannel ) context .getBean ("replyChannel" );
76
- context .start ();
77
76
Message <String > message = MessageBuilder .withPayload ("*" )
78
77
.setReplyChannel (replyChannel ).build ();
79
78
channel1 .send (message );
@@ -82,16 +81,12 @@ public void returnAddressWithChannelReferenceAfterMultipleEndpoints() {
82
81
assertThat (response .getPayload ()).isEqualTo ("********" );
83
82
PollableChannel channel2 = (PollableChannel ) context .getBean ("channel2" );
84
83
assertThat (channel2 .receive (0 )).isNull ();
85
- context .close ();
86
84
}
87
85
88
86
@ Test
89
87
public void returnAddressWithChannelNameAfterMultipleEndpoints () {
90
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
91
- "returnAddressTests.xml" , this .getClass ());
92
88
MessageChannel channel1 = (MessageChannel ) context .getBean ("channel1" );
93
89
PollableChannel replyChannel = (PollableChannel ) context .getBean ("replyChannel" );
94
- context .start ();
95
90
Message <String > message = MessageBuilder .withPayload ("*" )
96
91
.setReplyChannelName ("replyChannel" ).build ();
97
92
channel1 .send (message );
@@ -100,47 +95,32 @@ public void returnAddressWithChannelNameAfterMultipleEndpoints() {
100
95
assertThat (response .getPayload ()).isEqualTo ("********" );
101
96
PollableChannel channel2 = (PollableChannel ) context .getBean ("channel2" );
102
97
assertThat (channel2 .receive (0 )).isNull ();
103
- context .close ();
104
98
}
105
99
106
100
@ Test
107
101
public void returnAddressFallbackButNotAvailable () {
108
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
109
- "returnAddressTests.xml" , this .getClass ());
110
102
MessageChannel channel3 = (MessageChannel ) context .getBean ("channel3" );
111
- context .start ();
112
- GenericMessage <String > message = new GenericMessage <String >("*" );
113
- try {
114
- channel3 .send (message );
115
- }
116
- catch (MessagingException e ) {
117
- assertThat (e .getCause () instanceof DestinationResolutionException ).isTrue ();
118
- }
119
- context .close ();
103
+ GenericMessage <String > message = new GenericMessage <>("*" );
104
+ assertThatExceptionOfType (MessagingException .class )
105
+ .isThrownBy (() -> channel3 .send (message ))
106
+ .withCauseInstanceOf (DestinationResolutionException .class );
120
107
}
121
108
122
109
@ Test
123
110
public void outputChannelWithNoReturnAddress () {
124
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
125
- "returnAddressTests.xml" , this .getClass ());
126
111
MessageChannel channel4 = (MessageChannel ) context .getBean ("channel4" );
127
112
PollableChannel replyChannel = (PollableChannel ) context .getBean ("replyChannel" );
128
- context .start ();
129
- GenericMessage <String > message = new GenericMessage <String >("*" );
113
+ GenericMessage <String > message = new GenericMessage <>("*" );
130
114
channel4 .send (message );
131
115
Message <?> response = replyChannel .receive (3000 );
132
116
assertThat (response ).isNotNull ();
133
117
assertThat (response .getPayload ()).isEqualTo ("**" );
134
- context .close ();
135
118
}
136
119
137
120
@ Test
138
121
public void outputChannelTakesPrecedence () {
139
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext (
140
- "returnAddressTests.xml" , this .getClass ());
141
122
MessageChannel channel4 = (MessageChannel ) context .getBean ("channel4" );
142
123
PollableChannel replyChannel = (PollableChannel ) context .getBean ("replyChannel" );
143
- context .start ();
144
124
Message <String > message = MessageBuilder .withPayload ("*" )
145
125
.setReplyChannelName ("channel5" ).build ();
146
126
channel4 .send (message );
@@ -149,7 +129,6 @@ public void outputChannelTakesPrecedence() {
149
129
assertThat (response .getPayload ()).isEqualTo ("**" );
150
130
PollableChannel channel5 = (PollableChannel ) context .getBean ("channel5" );
151
131
assertThat (channel5 .receive (0 )).isNull ();
152
- context .close ();
153
132
}
154
133
155
134
}
0 commit comments