Search in sources :

Example 1 with DeletePolicyException

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();
    }
}
Also used : Transaction(com.haulmont.cuba.core.Transaction) Many2ManyA(com.haulmont.cuba.testmodel.many2many.Many2ManyA) DeletePolicyException(com.haulmont.cuba.core.global.DeletePolicyException) DeletePolicyException(com.haulmont.cuba.core.global.DeletePolicyException) Test(org.junit.Test)

Aggregations

Transaction (com.haulmont.cuba.core.Transaction)1 DeletePolicyException (com.haulmont.cuba.core.global.DeletePolicyException)1 Many2ManyA (com.haulmont.cuba.testmodel.many2many.Many2ManyA)1 Test (org.junit.Test)1