private Node createNode( Label... labels ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( labels ); tx.success(); return node; } }
@Test public void queryResultsMustIncludeNodesWithPropertiesAddedToBeIndexed() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleNodesIndex(); tx.success(); } long nodeId; try ( Transaction tx = db.beginTx() ) { awaitIndexesOnline(); nodeId = db.createNode( LABEL ).getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.getNodeById( nodeId ).setProperty( PROP, "value" ); assertQueryFindsIds( db, true, "nodes", "prop:value", nodeId ); tx.success(); } }
@Test public void queryNodesMustThrowWhenQueryingRelationshipIndex() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } awaitIndexesOnline(); try ( Transaction tx = db.beginTx() ) { expectedException.expect( Exception.class ); db.execute( format( QUERY_NODES, "rels", "bla bla" ) ).close(); tx.success(); } }
@Test public void shouldRenderNestedEntities() throws Exception { try ( Transaction ignored = database.getGraphDatabaseAPI().beginTx() ) { GraphDatabaseService graphdb = database.getGraphDatabaseAPI(); graphdb.execute( "CREATE (n {name: 'Sally'}), (m {age: 42}), (n)-[r:FOO {drunk: false}]->(m)" ); Result result = graphdb.execute( "MATCH p=(n)-[r]->(m) RETURN n, r, p, {node: n, edge: r, path: p}" ); CypherResultRepresentation representation = new CypherResultRepresentation( result, false, false ); // When Map<String, Object> serialized = serializeToStringThenParseAsToMap( representation ); // Then Object firstRow = ((List) serialized.get( "data" )).get( 0 ); Map nested = (Map) ((List) firstRow).get( 3 ); assertThat( nested.get( "node" ), is( equalTo( ((List) firstRow).get( 0 ) ) ) ); assertThat( nested.get( "edge" ), is( equalTo( ((List) firstRow).get( 1 ) ) ) ); assertThat( nested.get( "path" ), is( equalTo( ((List) firstRow).get( 2 ) ) ) ); } }
@Test public void queryRelationshipsMustThrowWhenQueryingNodeIndex() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleNodesIndex(); tx.success(); } awaitIndexesOnline(); try ( Transaction tx = db.beginTx() ) { expectedException.expect( Exception.class ); db.execute( format( QUERY_RELS, "nodes", "bla bla" ) ).close(); tx.success(); } }
@Test public void queryResultsMustNotIncludeNodesWithRemovedIndexedLabels() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleNodesIndex(); tx.success(); } long nodeId; try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( LABEL ); node.setProperty( PROP, "value" ); nodeId = node.getId(); tx.success(); } try ( Transaction tx = db.beginTx() ) { db.getNodeById( nodeId ).removeLabel( LABEL ); assertQueryFindsIds( db, true, "nodes", "nodes" ); tx.success(); } }
private Node createLabeledNode() { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( LABEL ); tx.success(); return node; } }
@Test public void queryingDroppedIndexForNodesInDroppingTransactionMustThrow() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleNodesIndex(); tx.success(); } awaitIndexesOnline(); try ( Transaction tx = db.beginTx() ) { db.execute( format( DROP, "nodes" ) ).close(); expectedException.expect( QueryExecutionException.class ); db.execute( format( QUERY_NODES, "nodes", "blabla" ) ); } }
@Test public void shouldWarnOnLargeLabelScansWithLoadCVSMatch() { for ( int i = 0; i < 11; i++ ) { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "A" ) ); tx.success(); } } Stream.of( "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> assertNotifications( version + "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MATCH (a:A) RETURN *", containsNoItem( largeLabelCSVWarning ) ) ); }
private void createNode( GraphDatabaseAPI db, String name ) { try ( Transaction tx = db.beginTx() ) { db.createNode( LABEL ).setProperty( KEY, name ); tx.success(); } }
@Test public void queryingDroppedIndexForRelationshipsInDroppingTransactionMustThrow() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } awaitIndexesOnline(); try ( Transaction tx = db.beginTx() ) { db.execute( format( DROP, "rels" ) ).close(); expectedException.expect( QueryExecutionException.class ); db.execute( format( QUERY_RELS, "rels", "blabla" ) ); } }
@Test public void shouldNotWarnOnSmallLabelScansWithLoadCVS() { try ( Transaction tx = db().beginTx() ) { db().createNode().addLabel( label( "A" ) ); tx.success(); } Stream.of( "CYPHER 3.1", "CYPHER 3.5" ).forEach( version -> { shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MATCH (a:A) RETURN *" ); shouldNotNotifyInStream( version, "EXPLAIN LOAD CSV FROM 'file:///ignore/ignore.csv' AS line MERGE (a:A) RETURN *" ); } ); }
private Node createNodeWithProperty( String key, String value, Label... labels ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( labels ); node.setProperty( key, value ); tx.success(); return node; } }