Search in sources :

Example 1 with OneTwoOneToOne

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

the class BasicTest method testNodeCacheInvalidationInRelationshipWrapper.

@Test
public void testNodeCacheInvalidationInRelationshipWrapper() {
    try (final Tx tx = app.tx()) {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestTwo testTwo1 = createTestNode(TestTwo.class, new NodeAttribute<>(TestTwo.testOne, testOne));
        final OneTwoOneToOne rel = testOne.getOutgoingRelationship(OneTwoOneToOne.class);
        final TestTwo testTwo2 = rel.getTargetNode();
        testTwo1.setProperty(AbstractNode.name, "test");
        assertEquals("Cache invalidation failure!", "test", testTwo2.getProperty(AbstractNode.name));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    // fill cache with other nodes
    try {
        createTestNodes(TestSix.class, 1000);
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
    try (final Tx tx = app.tx()) {
        final TestOne testOne = app.nodeQuery(TestOne.class).getFirst();
        final TestTwo testTwo1 = app.nodeQuery(TestTwo.class).getFirst();
        final OneTwoOneToOne rel = testOne.getOutgoingRelationship(OneTwoOneToOne.class);
        final TestTwo testTwo2 = rel.getTargetNode();
        testTwo1.setProperty(AbstractNode.name, "test2");
        assertEquals("Cache invalidation failure!", "test2", testTwo2.getProperty(AbstractNode.name));
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
        fail("Unexpected exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestTwo(org.structr.core.entity.TestTwo) TestOne(org.structr.core.entity.TestOne) OneTwoOneToOne(org.structr.core.entity.OneTwoOneToOne) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 FrameworkException (org.structr.common.error.FrameworkException)1 OneTwoOneToOne (org.structr.core.entity.OneTwoOneToOne)1 TestOne (org.structr.core.entity.TestOne)1 TestTwo (org.structr.core.entity.TestTwo)1 Tx (org.structr.core.graph.Tx)1