Skip to Main Content
Spring: A Developer's Notebook
book

Spring: A Developer's Notebook

by Bruce Tate, Justin Gehtland
April 2005
Intermediate to advanced content levelIntermediate to advanced
216 pages
4h 44m
English
O'Reilly Media, Inc.
Content preview from Spring: A Developer's Notebook

Testing JMS Applications

Distributed applications are hard to test. It's especially hard to test applications that might have remote behaviors. The good news is that with Spring, you don't have to actually invoke JMS to retrieve your messages. In this example, you'll learn how to create a stream of messages in the context that can save you the headache of actually creating the JMS infrastructure in every test case.

How do I do that?

You're going to create a series of messages in the Spring context. Your applications will draw these messages from an array list, instead of actually going across the wire and physically retrieving a JMS message. True, you won't be testing JMS, but you will be able to test the elements of your application that depend on JMS. You'll need to do the following:

  • Implement the interface that you use to deal with JMS. In our case, we'll subclass the façade.

  • In the new test implementation, draw messages from an array list, rather than from JMS.

  • Populate this array list data within the Spring context.

First, let's create a subclass of the façade, for test purposes only (Example 8-16). You'll need to modify the JMS method on the façade. Draw your messages from an array list.

Example 8-16. JMSTestRentABike.java

private List testBikes; public List getTestBikes( ) { return testBikes; } public void setTestBikes(List testBikes) { this.testBikes = testBikes; } int curBike = 0; public Bike getNewBikeFromQueue( ) { try { ActiveMQTextMessage m = (ActiveMQTextMessage)testBikes.get(curBike); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaBeans Unleashed

JavaBeans Unleashed

Dr. Donald Doherty, Rick Leinecker
Beginning Spring

Beginning Spring

Mert Caliskan, Kenan Sevindik, Rod Johnson, Jürgen Höller
Hibernate Search in Action

Hibernate Search in Action

Emmanuel Bernard, John Griffin

Publisher Resources

ISBN: 0596009100Supplemental ContentErrata Page