use of org.datanucleus.samples.annotations.callbacks.CallbackSub1Sub1 in project tests by datanucleus.
the class CallbackTest method testCallbackNotOverridden.
public void testCallbackNotOverridden() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
CallbackBase.invoked.clear();
tx.begin();
CallbackSub1Sub1 d = new CallbackSub1Sub1();
d.setName("dpt1");
d.setId("1");
em.persist(d);
em.flush();
assertEquals(1, CallbackBase.invoked.size());
assertEquals(CallbackSub1Sub1.class.getName(), (CallbackBase.invoked.get(0)).getName());
tx.rollback();
} finally {
CallbackBase.invoked.clear();
CallbackSub1Listener.invoked.clear();
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(CallbackSub1Sub1.class);
}
}
use of org.datanucleus.samples.annotations.callbacks.CallbackSub1Sub1 in project tests by datanucleus.
the class CallbackTest method testExpectionInCallbackListenerNotEaten.
public void testExpectionInCallbackListenerNotEaten() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
CallbackSub1Listener.raiseException = true;
CallbackSub1Sub1 d = new CallbackSub1Sub1();
d.setName("dpt1");
d.setId("1");
em.persist(d);
em.flush();
fail("Expected ArithmeticException");
} catch (ArithmeticException ex) {
// expected
} finally {
CallbackBase.invoked.clear();
CallbackSub1Listener.raiseException = false;
CallbackSub1Listener.invoked.clear();
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(CallbackSub1Sub1.class);
}
}
use of org.datanucleus.samples.annotations.callbacks.CallbackSub1Sub1 in project tests by datanucleus.
the class CallbackTest method testListenerClassCalled.
public void testListenerClassCalled() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
CallbackSub1Sub1 d = new CallbackSub1Sub1();
d.setName("dpt1");
d.setId("1");
em.persist(d);
em.flush();
assertEquals(2, CallbackSub1Listener.invoked.size());
assertEquals(PrePersist.class.getName(), CallbackSub1Listener.invoked.get(0));
assertEquals(PostPersist.class.getName(), CallbackSub1Listener.invoked.get(1));
tx.rollback();
} finally {
CallbackBase.invoked.clear();
CallbackSub1Listener.invoked.clear();
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(CallbackSub1Sub1.class);
}
}
Aggregations