Entries tagged [testing]

Monday April 26, 2010

How much time have you saved with OpenEJB? Find out!

Inspired by Matthew B. Jones' blog post sharing his experience saving a whopping 26 person weeks in development with OpenEJB, we've put together a time saved calculator.

A fun little tool for those that develop with OpenEJB and use a different platform in production. Check it out!

User Blog: OpenEJB : Rapid J2EE Development & Testing

Matthew B. Jones writes a great piece, OpenEJB : Rapid J2EE Development & Testing, sharing his team's experience using OpenEJB to aid in the development of their very large JBoss application. His team of 10 has been using OpenEJB since February and by his most conservative estimations has saved 26 man-weeks on deployment time alone. A shocking amount even to our ears.

Friday March 12, 2010

Example: Common Troubleshooting flags

Having trouble with a test? It's bound to happen eventually. We've coded up a little example that employs some of the more common ways to get more information to help resolve issues.

The heart of the example is the following setup method:

public void setUp() throws Exception {
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
    p.put("movieDatabase", "new://Resource?type=DataSource");
    p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");

    // These two debug levels will get you the basic log information
    // on the deployment of applications. Good first step in troubleshooting.
    p.put("log4j.category.OpenEJB.startup", "debug");
    p.put("log4j.category.OpenEJB.startup.config", "debug");

    // This log category is a good way to see what "openejb.foo" options
    // and flags are available and what their default values are
    p.put("log4j.category.OpenEJB.options", "debug");

    // This will output the full configuration of all containers
    // resources and other openejb.xml configurable items.  A good
    // way to see what the final configuration looks like after all
    // overriding has been applied.
    p.put("log4j.category.OpenEJB.startup.service", "debug");

    // Want timestamps in the log output?
    p.put("log4j.appender.C.layout", "org.apache.log4j.PatternLayout");
    p.put("log4j.appender.C.layout.ConversionPattern", "%d - %-5p - %m%n");

    // Will output a generated ejb-jar.xml file that represents
    // 100% of the annotations used in the code.  This is a great
    // way to figure out how to do something in xml for overriding
    // or just to "see" all your application meta-data in one place.
    // Look for log lines like this "Dumping Generated ejb-jar.xml to"
    p.put("openejb.descriptors.output", "true");

    // Setting the validation output level to verbose results in
    // validation messages that attempt to provide explanations
    // and information on what steps can be taken to remedy failures.
    // A great tool for those learning EJB.
    p.put("openejb.validation.output.level", "verbose");

    initialContext = new InitialContext(p);

    initialContext.bind("inject", this);

In practice it is not a good idea to enable so many debug flags as the output will be too much. Best to start with one, read the log output, and see if that doesn't give some direction. If not, disable it and move on to the next.

Wednesday March 10, 2010

Example: Testing Transaction Rollback

We've coded up a nice little example project that shows various ways to rollback transactions in unit tests.

The example also serves to show the various options in EJB that pertain to how to rollback transactions via either a UserTransaction, SessionContext.setRollbackOnly(), or throwing a RuntimeException. The example also shows how to mark a RuntimeException with @ApplicationException to bypass the rollback behavior.

Here's a snippet from the test case to show how simple it is to test:

 * Transaction is marked for rollback inside the bean via
 * calling the javax.ejb.SessionContext.setRollbackOnly() method
 * This is the cleanest way to make a transaction rollback.
public void testMarkedRollback() throws Exception {


    try {
        entityManager.persist(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
        entityManager.persist(new Movie("Joel Coen", "Fargo", 1996));
        entityManager.persist(new Movie("Joel Coen", "The Big Lebowski", 1998));

        List list = movies.getMovies();
        assertEquals("List.size()", 3, list.size());

    } finally {
        try {
            fail("A RollbackException should have been thrown");
        } catch (RollbackException e) {
            // Pass

    // Transaction was rolled back
    List list = movies.getMovies();
    assertEquals("List.size()", 0, list.size());


Monday March 08, 2010

User Blog: Maven, OpenEJB and eviware soapUI

Magnus K Karlsson has written a nice blog post about using Maven, OpenEJB and eviware soapUI to develop and test JAX-WS Web Services.

The full chain involves creating the Maven, OpenEJB driven unit tests and eventually deployment into JBoss with further testing driven manually via the eviware soapUI tool.

Thursday March 04, 2010

Article: Coarse Grained Unit Testing

Dr. Dobb's has a great article titled Coarse-Grained Unit Testing: Using OpenEJB and DBUnit to write repeatable unit tests for Java componentswhich shows how to combine OpenEJB with DBUnit to get a very effective testing setup. The article is complete with an example based on the fictitious Blue Star Galactic spaceship company. All source code is available to download.

Wednesday August 05, 2009

Screencast: EJB Unit Testing with Eclipse and OpenEJB (repost)

We've had some download issues with the original screencast, so we have uploaded it to a video sight and are reposting it to the blog.

This screencast shows how you can turn the plain, non-javaee version of Eclipse into an EJB testing machine. The tutorial walks you through installing Eclipse, adding OpenEJB to your project's classpath, and creating a simple EJB with a JUnit unit test.

EJB Unit Testing with Eclipse and OpenEJB from OpenEJB on Vimeo.

(video made with ScreenFlow)

User Blog: Effective Unit Testing EJB 3.0 with OpenEJB

Magnus K Karlsson writes Effective Unit Testing EJB 3.0 with OpenEJB.

As you state quite well, Mangus, many people have had a bad experience with EJB 2.1 and although simpler EJB 3.0 is not so easily testable without a container. Unless of course you use an embedded EJB container like OpenEJB.

We greatly appreciate blog posts like yours as many people try and fail with a few approaches before finally finding OpenEJB. So many more people don't even look for a solution. Blog posts like yours go a long way in helping to get the word out.

Thanks, Magnus!

Tuesday August 04, 2009

User Blog: OpenEJB 3.1 JBoss Embedded and EJB 3.0 unit testing

Nick Mpallas writes in his Nick Says blog an entry titled OpenEJB 3.1 JBoss Embedded and EJB 3.0 unit testing about his month long quest to figure out a way to unit test EJBs. He tries JBoss Embedded first as so many people do and eventually settles on OpenEJB with TestNG and Hibernate.

Thanks for writing, Nick! We're really excited to see more updates about your progress.

Monday August 03, 2009

User Blog: Restarting the embedded OpenEJB container between each test

Jonas Bandi writes in his CLOSED-LOOP blog a nice entry on Restarting the embedded OpenEJB container between each test. Jonas documents the use of a newer property "openejb.embedded.initialcontext.close" which allows you to destroy the embedded container system after each test.

Note that Maven users can use Surefire Forking to achieve a similar result that will also clear out any embedded database state as well. That approach basically gives you a fresh VM for every test and the approach we use internally in our build. Haven't done any speed comparisons to see how they stack up speed wise.

Sunday August 02, 2009

User Blog: How To Unit-Test EJB 3 ...in 0.8 Seconds

Adam Bien writes in is popular weblog an nice entry called How To Unit-Test EJB 3 ...in 0.8 Seconds. As the subject implies he covers using OpenEJB for fast and light EJB 3.0 unit testing.

Adam has been working on a new project called Project Kenai which aims to take a fresh look at Java EE design patterns. So many J2EE design patterns deal with things which were similified or eliminated altogether in EJB 3.0. It's about time someone came out with some new material.

Great work Adam! Thanks for ensuring your examples run on OpenEJB!

Thursday June 18, 2009

Screencast: EJB Unit Testing with Eclipse and OpenEJB

We've put together the first of hopefully many screencasts to walk you through various aspects of using OpenEJB. This screencast shows how you can turn the plain, non-javaee version of Eclipse into an EJB testing machine. The tutorial walks you through installing Eclipse, adding OpenEJB to your project's classpath, and creating a simple EJB with a JUnit unit test.

EJB Unit Testing with Eclipse and OpenEJB


Friday June 05, 2009

Apache OpenEJB 3.1.1 Released

The Apache OpenEJB team is excited to announce the release of OpenEJB 3.1.1.

This release includes some great enhancements for the embedded testing scenarios and general EJB programming. Notable improvements include:

- Dependency injection for test cases and clients of the embedded ejb container via new @LocalClient annotation.
- Support for annotating the same interface as @Local, @Remote and @WebService making it possible to exposing all possible EJB views with a single interface.
- Web Service views securable with @RolesAllowed, @PermitAll and @DenyAll annotations.
- Ability to easily use alternate sets of deployment descriptors for some or all tests via new 'openejb.altdd.prefix' property.
- Global lookups from any context simplified via new "openejb:" jndi namespace.

The release also contains several new examples including Applets invoking EJBs in webapps, Struts with JPA and EJB, secured web services and web services with Perl SOAP::Lite clients and more.

Tuesday April 28, 2009

Alternate descriptors for testing

Inspired by some user blog posts, we've added a new feature so support for altDD (alternative deployment descriptors) can be done in a test or other environment without much work.

Basically, just set the new "openejb.altdd.prefix" system property or initialcontext property to something like "test", then any descriptors in your META-INF/ directory that start with "test." will override the regular descriptor. So for example with an app like this:

  • META-INF/ejb-jar.xml
  • META-INF/test.ejb-jar.xml
  • META-INF/persistence.xml
  • META-INF/test.env-entry.properties

    Just initialize your test case like so:

     Properties properties = new Properties();
     properties.setProperty("openejb.altdd.prefix", "test");
     InitialContext initialContext = new InitialContext(properties);
    The logical result will be:

  • META-INF/ejb-jar.xml (via test.ejb-jar.xml)
  • META-INF/persistence.xml
  • META-INF/env-entry.properties (via test.env-entry.properties)

    This will work in any environment in which OpenEJB works (embedded, standalone, tomcat, geronimo, etc.).

  • Calendar


    Hot Blogs (today's hits)

    Tag Cloud