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
class.
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;
@BeforeClass
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");
}
@AfterClass
public static void onAfterClass() throws Exception{
// shutdown openejb
OpenEJB.destroy();
}
@Before
public void onBefore() throws Exception{
// start a UserTransaction for each test method
utx = new org.openejb.core.CoreUserTransaction()
utx.begin();
}
@After
public void onAfter() throws Exception{
utx.commit(); // you can do also a utx.rollback() here
}
//sample test method
@Test
public void testServiceMethod() throws Exception{
service.doSomething();
}
}
Regards,
Andreas
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:
> http://openejb.apache.org/3.0/unit-testing-transactions.html
>
>
> Thanks in advance.
>
> --
> Glauber VinÃcius Ventura de Melo Ferreira
> PGP: 0x5AA19EF5
>
>
--
View this message in context:
http://www.nabble.com/Rollback-transactions-in-unit-testing-tp19724095p19732849.html
Sent from the OpenEJB User mailing list archive at Nabble.com.