1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 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.
27
27
import org .junit .Test ;
28
28
29
29
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
30
+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
31
+ import org .springframework .context .annotation .Bean ;
30
32
import org .springframework .integration .MessageRejectedException ;
31
33
import org .springframework .integration .channel .QueueChannel ;
32
34
import org .springframework .integration .test .util .TestUtils ;
33
35
import org .springframework .messaging .Message ;
34
36
import org .springframework .messaging .MessageDeliveryException ;
35
37
import org .springframework .messaging .MessageHandlingException ;
38
+ import org .springframework .messaging .PollableChannel ;
36
39
import org .springframework .messaging .support .ErrorMessage ;
37
40
import org .springframework .messaging .support .GenericMessage ;
38
41
43
46
*/
44
47
public class ErrorMessageExceptionTypeRouterTests {
45
48
46
- private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory ();
49
+ private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory ();
47
50
48
- private QueueChannel illegalArgumentChannel = new QueueChannel ();
51
+ private final QueueChannel illegalArgumentChannel = new QueueChannel ();
49
52
50
- private QueueChannel runtimeExceptionChannel = new QueueChannel ();
53
+ private final QueueChannel runtimeExceptionChannel = new QueueChannel ();
51
54
52
- private QueueChannel messageHandlingExceptionChannel = new QueueChannel ();
55
+ private final QueueChannel messageHandlingExceptionChannel = new QueueChannel ();
53
56
54
- private QueueChannel messageDeliveryExceptionChannel = new QueueChannel ();
57
+ private final QueueChannel messageDeliveryExceptionChannel = new QueueChannel ();
55
58
56
- private QueueChannel defaultChannel = new QueueChannel ();
59
+ private final QueueChannel defaultChannel = new QueueChannel ();
57
60
58
61
@ Before
59
62
public void prepare () {
@@ -79,6 +82,7 @@ public void mostSpecificCause() {
79
82
router .setChannelMapping (RuntimeException .class .getName (), "runtimeExceptionChannel" );
80
83
router .setChannelMapping (MessageHandlingException .class .getName (), "messageHandlingExceptionChannel" );
81
84
router .setDefaultOutputChannel (defaultChannel );
85
+ router .afterPropertiesSet ();
82
86
83
87
router .handleMessage (message );
84
88
@@ -101,6 +105,7 @@ public void fallbackToNextMostSpecificCause() {
101
105
router .setChannelMapping (RuntimeException .class .getName (), "runtimeExceptionChannel" );
102
106
router .setChannelMapping (MessageHandlingException .class .getName (), "runtimeExceptionChannel" );
103
107
router .setDefaultOutputChannel (defaultChannel );
108
+ router .afterPropertiesSet ();
104
109
105
110
router .handleMessage (message );
106
111
@@ -122,6 +127,7 @@ public void fallbackToErrorMessageType() {
122
127
router .setApplicationContext (TestUtils .createTestApplicationContext ());
123
128
router .setChannelMapping (MessageHandlingException .class .getName (), "messageHandlingExceptionChannel" );
124
129
router .setDefaultOutputChannel (defaultChannel );
130
+ router .afterPropertiesSet ();
125
131
126
132
router .handleMessage (message );
127
133
@@ -141,6 +147,7 @@ public void fallbackToDefaultChannel() {
141
147
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter ();
142
148
router .setApplicationContext (TestUtils .createTestApplicationContext ());
143
149
router .setDefaultOutputChannel (defaultChannel );
150
+ router .afterPropertiesSet ();
144
151
145
152
router .handleMessage (message );
146
153
@@ -163,6 +170,7 @@ public void noMatchAndNoDefaultChannel() {
163
170
router .setChannelMapping (MessageDeliveryException .class .getName (), "messageDeliveryExceptionChannel" );
164
171
router .setResolutionRequired (true );
165
172
router .setBeanName ("fooRouter" );
173
+ router .afterPropertiesSet ();
166
174
167
175
try {
168
176
router .handleMessage (message );
@@ -188,6 +196,7 @@ public void exceptionPayloadButNotErrorMessage() {
188
196
router .setChannelMapping (RuntimeException .class .getName (), "runtimeExceptionChannel" );
189
197
router .setChannelMapping (MessageHandlingException .class .getName (), "messageHandlingExceptionChannel" );
190
198
router .setDefaultOutputChannel (defaultChannel );
199
+ router .afterPropertiesSet ();
191
200
192
201
router .handleMessage (message );
193
202
@@ -210,6 +219,7 @@ public void intermediateCauseHasNoMappingButMostSpecificCauseDoes() {
210
219
router .setChannelMapping (IllegalArgumentException .class .getName (), "illegalArgumentChannel" );
211
220
router .setChannelMapping (MessageHandlingException .class .getName (), "messageHandlingExceptionChannel" );
212
221
router .setDefaultOutputChannel (defaultChannel );
222
+ router .afterPropertiesSet ();
213
223
214
224
router .handleMessage (message );
215
225
@@ -229,6 +239,7 @@ public void testHierarchicalMapping() {
229
239
router .setApplicationContext (TestUtils .createTestApplicationContext ());
230
240
router .setChannelMapping (MessageHandlingException .class .getName (), "messageHandlingExceptionChannel" );
231
241
router .setDefaultOutputChannel (defaultChannel );
242
+ router .afterPropertiesSet ();
232
243
233
244
router .handleMessage (message );
234
245
@@ -241,6 +252,7 @@ public void testInvalidMapping() {
241
252
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter ();
242
253
router .setBeanFactory (beanFactory );
243
254
router .setApplicationContext (TestUtils .createTestApplicationContext ());
255
+ router .afterPropertiesSet ();
244
256
try {
245
257
router .setChannelMapping ("foo" , "fooChannel" );
246
258
fail ("IllegalStateException expected" );
@@ -251,4 +263,28 @@ public void testInvalidMapping() {
251
263
}
252
264
}
253
265
266
+ @ Test
267
+ public void testLateClassBinding () {
268
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (Config .class );
269
+ ctx .getBean (ErrorMessageExceptionTypeRouter .class ).handleMessage (new GenericMessage <>(new NullPointerException ()));
270
+ assertNotNull (ctx .getBean ("channel" , PollableChannel .class ).receive (0 ));
271
+ ctx .close ();
272
+ }
273
+
274
+ public static class Config {
275
+
276
+ @ Bean
277
+ public ErrorMessageExceptionTypeRouter errorMessageExceptionTypeRouter () {
278
+ ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter ();
279
+ router .setChannelMapping (NullPointerException .class .getName (), "channel" );
280
+ return router ;
281
+ }
282
+
283
+ @ Bean
284
+ public PollableChannel channel () {
285
+ return new QueueChannel ();
286
+ }
287
+
288
+ }
289
+
254
290
}
0 commit comments