use of com.haulmont.cuba.core.global.DeletePolicyException in project cuba by cuba-platform.
the class SoftDeleteMany2ManyTest method testMany2ManyDeny.
@Test
public void testMany2ManyDeny() throws Exception {
try (Transaction tx = cont.persistence().createTransaction()) {
Many2ManyA a = cont.entityManager().find(Many2ManyA.class, many2ManyA2.getId());
assertNotNull(a);
assertFalse(a.getCollectionOfB2().isEmpty());
assertEquals(many2ManyB2, a.getCollectionOfB2().iterator().next());
tx.commit();
}
try (Transaction tx = cont.persistence().createTransaction()) {
Many2ManyA a = cont.entityManager().find(Many2ManyA.class, many2ManyA2.getId());
cont.entityManager().remove(a);
tx.commit();
fail();
} catch (Exception e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
if (rootCause == null)
rootCause = e;
if (!(rootCause instanceof DeletePolicyException))
rootCause.printStackTrace();
assertTrue(rootCause instanceof DeletePolicyException);
}
try (Transaction tx = cont.persistence().createTransaction()) {
Many2ManyA a = cont.entityManager().find(Many2ManyA.class, many2ManyA2.getId());
assertNotNull(a);
assertFalse(a.getCollectionOfB2().isEmpty());
assertEquals(many2ManyB2, a.getCollectionOfB2().iterator().next());
tx.commit();
}
}
Aggregations