ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
Assert.assertNotNull(ref);
osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
tm.begin();
Transaction t = tm.getTransaction();
try {
cs.doSomethingBad();
Assert.fail("NullPointerException expected");
} catch (Exception e) {
Assert.assertTrue(e instanceof NullPointerException);
}
Transaction t2 = cs.getCurrentTransaction();
Assert.assertSame(t2, t);
Assert.assertEquals(Status.STATUS_MARKED_ROLLBACK, t.getStatus());
try {
t.commit(); // Throw a rollback exception.
} catch (RollbackException e) {
// Expected
} catch (Throwable e) {
Assert.fail(e.getMessage()); // Unexpected
}
Assert.assertNotNull(cs.getLastRolledBack());
Assert.assertNull(cs.getLastCommitted());
Assert.assertEquals(0, cs.getNumberOfCommit());
Assert.assertEquals(1, cs.getNumberOfRollback());
Assert.assertSame(t, cs.getLastRolledBack());
}