use of org.apache.openejb.test.TestFailureException in project tomee by apache.
the class PersistenceContextStatefulBean method testPropagatedPersistenceContext.
public void testPropagatedPersistenceContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
final EntityManager em = (EntityManager) ctx.lookup("java:comp/env/persistence/ExtendedTestContext");
Assert.assertNotNull("The EntityManager is null", em);
// call a do nothing method to assure entity manager actually exists
em.getFlushMode();
// get the raw entity manager so we can test it below
inheritedDelegate = (EntityManager) em.getDelegate();
// The extended entity manager is not propigated to a non-extended entity manager unless there is a transaction
final EntityManager nonExtendedEm = (EntityManager) ctx.lookup("java:comp/env/persistence/TestContext");
nonExtendedEm.getFlushMode();
final EntityManager nonExtendedDelegate = ((EntityManager) nonExtendedEm.getDelegate());
Assert.assertTrue("non-extended entity manager should be open", nonExtendedDelegate.isOpen());
Assert.assertNotSame("Extended non-extended entity manager shound not be the same instance as extendend entity manager when accessed out side of a transactions", inheritedDelegate, nonExtendedDelegate);
// When the non-extended entity manager is accessed within a transaction is should see the stateful extended context.
//
// Note: this code also tests EBJ 3.0 Persistence spec 5.9.1 "UserTransaction is begun within the method, the
// container associates the persistence context with the JTA transaction and calls EntityManager.joinTransaction."
// If our the extended entity manager were not associted with the transaction, the non-extended entity manager would
// not see it.
final UserTransaction userTransaction = ejbContext.getUserTransaction();
userTransaction.begin();
try {
Assert.assertSame("Extended non-extended entity manager to be same instance as extendend entity manager", inheritedDelegate, nonExtendedEm.getDelegate());
} finally {
userTransaction.commit();
}
// When a stateful bean with an extended entity manager creates another stateful bean, the new bean will
// inherit the extended entity manager (assuming it contains an extended entity manager for the same persistence
// unit).
final PersistenceContextStatefulHome home = (PersistenceContextStatefulHome) ejbContext.getEJBHome();
final PersistenceContextStatefulObject object = home.create();
// test the new stateful bean recieved the context
object.testPropgation();
// remove the bean
object.remove();
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of org.apache.openejb.test.TestFailureException in project tomee by apache.
the class SetterInjectionStatefulBean method lookupFloatEntry.
public void lookupFloatEntry() throws TestFailureException {
try {
final Float expected = new Float(1.0F);
Assert.assertNotNull("The Float looked up is null", flooatField);
Assert.assertEquals(expected, flooatField);
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of org.apache.openejb.test.TestFailureException in project tomee by apache.
the class SetterInjectionStatefulBean method lookupLongEntry.
public void lookupLongEntry() throws TestFailureException {
try {
final Long expected = new Long(1L);
Assert.assertNotNull("The Long looked up is null", loongField);
Assert.assertEquals(expected, loongField);
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of org.apache.openejb.test.TestFailureException in project tomee by apache.
the class SetterInjectionStatefulBean method lookupCharacterEntry.
public void lookupCharacterEntry() throws TestFailureException {
try {
final Character expected = new Character('D');
Assert.assertNotNull("The Character looked up is null", chaaracterField);
Assert.assertEquals(expected, chaaracterField);
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of org.apache.openejb.test.TestFailureException in project tomee by apache.
the class AnnotatedFieldInjectionStatelessBean method lookupJMSConnectionFactory.
public void lookupJMSConnectionFactory() throws TestFailureException {
try {
try {
testJmsConnection(coonnectionFactory.createConnection());
testJmsConnection(queueCoonnectionFactory.createConnection());
testJmsConnection(topicCoonnectionFactory.createConnection());
} catch (final Exception e) {
e.printStackTrace();
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
Aggregations