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.");
}
}
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");
}
}
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");
}
}
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");
}
}
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);
}
*/
}
Aggregations