29
29
import org .springframework .amqp .rabbit .junit .RabbitAvailable ;
30
30
import org .springframework .amqp .rabbit .junit .RabbitAvailableCondition ;
31
31
import org .springframework .amqp .rabbit .support .ListenerExecutionFailedException ;
32
+ import org .springframework .context .ApplicationContext ;
33
+ import org .springframework .context .event .ContextClosedEvent ;
32
34
33
35
import static org .assertj .core .api .Assertions .assertThat ;
36
+ import static org .mockito .Mockito .mock ;
34
37
35
38
/**
36
39
* @author Gary Russell
40
+ * @author Artem Bilan
41
+ *
37
42
* @since 2.0.5
38
43
*
39
44
*/
@@ -52,6 +57,8 @@ class RepublishMessageRecovererIntegrationTests {
52
57
void testBigHeader () {
53
58
CachingConnectionFactory ccf = new CachingConnectionFactory (
54
59
RabbitAvailableCondition .getBrokerRunning ().getConnectionFactory ());
60
+ ApplicationContext applicationContext = mock ();
61
+ ccf .setApplicationContext (applicationContext );
55
62
RabbitTemplate template = new RabbitTemplate (ccf );
56
63
this .maxHeaderSize = RabbitUtils .getMaxFrame (template .getConnectionFactory ())
57
64
- RepublishMessageRecoverer .DEFAULT_FRAME_MAX_HEADROOM ;
@@ -69,14 +76,17 @@ void testBigHeader() {
69
76
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx..." ;
70
77
assertThat (trace ).contains (truncatedMessage );
71
78
assertThat ((String ) received .getMessageProperties ().getHeader (RepublishMessageRecoverer .X_EXCEPTION_MESSAGE ))
72
- .isEqualTo (truncatedMessage );
79
+ .isEqualTo (truncatedMessage );
80
+ ccf .onApplicationEvent (new ContextClosedEvent (applicationContext ));
73
81
ccf .destroy ();
74
82
}
75
83
76
84
@ Test
77
85
void testSmallException () {
78
86
CachingConnectionFactory ccf = new CachingConnectionFactory (
79
87
RabbitAvailableCondition .getBrokerRunning ().getConnectionFactory ());
88
+ ApplicationContext applicationContext = mock ();
89
+ ccf .setApplicationContext (applicationContext );
80
90
RabbitTemplate template = new RabbitTemplate (ccf );
81
91
this .maxHeaderSize = RabbitUtils .getMaxFrame (template .getConnectionFactory ())
82
92
- RepublishMessageRecoverer .DEFAULT_FRAME_MAX_HEADROOM ;
@@ -91,6 +101,7 @@ void testSmallException() {
91
101
String trace = received .getMessageProperties ().getHeaders ()
92
102
.get (RepublishMessageRecoverer .X_EXCEPTION_STACKTRACE ).toString ();
93
103
assertThat (trace ).isEqualTo (getStackTraceAsString (cause ));
104
+ ccf .onApplicationEvent (new ContextClosedEvent (applicationContext ));
94
105
ccf .destroy ();
95
106
}
96
107
@@ -99,6 +110,8 @@ void testBigMessageSmallTrace() {
99
110
CachingConnectionFactory ccf = new CachingConnectionFactory (
100
111
RabbitAvailableCondition .getBrokerRunning ().getConnectionFactory ());
101
112
RabbitTemplate template = new RabbitTemplate (ccf );
113
+ ApplicationContext applicationContext = mock ();
114
+ ccf .setApplicationContext (applicationContext );
102
115
this .maxHeaderSize = RabbitUtils .getMaxFrame (template .getConnectionFactory ())
103
116
- RepublishMessageRecoverer .DEFAULT_FRAME_MAX_HEADROOM ;
104
117
assertThat (this .maxHeaderSize ).isGreaterThan (0 );
@@ -117,6 +130,7 @@ void testBigMessageSmallTrace() {
117
130
.getHeader (RepublishMessageRecoverer .X_EXCEPTION_MESSAGE ).toString ();
118
131
assertThat (trace .length () + exceptionMessage .length ()).isEqualTo (this .maxHeaderSize );
119
132
assertThat (exceptionMessage ).endsWith ("..." );
133
+ ccf .onApplicationEvent (new ContextClosedEvent (applicationContext ));
120
134
ccf .destroy ();
121
135
}
122
136
0 commit comments