Search in sources :

Example 6 with TestSix

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

the class CypherTest method test05RollbackDelete.

@Test
public void test05RollbackDelete() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        String relId = null;
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            relId = rel.getUuid();
            tx.success();
        }
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            // do not commit transaction
            testOne.getRelationships().iterator().next().getRelationship().delete();
        }
        try (final Tx tx = app.tx()) {
            assertEquals("UUID of relationship should be readable after rollback", relId, rel.getUuid());
            tx.success();
        } catch (NotFoundException iex) {
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 7 with TestSix

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

the class SearchAndSortingTest method test09SearchBySourceAndTargetId.

@Test
public void test09SearchBySourceAndTargetId() {
    try {
        final TestOne test1 = createTestNode(TestOne.class);
        final List<TestSix> tests = createTestNodes(TestSix.class, 5);
        try (final Tx tx = app.tx()) {
            test1.setProperty(TestOne.manyToManyTestSixs, tests);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            final List<SixOneManyToMany> result1 = app.relationshipQuery(SixOneManyToMany.class).and(SixOneManyToMany.sourceId, tests.get(0).getUuid()).getAsList();
            assertEquals("Invalid sourceId query result", 1, result1.size());
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            final List<SixOneManyToMany> result1 = app.relationshipQuery(SixOneManyToMany.class).and(SixOneManyToMany.targetId, test1.getUuid()).getAsList();
            assertEquals("Invalid targetId query result", 5, result1.size());
            tx.success();
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : SixOneManyToMany(org.structr.core.entity.SixOneManyToMany) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestOne(org.structr.core.entity.TestOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 8 with TestSix

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

the class PropertyTest method testOneToOneOnEntityProperty.

// ----- entity property tests -----
@Test
public void testOneToOneOnEntityProperty() throws Exception {
    try {
        final TestSix a = createTestNode(TestSix.class);
        final TestSix c = createTestNode(TestSix.class);
        final TestThree b = createTestNode(TestThree.class);
        final TestThree d = createTestNode(TestThree.class);
        try (final Tx tx = app.tx()) {
            a.setProperty(AbstractNode.name, "a");
            c.setProperty(AbstractNode.name, "c");
            b.setProperty(AbstractNode.name, "b");
            d.setProperty(AbstractNode.name, "d");
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
            fail("Unable to create test nodes");
        }
        assertNotNull(a);
        assertNotNull(c);
        assertNotNull(b);
        assertNotNull(d);
        // create two connections
        try (final Tx tx = app.tx()) {
            a.setProperty(TestSix.oneToOneTestThree, b);
            c.setProperty(TestSix.oneToOneTestThree, d);
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
            fail("Unable to link test nodes");
        }
        try (final Tx tx = app.tx()) {
            // verify connections
            TestThree verifyB = a.getProperty(TestSix.oneToOneTestThree);
            TestThree verifyD = c.getProperty(TestSix.oneToOneTestThree);
            assertTrue(verifyB != null && verifyB.equals(b));
            assertTrue(verifyD != null && verifyD.equals(d));
        }
        try (final Tx tx = app.tx()) {
            a.setProperty(TestSix.oneToOneTestThree, d);
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
            fail("Unable to link test nodes");
        }
        try (final Tx tx = app.tx()) {
            // verify connection
            TestThree verifyD2 = a.getProperty(TestSix.oneToOneTestThree);
            assertTrue(verifyD2 != null && verifyD2.equals(d));
            // testSix2 should not have a testThree associated
            TestThree vrfy4 = c.getProperty(TestSix.oneToOneTestThree);
            assertNull(vrfy4);
        }
    } catch (FrameworkException fex) {
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.core.entity.TestThree) TestSix(org.structr.core.entity.TestSix) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 9 with TestSix

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

the class PropertyTest method testOneToManyOnCollectionProperty.

// ----- collection property tests -----
@Test
public void testOneToManyOnCollectionProperty() throws Exception {
    TestOne testOne = null;
    List<TestSix> testSixs = null;
    List<TestSix> testSixs2 = null;
    int index = 0;
    List<Integer> index1 = new LinkedList();
    List<Integer> index2 = new LinkedList();
    try (final Tx tx = app.tx()) {
        testOne = createTestNode(TestOne.class);
        testSixs = createTestNodes(TestSix.class, 20);
        for (final TestSix testSix : testSixs) {
            int i = index++;
            testSix.setProperty(TestSix.index, i);
            System.out.println(i + " ");
            index1.add(i);
        }
        testOne.setProperty(TestOne.manyToManyTestSixs, testSixs);
        tx.success();
    }
    try (final Tx tx = app.tx()) {
        testSixs2 = testOne.getProperty(TestOne.manyToManyTestSixs);
        for (final TestSix testSix : testSixs2) {
            int i = testSix.getProperty(TestSix.index);
            System.out.println(i + " ");
            index2.add(i);
        }
        assertEquals(index1, index2);
        tx.success();
    }
}
Also used : Tx(org.structr.core.graph.Tx) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Example 10 with TestSix

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

the class PropertyTest method testManyToManyOnCollectionProperty.

@Test
public void testManyToManyOnCollectionProperty() throws Exception {
    try {
        Property<List<TestOne>> instance = TestSix.manyToManyTestOnes;
        TestSix testSix1 = null;
        TestSix testSix2 = null;
        TestOne testOne1 = null;
        TestOne testOne2 = null;
        testSix1 = createTestNode(TestSix.class);
        testSix2 = createTestNode(TestSix.class);
        testOne1 = createTestNode(TestOne.class);
        testOne2 = createTestNode(TestOne.class);
        assertNotNull(testSix1);
        assertNotNull(testSix2);
        assertNotNull(testOne1);
        assertNotNull(testOne2);
        // set two TestOne entities on both TestSix entities
        List<TestOne> twoTestOnesList = new LinkedList<>();
        twoTestOnesList.add(testOne1);
        twoTestOnesList.add(testOne2);
        try (final Tx tx = app.tx()) {
            instance.setProperty(securityContext, testSix1, twoTestOnesList);
            instance.setProperty(securityContext, testSix2, twoTestOnesList);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            List<TestOne> testOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
            List<TestOne> testOnesFromTestSix2 = instance.getProperty(securityContext, testSix2, true);
            assertNotNull(testOnesFromTestSix1);
            assertNotNull(testOnesFromTestSix2);
            // both entities should have the two related nodes
            assertEquals(2, testOnesFromTestSix1.size());
            assertEquals(2, testOnesFromTestSix2.size());
        }
        // create new list with one TestOne entity
        List<TestOne> oneTestOneList = new LinkedList<>();
        oneTestOneList.add(testOne1);
        try (final Tx tx = app.tx()) {
            // set list with one TestOne node as related nodes
            instance.setProperty(securityContext, testSix1, oneTestOneList);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            List<TestOne> oneTestOnesFromTestSix1 = instance.getProperty(securityContext, testSix1, true);
            // entity should have exactly one related node
            assertNotNull(oneTestOnesFromTestSix1);
            assertEquals(1, oneTestOnesFromTestSix1.size());
            assertEquals(oneTestOnesFromTestSix1.get(0).getUuid(), testOne1.getUuid());
        }
    } catch (FrameworkException fex) {
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) LinkedList(java.util.LinkedList) List(java.util.List) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) StructrTest(org.structr.common.StructrTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 TestSix (org.structr.core.entity.TestSix)17 Tx (org.structr.core.graph.Tx)17 FrameworkException (org.structr.common.error.FrameworkException)16 TestOne (org.structr.core.entity.TestOne)13 StructrTest (org.structr.common.StructrTest)6 LinkedList (java.util.LinkedList)5 NotFoundException (org.structr.api.NotFoundException)5 SixOneOneToOne (org.structr.core.entity.SixOneOneToOne)5 TestThree (org.structr.core.entity.TestThree)5 GraphObject (org.structr.core.GraphObject)3 Collection (java.util.Collection)2 Date (java.util.Date)2 List (java.util.List)2 UnlicensedException (org.structr.common.error.UnlicensedException)2 TestFour (org.structr.core.entity.TestFour)2 TestTwo (org.structr.core.entity.TestTwo)2 ActionContext (org.structr.schema.action.ActionContext)2 DecimalFormat (java.text.DecimalFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1