Search in sources :

Example 1 with DeleteDenyException

use of org.apache.cayenne.DeleteDenyException in project cayenne by apache.

the class DeleteRulesIT method testDenyFlattenedNoReverse.

@Test
public void testDenyFlattenedNoReverse() {
    // temporarily set delete rule to DENY...
    int oldRule = changeDeleteRule(DeleteRule.DENY);
    ObjRelationship reverse = unsetReverse();
    try {
        DeleteRuleFlatA a = context.newObject(DeleteRuleFlatA.class);
        DeleteRuleFlatB b = context.newObject(DeleteRuleFlatB.class);
        a.addToFlatB(b);
        context.commitChanges();
        try {
            context.deleteObjects(a);
            fail("Must have thrown a deny exception..");
        } catch (DeleteDenyException ex) {
            // expected... but check further
            assertJoinNotDeleted(a, b);
        }
    } finally {
        changeDeleteRule(oldRule);
        restoreReverse(reverse);
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) DeleteDenyException(org.apache.cayenne.DeleteDenyException) DeleteRuleFlatA(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA) DeleteRuleFlatB(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB) Test(org.junit.Test)

Example 2 with DeleteDenyException

use of org.apache.cayenne.DeleteDenyException in project cayenne by apache.

the class DeleteRulesIT method testDenyFlattened.

@Test
public void testDenyFlattened() {
    // temporarily set delete rule to DENY...
    int oldRule = changeDeleteRule(DeleteRule.DENY);
    try {
        DeleteRuleFlatA a = context.newObject(DeleteRuleFlatA.class);
        DeleteRuleFlatB b = context.newObject(DeleteRuleFlatB.class);
        a.addToFlatB(b);
        context.commitChanges();
        try {
            context.deleteObjects(a);
            fail("Must have thrown a deny exception..");
        } catch (DeleteDenyException ex) {
            // expected... but check further
            assertJoinNotDeleted(a, b);
        }
    } finally {
        changeDeleteRule(oldRule);
    }
}
Also used : DeleteDenyException(org.apache.cayenne.DeleteDenyException) DeleteRuleFlatA(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA) DeleteRuleFlatB(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB) Test(org.junit.Test)

Aggregations

DeleteDenyException (org.apache.cayenne.DeleteDenyException)2 DeleteRuleFlatA (org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA)2 DeleteRuleFlatB (org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB)2 Test (org.junit.Test)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1