private String doExportGraph( GraphDatabaseService db ) { SubGraph graph = DatabaseSubGraph.from( db ); return doExportGraph( graph ); }
@Test public void testEmptyGraph() { assertEquals( "", doExportGraph( gdb ) ); }
@Test public void testNodeWithDoubleProperty() { final double doubleValue = 123456.123456; final String expected = "123456.123456"; gdb.createNode().setProperty( "double", doubleValue ); assertEquals( "create (_0 {`double`:" + expected + "})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( gdb ) ); }
@Test public void testNodeWithFloatProperty() { final float floatValue = 10.1f; final String expected = "10.100000"; gdb.createNode().setProperty( "float", floatValue ); assertEquals( "create (_0 {`float`:" + expected + "})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( gdb ) ); }
@Test public void testNodeWithProperties() { gdb.createNode().setProperty( "name", "Andres" ); assertEquals( "create (_0 {`name`:\"Andres\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( gdb ) ); }
@Test public void testFromRelCypherResult() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL`]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testSingleNode() { Node n = gdb.createNode(); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + ")" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testFromSimpleCypherResult() { Node n = gdb.createNode(); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + ")" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfRelationshipStringPropertyValue() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); rel.setProperty( "name", "Brutus \"Brutal\" Howell" ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL` {`name`:\"Brutus \\\"Brutal\\\" Howell\"}]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfRelationshipStringArrayPropertyValue() { Node n = gdb.createNode(); final Relationship rel = n.createRelationshipTo( n, RelationshipType.withName( "REL" ) ); rel.setProperty( "name", new String[]{"Brutus \"Brutal\" Howell", "Dr."} ); final ExecutionResult result = result( "rel", rel ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create (_0)" + lineSeparator() + "create (_0)-[:`REL` {`name`:[\"Brutus \\\"Brutal\\\" Howell\", \"Dr.\"]}]->(_0)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfNodeStringArrayPropertyValue() { Node n = gdb.createNode(); n.setProperty( "name", new String[]{"Brutus \"Brutal\" Howell", "Dr."} ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:[\"Brutus \\\"Brutal\\\" Howell\", \"Dr.\"]})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingStringPropertyWithBackslashAndDoubleQuote() { Node n = gdb.createNode(); n.setProperty( "name", "Some\\\"thing" ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:\"Some\\\\\\\"thing\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingStringPropertyWithBackslash() { Node n = gdb.createNode(); n.setProperty( "name", "Some\\thing" ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:\"Some\\\\thing\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testEscapingOfNodeStringPropertyValue() { Node n = gdb.createNode(); n.setProperty( "name", "Brutus \"Brutal\" Howell" ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`name`:\"Brutus \\\"Brutal\\\" Howell\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testSingleNodeWithProperties() { Node n = gdb.createNode(); n.setProperty( "name", "Node1" ); n.setProperty( "age", 42 ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`age`:42, `name`:\"Node1\"})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testSingleNodeWithArrayProperties() { Node n = gdb.createNode(); n.setProperty( "name", new String[]{"a", "b"} ); n.setProperty( "age", new int[]{1, 2} ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + " {`age`:[1, 2], `name`:[\"a\", \"b\"]})" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testExportUniquenessConstraint() { gdb.schema().constraintFor( Label.label( "Foo" ) ).assertPropertyIsUnique( "bar" ).create(); assertEquals( "create constraint on (n:`Foo`) assert n.`bar` is unique;" + lineSeparator(), doExportGraph( gdb ) ); }
@Test public void testExportIndex() { gdb.schema().indexFor( Label.label( "Foo" ) ).on( "bar" ).create(); assertEquals( "create index on :`Foo`(`bar`);" + lineSeparator() , doExportGraph( gdb ) ); }
@Test public void testSingleNodeLabels() { Node n = gdb.createNode(); n.addLabel( Label.label( "Foo" ) ); n.addLabel( Label.label( "Bar" ) ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, false ); assertEquals( "create (_" + n.getId() + ":`Foo`:`Bar`)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }
@Test public void testExportConstraintsViaCypherResult() { final Label label = Label.label( "Foo" ); gdb.schema().constraintFor( label ).assertPropertyIsUnique( "bar" ).create(); gdb.schema().constraintFor( label ).assertPropertyIsUnique( "bar2" ).create(); commitAndStartNewTransactionAfterSchemaChanges(); Node n = gdb.createNode( label ); final ExecutionResult result = result( "node", n ); final SubGraph graph = CypherResultSubGraph.from( result, gdb, true ); assertEquals( "create constraint on (n:`Foo`) assert n.`bar2` is unique;" + lineSeparator() + "create constraint on (n:`Foo`) assert n.`bar` is unique;" + lineSeparator() + "create (_0:`Foo`)" + lineSeparator() + ";" + lineSeparator(), doExportGraph( graph ) ); }