Search in sources :

Example 1 with TestSix

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

the class BasicTest method test06DuplicateRelationshipsManyToMany.

@Test
public void test06DuplicateRelationshipsManyToMany() {
    try (final Tx tx = app.tx()) {
        final TestSix test1 = app.create(TestSix.class);
        final TestOne test2 = app.create(TestOne.class);
        // test duplicate prevention
        app.create(test1, test2, SixOneManyToMany.class);
        app.create(test1, test2, SixOneManyToMany.class);
        fail("Creating duplicate relationships should throw an exception.");
        tx.success();
    } catch (FrameworkException ex) {
    }
    // for manyToMany only.
    try (final Tx tx = app.tx()) {
        final TestSix test1 = app.create(TestSix.class);
        final TestOne test2 = app.create(TestOne.class);
        // test duplicate prevention
        final List<TestOne> list = new LinkedList<>();
        list.add(test2);
        list.add(test2);
        test1.setProperty(TestSix.manyToManyTestOnes, 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) TestOne(org.structr.core.entity.TestOne) LinkedList(java.util.LinkedList) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 2 with TestSix

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

the class BasicTest method test00SimpleCreateOperation.

@Test
public void test00SimpleCreateOperation() {
    try (final Tx tx = app.tx()) {
        final PropertyMap properties = new PropertyMap();
        properties.put(TestSix.name, "name");
        // test null value for a 1:1 related property
        properties.put(TestSix.oneToOneTestThree, null);
        app.create(TestSix.class, properties);
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        final TestSix test = app.nodeQuery(TestSix.class).getFirst();
        assertNotNull("Invalid simple object creation result", test);
        assertEquals("Invalid simple object creation result", "name", test.getProperty(AbstractNode.name));
        assertEquals("Invalid simple object creation result", null, test.getProperty(TestSix.oneToOneTestThree));
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception");
    }
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 3 with TestSix

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

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

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

the class CypherTest method testCypherResultWrapping.

@Test
public void testCypherResultWrapping() {
    try (final Tx tx = app.tx()) {
        List<TestOne> testOnes = createTestNodes(TestOne.class, 10);
        List<TestSix> testSixs = createTestNodes(TestSix.class, 10);
        for (final TestOne testOne : testOnes) {
            testOne.setProperty(TestOne.manyToManyTestSixs, testSixs);
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.warn("", ex);
        fail("Unexpected exception");
    }
    try (final Tx tx = app.tx()) {
        final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH (n:TestOne) RETURN DISTINCT n");
        assertEquals("Invalid wrapped cypher query result", 10, result.size());
        for (final GraphObject obj : result) {
            System.out.println(obj);
            assertEquals("Invalid wrapped cypher query result", TestOne.class, obj.getClass());
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH (n:TestOne)-[r]-(m:TestSix) RETURN DISTINCT  n, r, m ");
        final Iterator<GraphObject> it = result.iterator();
        assertEquals("Invalid wrapped cypher query result", 300, result.size());
        while (it.hasNext()) {
            // n
            assertEquals("Invalid wrapped cypher query result", TestOne.class, it.next().getClass());
            // r
            assertEquals("Invalid wrapped cypher query result", SixOneManyToMany.class, it.next().getClass());
            // m
            assertEquals("Invalid wrapped cypher query result", TestSix.class, it.next().getClass());
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN p ");
        assertEquals("Invalid wrapped cypher query result", 100, result.size());
        for (final GraphObject obj : result) {
            assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN { nodes: nodes(p), rels: relationships(p) } ");
        assertEquals("Invalid wrapped cypher query result", 100, result.size());
        for (final GraphObject obj : result) {
            assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());
            final Object nodes = obj.getProperty(new StringProperty("nodes"));
            final Object rels = obj.getProperty(new StringProperty("rels"));
            assertTrue("Invalid wrapped cypher query result", nodes instanceof Collection);
            assertTrue("Invalid wrapped cypher query result", rels instanceof Collection);
            final Iterator it = ((Collection) nodes).iterator();
            while (it.hasNext()) {
                assertEquals("Invalid wrapped cypher query result", TestOne.class, it.next().getClass());
                assertEquals("Invalid wrapped cypher query result", TestSix.class, it.next().getClass());
            }
            for (final Object node : ((Collection) rels)) {
                assertEquals("Invalid wrapped cypher query result", SixOneManyToMany.class, node.getClass());
            }
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN DISTINCT { path: p, value: 12 } ");
        assertEquals("Invalid wrapped cypher query result", 100, result.size());
        final Iterator it = result.iterator();
        while (it.hasNext()) {
            final Object path = it.next();
            final Object value = it.next();
            assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, path.getClass());
            assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, value.getClass());
            assertEquals("Invalid wrapped cypher query result", 12L, ((GraphObjectMap) value).getProperty(new StringProperty("value")));
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    try (final Tx tx = app.tx()) {
        final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN { nodes: { x : { y : { z : nodes(p) } } } } ");
        assertEquals("Invalid wrapped cypher query result", 100, result.size());
        for (final GraphObject obj : result) {
            assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());
            final Object nodes = obj.getProperty(new StringProperty("nodes"));
            assertTrue("Invalid wrapped cypher query result", nodes instanceof GraphObjectMap);
            final Object x = ((GraphObjectMap) nodes).getProperty(new StringProperty("x"));
            assertTrue("Invalid wrapped cypher query result", x instanceof GraphObjectMap);
            final Object y = ((GraphObjectMap) x).getProperty(new StringProperty("y"));
            assertTrue("Invalid wrapped cypher query result", y instanceof GraphObjectMap);
            final Object z = ((GraphObjectMap) y).getProperty(new StringProperty("z"));
            assertTrue("Invalid wrapped cypher query result", z instanceof Collection);
        }
        tx.success();
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
/*
		try (final Tx tx = app.tx()) {

			final List<GraphObject> result = app.command(CypherQueryCommand.class).execute("MATCH p = (n:TestOne)-[r]-(m:TestSix) RETURN p");

			assertEquals("Invalid wrapped cypher query result", 100, result.size());

			for (final GraphObject obj : result) {

				assertEquals("Invalid wrapped cypher query result", GraphObjectMap.class, obj.getClass());

				final Object paths = obj.getProperty(new StringProperty("p"));

				assertTrue("Invalid wrapped cypher query result", paths instanceof Iterable);

				final Iterator it = ((Iterable)paths).iterator();
				while (it.hasNext()) {

					assertEquals("Invalid wrapped cypher query result", TestOne.class, it.next().getClass());		// n
					assertEquals("Invalid wrapped cypher query result", SixOneManyToMany.class, it.next().getClass());	// r
					assertEquals("Invalid wrapped cypher query result", TestSix.class, it.next().getClass());		// m
				}
			}

			tx.success();


		} catch (FrameworkException ex) {
			logger.error("", ex);
		}
		*/
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StringProperty(org.structr.core.property.StringProperty) GraphObject(org.structr.core.GraphObject) GraphObjectMap(org.structr.core.GraphObjectMap) Iterator(java.util.Iterator) Collection(java.util.Collection) GraphObject(org.structr.core.GraphObject) TestOne(org.structr.core.entity.TestOne) CypherQueryCommand(org.structr.core.graph.CypherQueryCommand) 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