1
1
/*
2
- * Copyright 2010-2017 the original author or authors.
2
+ * Copyright 2010-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.
35
35
import org .junit .Test ;
36
36
37
37
import org .springframework .amqp .core .AcknowledgeMode ;
38
+ import org .springframework .amqp .core .MessagePostProcessor ;
38
39
import org .springframework .amqp .core .Queue ;
39
40
import org .springframework .amqp .rabbit .connection .ConnectionFactory ;
40
41
import org .springframework .amqp .rabbit .listener .DirectMessageListenerContainer ;
@@ -62,16 +63,17 @@ public class ListenerContainerParserTests {
62
63
private DefaultListableBeanFactory beanFactory ;
63
64
64
65
@ Before
65
- public void setUp () throws Exception {
66
+ public void setUp () {
66
67
beanFactory = new DefaultListableBeanFactory ();
67
68
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader (beanFactory );
68
69
reader .loadBeanDefinitions (new ClassPathResource (getClass ().getSimpleName () + "-context.xml" , getClass ()));
69
70
beanFactory .setBeanExpressionResolver (new StandardBeanExpressionResolver ());
70
71
}
71
72
72
73
@ Test
73
- public void testParseWithQueueNames () throws Exception {
74
- SimpleMessageListenerContainer container = beanFactory .getBean ("container1" , SimpleMessageListenerContainer .class );
74
+ public void testParseWithQueueNames () {
75
+ SimpleMessageListenerContainer container =
76
+ this .beanFactory .getBean ("container1" , SimpleMessageListenerContainer .class );
75
77
assertEquals (AcknowledgeMode .MANUAL , container .getAcknowledgeMode ());
76
78
assertEquals (beanFactory .getBean (ConnectionFactory .class ), container .getConnectionFactory ());
77
79
assertEquals (MessageListenerAdapter .class , container .getMessageListener ().getClass ());
@@ -111,7 +113,7 @@ public void testParseWithQueueNames() throws Exception {
111
113
}
112
114
113
115
@ Test
114
- public void testParseWithDirect () throws Exception {
116
+ public void testParseWithDirect () {
115
117
DirectMessageListenerContainer container = beanFactory .getBean ("direct1" , DirectMessageListenerContainer .class );
116
118
assertEquals (AcknowledgeMode .MANUAL , container .getAcknowledgeMode ());
117
119
assertEquals (beanFactory .getBean (ConnectionFactory .class ), container .getConnectionFactory ());
@@ -146,7 +148,7 @@ public void testParseWithDirect() throws Exception {
146
148
}
147
149
148
150
@ Test
149
- public void testParseWithQueues () throws Exception {
151
+ public void testParseWithQueues () {
150
152
SimpleMessageListenerContainer container = beanFactory .getBean ("container2" , SimpleMessageListenerContainer .class );
151
153
Queue queue = beanFactory .getBean ("bar" , Queue .class );
152
154
assertEquals ("[foo, " + queue .getName () + "]" , Arrays .asList (container .getQueueNames ()).toString ());
@@ -155,7 +157,7 @@ public void testParseWithQueues() throws Exception {
155
157
}
156
158
157
159
@ Test
158
- public void testParseWithAdviceChain () throws Exception {
160
+ public void testParseWithAdviceChain () {
159
161
SimpleMessageListenerContainer container = beanFactory .getBean ("container3" , SimpleMessageListenerContainer .class );
160
162
Object adviceChain = ReflectionTestUtils .getField (container , "adviceChain" );
161
163
assertNotNull (adviceChain );
@@ -164,35 +166,35 @@ public void testParseWithAdviceChain() throws Exception {
164
166
}
165
167
166
168
@ Test
167
- public void testParseWithDefaults () throws Exception {
169
+ public void testParseWithDefaults () {
168
170
SimpleMessageListenerContainer container = beanFactory .getBean ("container4" , SimpleMessageListenerContainer .class );
169
171
assertEquals (1 , ReflectionTestUtils .getField (container , "concurrentConsumers" ));
170
172
assertEquals (true , ReflectionTestUtils .getField (container , "defaultRequeueRejected" ));
171
173
}
172
174
173
175
@ Test
174
- public void testParseWithDefaultQueueRejectedFalse () throws Exception {
176
+ public void testParseWithDefaultQueueRejectedFalse () {
175
177
SimpleMessageListenerContainer container = beanFactory .getBean ("container5" , SimpleMessageListenerContainer .class );
176
178
assertEquals (1 , ReflectionTestUtils .getField (container , "concurrentConsumers" ));
177
179
assertEquals (false , ReflectionTestUtils .getField (container , "defaultRequeueRejected" ));
178
180
assertFalse (container .isChannelTransacted ());
179
181
}
180
182
181
183
@ Test
182
- public void testParseWithTx () throws Exception {
184
+ public void testParseWithTx () {
183
185
SimpleMessageListenerContainer container = beanFactory .getBean ("container6" , SimpleMessageListenerContainer .class );
184
186
assertTrue (container .isChannelTransacted ());
185
187
assertEquals (5 , ReflectionTestUtils .getField (container , "txSize" ));
186
188
}
187
189
188
190
@ Test
189
- public void testNamedListeners () throws Exception {
191
+ public void testNamedListeners () {
190
192
beanFactory .getBean ("testListener1" , SimpleMessageListenerContainer .class );
191
193
beanFactory .getBean ("testListener2" , SimpleMessageListenerContainer .class );
192
194
}
193
195
194
196
@ Test
195
- public void testAnonListeners () throws Exception {
197
+ public void testAnonListeners () {
196
198
beanFactory .getBean ("org.springframework.amqp.rabbit.config.ListenerContainerFactoryBean#0" ,
197
199
SimpleMessageListenerContainer .class );
198
200
beanFactory .getBean ("org.springframework.amqp.rabbit.config.ListenerContainerFactoryBean#1" ,
@@ -203,7 +205,7 @@ public void testAnonListeners() throws Exception {
203
205
}
204
206
205
207
@ Test
206
- public void testAnonEverything () throws Exception {
208
+ public void testAnonEverything () {
207
209
SimpleMessageListenerContainer container = beanFactory .getBean (
208
210
"org.springframework.amqp.rabbit.config.ListenerContainerFactoryBean#3" ,
209
211
SimpleMessageListenerContainer .class );
@@ -217,7 +219,7 @@ public void testAnonEverything() throws Exception {
217
219
}
218
220
219
221
@ Test
220
- public void testAnonParent () throws Exception {
222
+ public void testAnonParent () {
221
223
beanFactory .getBean ("anonParentL1" , SimpleMessageListenerContainer .class );
222
224
beanFactory .getBean ("anonParentL2" , SimpleMessageListenerContainer .class );
223
225
}
@@ -234,6 +236,21 @@ public void testIncompatibleTxAtts() {
234
236
}
235
237
}
236
238
239
+ @ Test
240
+ @ SuppressWarnings ("unchecked" )
241
+ public void testParseMessagePostProcessor () {
242
+ SimpleMessageListenerContainer listenerContainer =
243
+ this .beanFactory .getBean ("testMessagePostProcessor" , SimpleMessageListenerContainer .class );
244
+
245
+ Collection <MessagePostProcessor > messagePostProcessors =
246
+ TestUtils .getPropertyValue (listenerContainer , "afterReceivePostProcessors" , Collection .class );
247
+
248
+ assertFalse (messagePostProcessors .isEmpty ());
249
+ assertThat (messagePostProcessors ,
250
+ contains (this .beanFactory .getBean ("unzipPostProcessor" ),
251
+ this .beanFactory .getBean ("gUnzipPostProcessor" )));
252
+ }
253
+
237
254
static class TestBean {
238
255
239
256
public void handle (String s ) {
0 commit comments