Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Build, deploy, and test EJB components in just a few seconds

OpenEJB simplifies Enterprise JavaBeans development

  • Print
  • Feedback

Page 6 of 6

  1. Start OC4J
  2. Deploy your application to OC4J
  3. Run the test with the following command line arguments:

     -Djava.naming.factory.initial=
       com.evermind.server.ApplicationClientInitialContextFactory
    -Djava.naming.provider.url=ormi://localhost:23791/myapplication
    -Djava.naming.security.principal=admin
    -Djava.naming.security.credentials=password 
    


The above command line arguments specify that OC4J is the JNDI provider. Furthermore, it tells OC4J to expose the resources within the application myapplication.

OC4J provides two different classes as the JNDI provider:

  1. com.evermind.server.ApplicationClientInitialContextFactory
  2. com.evermind.server.rmi.RMIInitialContextFactory

For a discussion about which class to choose, see the chapter on JNDI from the Oracle9iAS Containers for J2EE Services Guide.

Here is how CarEjbTest is run for OC4J in Eclipse:

Figure 5. VM arguments are provided to a JUnit test that calls a remote OC4J server. Click on thumbnail to view full-sized image.

Discussion

OpenEJB's boot time is just a few seconds. You may recall that in the project I work on, we have 300 classes and 10 EJB components. In embedded mode, OpenEJB runs within the test's JVM. On our laptop, it takes almost three seconds for OpenEJB and the tests to start. There is no need to redeploy or empty the cache when the same test runs repeatedly.

To save even more time, you can use XStream to generate input data in XML for the tests. When testing, XStream simply saves you from punching the same input data repeatedly.

Frequently testing EJB components usually proves time-consuming. Several frameworks try to reduce the time it takes to test EJB components, but these frameworks often require you to learn framework-specific features. As illustrated in this article, using OpenEJB as an embedded container not only significantly reduces the time it takes to test EJB components, but also build and deploy them as well.

Thanks to David Blevins and Fredrik Harloff for reviewing and commenting on this article.

About the author

Nader Aeinehchi works as chief architect at EDB Business Partner, one of Scandinavia's largest IT companies. He has been extensively working with Java since 1996. He holds a MS in physics.

Read more about Enterprise Java in JavaWorld's Enterprise Java section.

  • Print
  • Feedback

Resources