25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16 ■ Messaging with Your <strong>Spring</strong> Application<br />

@Autowired<br />

RabbitMQProducer rabbitmqProducer;<br />

@Autowired<br />

DocumentService documentFacade;<br />

@Test<br />

public void testProducer(){<br />

log.debug("Testing RabbitMQ Producer...");<br />

assertNotNull(rabbitmqProducer);<br />

assertNotNull(documentFacade);<br />

for(Document document : documentFacade.getAllDocuments())<br />

rabbitmqProducer.send(document);<br />

}<br />

}<br />

@Test<br />

public void testJustWait() throws InterruptedException{<br />

Thread.sleep(5000);<br />

}<br />

Listing 16-11 shows the unit test. You are using the same DocumentServiceFacade to pull some documents from<br />

the HSQLDB in-memory database; just send them through the RabbitMQProducer class. Also, you can get documents<br />

from the MongoDB server (by using the mongoDocumentDAO) and as you can see by the @ContextConfiguration<br />

annotation, you can add more XML configurations. Another way is to include or import more bean definitions.<br />

And of course, you need to remember that the RabbitMQ server needs to be up and running, so you can run the<br />

unit test (see Listing 16-11 and the “Install RabbitMQ” section in Appendix A).<br />

To run the test, use<br />

gradle :ch16:test<br />

While running the test, you should see the console and see that your mydocuments exchange and the docs-pdf,<br />

docs-txt, and docs-web queues were created as shown in Figures 16-2 and 16-3.<br />

227

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!