Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public class MoviesTest extends TestCase {
    private Context context;

    protected void setUp() throws Exception {
        // initialize jndi context as usual
    }

    public void test() throws Exception {
        Caller transactionBean = (Caller) context.lookup("TransactionBeanLocal");

        transactionBean.call(new Callable() {
            public Object call() throws Exception {
                Movies movies = (Movies) context.lookup("MoviesLocal");

                movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
                movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
                movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));

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

                for (Movie movie : list) {
                    movies.deleteMovie(movie);
                }

                assertEquals("Movies.getMovies()", 0, movies.getMovies().size());

                return null;
            }
        });
    }
}

Same test code, different transaction scenarios

Maybe you'd like to test how things behave with and without a transaction to guarantee everyone is doing the right thing in all situations. Negative testing is often a very good way to stop out dangerous bugs.

...