Search in sources :

Example 1 with SixOneOneToOne

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

the class CypherTest method test03DeleteDirectly.

@Test
public void test03DeleteDirectly() {
    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()) {
            testOne.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) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 2 with SixOneOneToOne

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

the class CypherTest method test01DeleteAfterLookupWithCypherInTransaction.

@Test
public void test01DeleteAfterLookupWithCypherInTransaction() {
    try {
        final TestSix testSix = this.createTestNode(TestSix.class);
        final TestOne testOne = this.createTestNode(TestOne.class);
        SixOneOneToOne rel = null;
        assertNotNull(testSix);
        assertNotNull(testOne);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        DatabaseService graphDb = app.command(GraphDatabaseCommand.class).execute();
        try (final Tx tx = app.tx()) {
            NativeResult<Relationship> result = graphDb.execute("MATCH (n)<-[r:ONE_TO_ONE]-() RETURN r");
            final Iterator<Relationship> rels = result.columnAs("r");
            assertTrue(rels.hasNext());
            rels.next().delete();
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            rel.getUuid();
            fail("Accessing a deleted relationship should thow an exception.");
            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) Relationship(org.structr.api.graph.Relationship) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) DatabaseService(org.structr.api.DatabaseService) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) GraphDatabaseCommand(org.structr.core.graph.GraphDatabaseCommand) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 3 with SixOneOneToOne

use of org.structr.core.entity.SixOneOneToOne 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 4 with SixOneOneToOne

use of org.structr.core.entity.SixOneOneToOne 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 5 with SixOneOneToOne

use of org.structr.core.entity.SixOneOneToOne 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)5 NotFoundException (org.structr.api.NotFoundException)5 FrameworkException (org.structr.common.error.FrameworkException)5 SixOneOneToOne (org.structr.core.entity.SixOneOneToOne)5 TestOne (org.structr.core.entity.TestOne)5 TestSix (org.structr.core.entity.TestSix)5 Tx (org.structr.core.graph.Tx)5 DatabaseService (org.structr.api.DatabaseService)1 NotInTransactionException (org.structr.api.NotInTransactionException)1 Relationship (org.structr.api.graph.Relationship)1 GraphObject (org.structr.core.GraphObject)1 GraphDatabaseCommand (org.structr.core.graph.GraphDatabaseCommand)1