2929import org .springframework .amqp .rabbit .junit .RabbitAvailable ;
3030import org .springframework .amqp .rabbit .junit .RabbitAvailableCondition ;
3131import org .springframework .amqp .rabbit .support .ListenerExecutionFailedException ;
32+ import org .springframework .context .ApplicationContext ;
33+ import org .springframework .context .event .ContextClosedEvent ;
3234
3335import static org .assertj .core .api .Assertions .assertThat ;
36+ import static org .mockito .Mockito .mock ;
3437
3538/**
3639 * @author Gary Russell
40+ * @author Artem Bilan
41+ *
3742 * @since 2.0.5
3843 *
3944 */
@@ -52,6 +57,8 @@ class RepublishMessageRecovererIntegrationTests {
5257 void testBigHeader () {
5358 CachingConnectionFactory ccf = new CachingConnectionFactory (
5459 RabbitAvailableCondition .getBrokerRunning ().getConnectionFactory ());
60+ ApplicationContext applicationContext = mock ();
61+ ccf .setApplicationContext (applicationContext );
5562 RabbitTemplate template = new RabbitTemplate (ccf );
5663 this .maxHeaderSize = RabbitUtils .getMaxFrame (template .getConnectionFactory ())
5764 - RepublishMessageRecoverer .DEFAULT_FRAME_MAX_HEADROOM ;
@@ -69,14 +76,17 @@ void testBigHeader() {
6976 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx..." ;
7077 assertThat (trace ).contains (truncatedMessage );
7178 assertThat ((String ) received .getMessageProperties ().getHeader (RepublishMessageRecoverer .X_EXCEPTION_MESSAGE ))
72- .isEqualTo (truncatedMessage );
79+ .isEqualTo (truncatedMessage );
80+ ccf .onApplicationEvent (new ContextClosedEvent (applicationContext ));
7381 ccf .destroy ();
7482 }
7583
7684 @ Test
7785 void testSmallException () {
7886 CachingConnectionFactory ccf = new CachingConnectionFactory (
7987 RabbitAvailableCondition .getBrokerRunning ().getConnectionFactory ());
88+ ApplicationContext applicationContext = mock ();
89+ ccf .setApplicationContext (applicationContext );
8090 RabbitTemplate template = new RabbitTemplate (ccf );
8191 this .maxHeaderSize = RabbitUtils .getMaxFrame (template .getConnectionFactory ())
8292 - RepublishMessageRecoverer .DEFAULT_FRAME_MAX_HEADROOM ;
@@ -91,6 +101,7 @@ void testSmallException() {
91101 String trace = received .getMessageProperties ().getHeaders ()
92102 .get (RepublishMessageRecoverer .X_EXCEPTION_STACKTRACE ).toString ();
93103 assertThat (trace ).isEqualTo (getStackTraceAsString (cause ));
104+ ccf .onApplicationEvent (new ContextClosedEvent (applicationContext ));
94105 ccf .destroy ();
95106 }
96107
@@ -99,6 +110,8 @@ void testBigMessageSmallTrace() {
99110 CachingConnectionFactory ccf = new CachingConnectionFactory (
100111 RabbitAvailableCondition .getBrokerRunning ().getConnectionFactory ());
101112 RabbitTemplate template = new RabbitTemplate (ccf );
113+ ApplicationContext applicationContext = mock ();
114+ ccf .setApplicationContext (applicationContext );
102115 this .maxHeaderSize = RabbitUtils .getMaxFrame (template .getConnectionFactory ())
103116 - RepublishMessageRecoverer .DEFAULT_FRAME_MAX_HEADROOM ;
104117 assertThat (this .maxHeaderSize ).isGreaterThan (0 );
@@ -117,6 +130,7 @@ void testBigMessageSmallTrace() {
117130 .getHeader (RepublishMessageRecoverer .X_EXCEPTION_MESSAGE ).toString ();
118131 assertThat (trace .length () + exceptionMessage .length ()).isEqualTo (this .maxHeaderSize );
119132 assertThat (exceptionMessage ).endsWith ("..." );
133+ ccf .onApplicationEvent (new ContextClosedEvent (applicationContext ));
120134 ccf .destroy ();
121135 }
122136
0 commit comments