Search in sources :

Example 11 with TestSix

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

the class PropertyTest method testOneToManyOnEntityProperty.

@Test
public void testOneToManyOnEntityProperty() throws Exception {
    try {
        final TestSix testSix1 = createTestNode(TestSix.class);
        final TestSix testSix2 = createTestNode(TestSix.class);
        final TestThree testThree1 = createTestNode(TestThree.class);
        final TestThree testThree2 = createTestNode(TestThree.class);
        try (final Tx tx = app.tx()) {
            testSix1.setProperty(AbstractNode.name, "a");
            testSix2.setProperty(AbstractNode.name, "c");
            testThree1.setProperty(AbstractNode.name, "b");
            testThree2.setProperty(AbstractNode.name, "d");
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
            fail("Unable to create test nodes");
        }
        assertNotNull(testSix1);
        assertNotNull(testThree1);
        assertNotNull(testSix2);
        assertNotNull(testThree2);
        /**
         * We test the following here:
         * A -> B
         * C -> D
         *
         * then connect A -> D, so C and B should not
         * be related any more
         */
        try (final Tx tx = app.tx()) {
            testSix1.setProperty(TestSix.oneToManyTestThrees, toList(testThree1));
            testSix2.setProperty(TestSix.oneToManyTestThrees, toList(testThree2));
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
            fail("Unable to link test nodes");
        }
        try (final Tx tx = app.tx()) {
            // verify connections
            List<TestThree> verifyB = testSix1.getProperty(TestSix.oneToManyTestThrees);
            List<TestThree> verifyD = testSix2.getProperty(TestSix.oneToManyTestThrees);
            assertTrue(verifyB != null && verifyB.get(0).equals(testThree1));
            assertTrue(verifyD != null && verifyD.get(0).equals(testThree2));
        }
        try (final Tx tx = app.tx()) {
            testSix1.setProperty(TestSix.oneToManyTestThrees, toList(testThree2));
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
            fail("Unable to link test nodes");
        }
        try (final Tx tx = app.tx()) {
            // verify connection
            List<TestThree> verifyD2 = testSix1.getProperty(TestSix.oneToManyTestThrees);
            assertEquals(1, verifyD2.size());
            assertEquals(testThree2, verifyD2.get(0));
            // testSix2 should not have a testThree associated
            List<TestThree> vrfy4 = testSix2.getProperty(TestSix.oneToManyTestThrees);
            assertEquals(0, vrfy4.size());
        }
    } 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 12 with TestSix

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

the class SystemTest method testConcurrentIdenticalRelationshipCreation.

@Test
public void testConcurrentIdenticalRelationshipCreation() {
    try {
        final ExecutorService service = Executors.newCachedThreadPool();
        final TestSix source = createTestNode(TestSix.class);
        final TestOne target = createTestNode(TestOne.class);
        final Future one = service.submit(new RelationshipCreator(source, target));
        final Future two = service.submit(new RelationshipCreator(source, target));
        // wait for completion
        one.get();
        two.get();
        try (final Tx tx = app.tx()) {
            // check for a single relationship since all three parts of
            // both relationships are equal => only one should be created
            final List<TestOne> list = source.getProperty(TestSix.oneToManyTestOnes);
            assertEquals("Invalid concurrent identical relationship creation result", 1, list.size());
            tx.success();
        }
        service.shutdownNow();
    } catch (ExecutionException | InterruptedException | FrameworkException fex) {
        logger.warn("", fex);
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) TestOne(org.structr.core.entity.TestOne) ExecutionException(java.util.concurrent.ExecutionException) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 13 with TestSix

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

the class BasicTest method test01DeleteRelationship.

@Test
public void test01DeleteRelationship() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        try {
            // try to delete relationship
            rel.getRelationship().delete();
            fail("Should have raised an org.neo4j.graphdb.NotInTransactionException");
        } catch (NotInTransactionException e) {
        }
        // Relationship still there
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            app.delete(rel);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            String uuid = rel.getUuid();
            fail("Deleted entity should have thrown an exception on access.");
        } catch (NotFoundException iex) {
        }
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotInTransactionException(org.structr.api.NotInTransactionException) 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 14 with TestSix

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

the class BasicTest method test06DuplicateRelationshipsOneToMany.

@Test
public void test06DuplicateRelationshipsOneToMany() {
    try (final Tx tx = app.tx()) {
        final TestSix test1 = app.create(TestSix.class);
        final TestThree test2 = app.create(TestThree.class);
        // test duplicate prevention
        app.create(test1, test2, SixThreeOneToMany.class);
        app.create(test1, test2, SixThreeOneToMany.class);
        tx.success();
    } catch (FrameworkException ex) {
        fail("Creating duplicate relationships via app.create() should NOT throw an exception.");
    }
    // the duplicates in the list
    try (final Tx tx = app.tx()) {
        final TestSix test1 = app.create(TestSix.class);
        final TestThree test2 = app.create(TestThree.class);
        // test duplicate prevention
        final List<TestThree> list = new LinkedList<>();
        list.add(test2);
        list.add(test2);
        test1.setProperty(TestSix.oneToManyTestThrees, list);
        tx.success();
    } catch (FrameworkException ex) {
        fail("Creating duplicate relationships via setProperty() should NOT throw an exception.");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestThree(org.structr.core.entity.TestThree) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 15 with TestSix

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

the class CypherTest method test04DeleteAfterIndexLookup.

@Test
public void test04DeleteAfterIndexLookup() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            GraphObject searchRes = app.getNodeById(testSix.getUuid());
            assertNotNull(searchRes);
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            testSix.getRelationships().iterator().next().getRelationship().delete();
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            rel.getUuid();
            fail("Accessing a deleted relationship should thow an exception.");
            tx.success();
        } catch (NotFoundException nfex) {
            assertNotNull(nfex.getMessage());
        }
    } 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) GraphObject(org.structr.core.GraphObject) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) 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