Search in sources :

Example 1 with TestTen

use of org.structr.core.entity.TestTen in project structr by structr.

the class BasicTest method test08OverlappingDeleteCascades.

@Test
public void test08OverlappingDeleteCascades() {
    try {
        final List<TestTen> rootNodes = new LinkedList<>();
        final List<TestTen> allChildren = new LinkedList<>();
        final List<TestTen> allGrandChildren = new LinkedList<>();
        try (final Tx tx = app.tx()) {
            // create some nodes..
            rootNodes.addAll(createTestNodes(TestTen.class, 3));
            for (final TestTen node : rootNodes) {
                final List<TestTen> children = createTestNodes(TestTen.class, 3);
                node.setProperty(TestTen.tenTenChildren, children);
                for (final TestTen child : children) {
                    final List<TestTen> grandChildren = createTestNodes(TestTen.class, 3);
                    child.setProperty(TestTen.tenTenChildren, grandChildren);
                    allGrandChildren.addAll(grandChildren);
                }
                allChildren.addAll(children);
            }
            // create some additional links off a different type but with cascading delete
            rootNodes.get(0).setProperty(TestTen.testChild, allGrandChildren.get(0));
            allChildren.get(0).setProperty(TestTen.testChild, allGrandChildren.get(1));
            tx.success();
        }
        // check preconditions: exactly 39 nodes should exist
        try (final Tx tx = app.tx()) {
            assertEquals("Wrong number of nodes", 39, app.nodeQuery(TestTen.class).getAsList().size());
            tx.success();
        }
        // delete one root node
        try (final Tx tx = app.tx()) {
            app.delete(rootNodes.get(0));
            tx.success();
        }
        // check conditions after deletion, 26 nodes shoud exist
        try (final Tx tx = app.tx()) {
            assertEquals("Wrong number of nodes", 26, app.nodeQuery(TestTen.class).getAsList().size());
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : TestTen(org.structr.core.entity.TestTen) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 FrameworkException (org.structr.common.error.FrameworkException)1 TestTen (org.structr.core.entity.TestTen)1 Tx (org.structr.core.graph.Tx)1