tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Karalus <>
Subject Re: Rollback transactions in unit testing
Date Mon, 29 Sep 2008 22:21:08 GMT

We are also using openejb for junit testing. In our tests we are using
UserTransaction to control the test data. Maybe  this approach might also
work for you. 
Below is the basic code, the startup and shutdown  of the container,  as
well as starting/stopping transaction could also be  moved to a base junit 
This works fine  with openejb 3.0, in 3.1-SNAPSHOT the UserTransaction can
be  retrieved with a jndi lookup (I think is java:openejb/UserTransaction)

public MyTest {

 static  MyService service;
 UserTransaction tx;

public static void  onBeforeClass() throws Exception{
   // start openejb embeded container  here
   InitialContext ctx  = new  IntialContext(props);
   // lookup service here
   service = (MyService)  ctx.lookup("java:openejb/MyServiceLocal");

public static void  onAfterClass() throws Exception{
   // shutdown openejb

public void onBefore() throws Exception{
  // start a UserTransaction for each  test method
  utx = new org.openejb.core.CoreUserTransaction()

public void onAfter() throws Exception{
  utx.commit();  // you can do also a utx.rollback() here

//sample test  method
public void testServiceMethod() throws  Exception{



Glauber Ferreira-2 wrote:
> Hi all.
> I need to rollback transactions in order to revert all data modified
> (deleted, updated, created) by my tests. How can I do that in the test
> code
> listed in this link:
> Thanks in advance.
> -- 
> Glauber Vinícius Ventura de Melo Ferreira
> PGP: 0x5AA19EF5

View this message in context:
Sent from the OpenEJB User mailing list archive at

View raw message