Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
JW Blogs: The cult of Spring
Obviously when you're up and coming, you gun for those already on top. Nonetheless, JW blogger Josh Fruhlinger is charmed
by Web4J creator John O'Hanley's recent comments about the Spring framework, which he notes "has met with a disturbing lack of criticism ..."
| Agile Development: Five Steps to Continuous Integration |
| SOA redefined: Simple. Open. Affordable. |
| The Four Requirements of Next Generation Web Performance Management |
Enterprise JavaBeans (EJB) has become increasingly less popular among J2EE developers in the last couple of years. Many factors contribute to this poor reputation, but high on the list is the fact that EJB components are inherently difficult to test.
The EJB 3.0 Expert Group recognizes that testing EJB applications proves difficult, and the upcoming specification is expected to address the issue. However, at the time of this writing, EJB 3.0 is still in early draft review (see Resources). The specification's finalization and widespread implementation by vendors is still many months away.
In a typical current EJB application, business logic hides behind session-bean facades. For performance reasons, a large portion of the code running on the EJB container is exposed only via EJB local interfaces, which are inaccessible to a suite of JUnit tests running on a separate JVM. In the case of container-managed persistence (CMP) entity beans, much of this code also relies on container-provided services, making it virtually impossible to run outside the EJB container. For example, the EJB CMP bean classes that the application developer writes are themselves abstract classes, the concrete implementations of which are provided by the container. In short, creating a suite of comprehensive unit tests for an EJB-based application creates a real headache for any proponent of test-driven development (TDD).
Two approaches tackle this problem. First is the use of mock objects, which involves a dummy implementation of the EJB API, that can run outside the EJB container. An example is MockEJB. The second approach involves the use of an in-container testing framework such as Cactus, from the Apache Jakarta Project. Here, the idea is to deploy the test code onto the container and run the tests in the application's real execution environment.
In this article, I present a framework that follows the in-container test approach, but has the advantage of being simple to understand and use. It involves the following:
Before we discuss how the framework works, let's first consider our requirements for an EJB testing mechanism:
lib directory to enable the framework.
Let's now explore how our framework is implemented.
A key component in the framework is the interface ContainerTest, the test interface for which any implementation class constitutes a test case. The methods in the test class execute on
the EJB container, and are invoked by the UnitTester EJB, which I discuss shortly.
ContainerTest defines the following methods:
public void setUp(Object[] args) throws Exception;
public boolean doTransaction();
public void runTest(Map resultMap) throws Exception;
public void afterTransaction(Map resultMap) throws Exception;
public void tearDown(boolean succeeded) throws Exception;
The test interface models a JUnit test's lifecycle, with setUp() and tearDown() methods. These methods can be used to set up state before running the tests and revert state afterwards. Note that arguments
can be supplied to the setUp() method from the client in the form of an Object array, although this is optional.
| Subject | Replies |
Last post
|
|
By Samudra Gupta |
2 |
05/16/08 06:28 AM
by Anonymous |
|
By |
0 |
10/14/07 09:43 AM
by Anonymous |
|
By JavaWorld |
1 |
05/24/07 12:15 AM
by Anonymous |
|
By nicolas frank |
1 |
03/02/06 05:44 PM
by Anonymous |
Free Download - 5 Minute Product Review. When slow equals Off: Manage the complexity of Web applications - Symphoniq
![]()
Free Download - 5 Minute Product Review. Realize the benefits of real user monitoring in less than an hour. - Symphoniq