3434import org .easymock .internal .AlwaysMatcher ;
3535import org .junit .Before ;
3636import org .junit .Test ;
37+
38+ import org .springframework .context .event .ContextRefreshedEvent ;
39+ import org .springframework .context .support .StaticApplicationContext ;
3740import org .springframework .core .task .TaskExecutor ;
3841import org .springframework .jms .StubQueue ;
3942import org .springframework .util .ErrorHandler ;
@@ -87,7 +90,7 @@ public void testSettingConcurrentConsumersToANegativeValueIsNotAllowed() throws
8790 }
8891
8992 @ Test
90- public void testInitDoesNotStartTheConnectionIfAutoStartIsSetToFalse () throws Exception {
93+ public void testContextRefreshedEventDoesNotStartTheConnectionIfAutoStartIsSetToFalse () throws Exception {
9194 MockControl mockMessageConsumer = MockControl .createControl (MessageConsumer .class );
9295 MessageConsumer messageConsumer = (MessageConsumer ) mockMessageConsumer .getMock ();
9396 messageConsumer .setMessageListener (null );
@@ -127,6 +130,7 @@ public void testInitDoesNotStartTheConnectionIfAutoStartIsSetToFalse() throws Ex
127130 this .container .setMessageListener (new TestMessageListener ());
128131 this .container .setAutoStartup (false );
129132 this .container .afterPropertiesSet ();
133+ this .container .onApplicationEvent (new ContextRefreshedEvent (new StaticApplicationContext ()));
130134
131135 mockMessageConsumer .verify ();
132136 mockSession .verify ();
@@ -135,7 +139,7 @@ public void testInitDoesNotStartTheConnectionIfAutoStartIsSetToFalse() throws Ex
135139 }
136140
137141 @ Test
138- public void testInitStartsTheConnectionByDefault () throws Exception {
142+ public void testContextRefreshedEventStartsTheConnectionByDefault () throws Exception {
139143 MockControl mockMessageConsumer = MockControl .createControl (MessageConsumer .class );
140144 MessageConsumer messageConsumer = (MessageConsumer ) mockMessageConsumer .getMock ();
141145 messageConsumer .setMessageListener (null );
@@ -177,6 +181,7 @@ public void testInitStartsTheConnectionByDefault() throws Exception {
177181
178182 this .container .setMessageListener (new TestMessageListener ());
179183 this .container .afterPropertiesSet ();
184+ this .container .onApplicationEvent (new ContextRefreshedEvent (new StaticApplicationContext ()));
180185
181186 mockMessageConsumer .verify ();
182187 mockSession .verify ();
@@ -238,6 +243,7 @@ public void onMessage(Message message, Session sess) {
238243 });
239244
240245 this .container .afterPropertiesSet ();
246+ this .container .start ();
241247
242248 MockControl mockMessage = MockControl .createControl (Message .class );
243249 final Message message = (Message ) mockMessage .getMock ();
@@ -300,6 +306,7 @@ public void execute(Runnable task) {
300306 }
301307 });
302308 this .container .afterPropertiesSet ();
309+ this .container .start ();
303310
304311 MockControl mockMessage = MockControl .createControl (Message .class );
305312 final Message message = (Message ) mockMessage .getMock ();
@@ -367,6 +374,7 @@ public void onMessage(Message message, Session session) throws JMSException {
367374
368375 this .container .setExceptionListener (exceptionListener );
369376 this .container .afterPropertiesSet ();
377+ this .container .start ();
370378
371379 // manually trigger an Exception with the above bad MessageListener...
372380 MockControl mockMessage = MockControl .createControl (Message .class );
@@ -430,6 +438,7 @@ public void onMessage(Message message, Session session) throws JMSException {
430438 EasyMock .replay (errorHandler );
431439 this .container .setErrorHandler (errorHandler );
432440 this .container .afterPropertiesSet ();
441+ this .container .start ();
433442
434443 // manually trigger an Exception with the above bad MessageListener...
435444 Message message = EasyMock .createMock (Message .class );
@@ -484,6 +493,7 @@ public void onMessage(Message message) {
484493 }
485494 });
486495 this .container .afterPropertiesSet ();
496+ this .container .start ();
487497
488498 // manually trigger an Exception with the above bad MessageListener...
489499 MockControl mockMessage = MockControl .createControl (Message .class );
@@ -547,6 +557,7 @@ public void onMessage(Message message) {
547557 }
548558 });
549559 this .container .afterPropertiesSet ();
560+ this .container .start ();
550561
551562 // manually trigger an Exception with the above bad MessageListener...
552563 MockControl mockMessage = MockControl .createControl (Message .class );
@@ -614,6 +625,7 @@ public void testDestroyClosesConsumersSessionsAndConnectionInThatOrder() throws
614625
615626 this .container .setMessageListener (new TestMessageListener ());
616627 this .container .afterPropertiesSet ();
628+ this .container .start ();
617629 this .container .destroy ();
618630
619631 mockMessageConsumer .verify ();
0 commit comments