Refine search
@Test public void canCreateRelationshipBetweenTwoNodesWithLoopsThenDeleteOneOfTheNodesAndItsRelationships() { Node source = getGraphDb().createNode(); Node target = getGraphDb().createNode(); source.createRelationshipTo( source, TEST ); target.createRelationshipTo( target, TEST ); source.createRelationshipTo( target, TEST ); newTransaction(); for ( Relationship rel : target.getRelationships() ) { rel.delete(); } target.delete(); }
@Test( expected = NotFoundException.class ) public void deletionOfAlreadyDeletedRelationshipShouldThrow() { // Given GraphDatabaseService db = getGraphDb(); // transaction is opened by test Node node1 = db.createNode(); Node node2 = db.createNode(); Relationship relationship = node1.createRelationshipTo( node2, TEST ); commit(); try ( Transaction tx = db.beginTx() ) { relationship.delete(); tx.success(); } // When try ( Transaction tx = db.beginTx() ) { relationship.delete(); tx.success(); } }
@Test public void shouldAdvertiseRelationshipTypesThatCurrentlyExistInTheDatabase() throws Throwable { try ( Transaction tx = db.beginTx() ) { db.getRelationshipById( relId ).delete(); tx.success(); } Database database = new WrappedDatabase( db ); DatabaseMetadataService service = new DatabaseMetadataService( database ); try ( Transaction tx = db.beginTx() ) { Response response = service.getRelationshipTypes( false ); assertEquals( 200, response.getStatus() ); List<Map<String,Object>> jsonList = JsonHelper.jsonToList( response.getEntity() .toString() ); assertEquals( 3, jsonList.size() ); } database.stop(); }
d = graphDb.createNode(); a.createRelationshipTo( a, withName( "ALPHA" ) ); a.createRelationshipTo( b, withName( "BETA" ) ); a.createRelationshipTo( c, withName( "GAMMA" ) ); a.createRelationshipTo( d, withName( "DELTA" ) ); dead.delete(); node.delete();
private void testGetRelationshipTypes( Node node, Set<String> expectedTypes ) { assertExpectedRelationshipTypes( expectedTypes, node, false ); node.createRelationshipTo( getGraphDb().createNode(), RelType.TYPE1 ); expectedTypes.add( RelType.TYPE1.name() ); assertExpectedRelationshipTypes( expectedTypes, node, false ); node.createRelationshipTo( getGraphDb().createNode(), RelType.TYPE1 ); assertExpectedRelationshipTypes( expectedTypes, node, true ); Relationship rel = node.createRelationshipTo( getGraphDb().createNode(), RelType.TYPE2 ); expectedTypes.add( RelType.TYPE2.name() ); assertExpectedRelationshipTypes( expectedTypes, node, false ); rel.delete(); expectedTypes.remove( RelType.TYPE2.name() ); assertExpectedRelationshipTypes( expectedTypes, node, true ); node.createRelationshipTo( getGraphDb().createNode(), RelType.TYPE2 ); node.createRelationshipTo( getGraphDb().createNode(), RelType.TYPE2 ); expectedTypes.add( RelType.TYPE2.name() ); node.createRelationshipTo( getGraphDb().createNode(), MyRelTypes.TEST ); expectedTypes.add( MyRelTypes.TEST.name() ); assertExpectedRelationshipTypes( expectedTypes, node, true ); for ( Relationship r : node.getRelationships( RelType.TYPE1 ) ) { assertExpectedRelationshipTypes( expectedTypes, node, false ); r.delete(); } expectedTypes.remove( RelType.TYPE1.name() ); assertExpectedRelationshipTypes( expectedTypes, node, true ); }
@Test public void testDeletedRelationship() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship relationship = node1.createRelationshipTo( node2, TEST ); relationship.delete(); try { relationship.setProperty( "key1", 1 ); fail( "Adding property to deleted rel should throw exception." ); } catch ( Exception e ) { // good } node1.delete(); node2.delete(); }
@Test public void shouldAllowToStringOnCreatedRelationshipInAfterCommit() relationship = startNode.createRelationshipTo( endNode, type ); tx.success(); try ( Transaction tx = dbRule.beginTx() ) relationship.delete(); tx.success();
@Test public void shouldAdvertiseRelationshipTypesThatCurrentlyInUseInTheDatabase() throws Throwable { try ( Transaction tx = db.beginTx() ) { db.getRelationshipById( relId ).delete(); tx.success(); } Database database = new WrappedDatabase( db ); DatabaseMetadataService service = new DatabaseMetadataService( database ); try ( Transaction tx = db.beginTx() ) { Response response = service.getRelationshipTypes( true ); assertEquals( 200, response.getStatus() ); List<Map<String,Object>> jsonList = JsonHelper.jsonToList( response.getEntity() .toString() ); assertEquals( 2, jsonList.size() ); } database.stop(); } }
@Test public void createBatchNodeAndRelationshipsDeleteAllInEmbedded() throws Exception { /* * ()--[REL_TYPE1]-->(node)--[BATCH_TEST]->() */ BatchInserter inserter = newBatchInserter(); long nodeId = inserter.createNode( null ); inserter.createRelationship( nodeId, inserter.createNode( null ), RelTypes.BATCH_TEST, null ); inserter.createRelationship( inserter.createNode( null ), nodeId, RelTypes.REL_TYPE1, null ); // Delete node and all its relationships GraphDatabaseService db = switchToEmbeddedGraphDatabaseService( inserter ); try ( Transaction tx = db.beginTx() ) { Node node = db.getNodeById( nodeId ); for ( Relationship relationship : node.getRelationships() ) { relationship.delete(); } node.delete(); tx.success(); } db.shutdown(); }
for ( int i = 0; i < initialSize; i++ ) me.createRelationshipTo( getGraphDb().createNode(), RelType.INITIAL ); me.createRelationshipTo( otherNode, spec.type ); otherNode.createRelationshipTo( me, spec.type ); if ( !otherNode.equals( me ) ) otherNode.delete(); rel.delete(); me.delete();
d = graphDb.createNode(), e = graphDb.createNode(), f = graphDb.createNode(); a.createRelationshipTo( b, withName( "CIRCLE" ) ); b.createRelationshipTo( c, withName( "CIRCLE" ) ); one = c.createRelationshipTo( d, withName( "CIRCLE" ) ).getId(); d.createRelationshipTo( e, withName( "CIRCLE" ) ); e.createRelationshipTo( f, withName( "CIRCLE" ) ); try ( Transaction tx = graphDb.beginTx() ) deleted.delete(); for ( Relationship relationship : graphDb.getAllRelationships() )
@Test public void testMultipleDeleteRelationship() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel = node1.createRelationshipTo( node2, MyRelTypes.TEST ); rel.delete(); node1.delete(); node2.delete(); try { rel.delete(); Transaction tx = getTransaction(); tx.success(); tx.close(); fail( "Should not validate" ); } catch ( Exception e ) { // ok } }
@Test( expected = NotFoundException.class ) public void deletionOfSameRelationshipTwiceInOneTransactionShouldNotRollbackIt() Relationship relationship = node1.createRelationshipTo( node2, TEST ); commit(); relationship.delete(); try relationship.delete();
@Test public void testDeleteReferenceNodeOrLastNodeIsOk() { Transaction tx = getTransaction(); for ( int i = 0; i < 10; i++ ) { getGraphDb().createNode(); } // long numNodesPre = getNodeManager().getNumberOfIdsInUse( Node.class // ); // empty the DB instance for ( Node node : getGraphDb().getAllNodes() ) { for ( Relationship rel : node.getRelationships() ) { rel.delete(); } node.delete(); } tx.success(); tx.close(); tx = getGraphDb().beginTx(); assertFalse( getGraphDb().getAllNodes().iterator().hasNext() ); // TODO: this should be valid, fails right now! // assertEquals( 0, numNodesPost ); tx.success(); tx.close(); }
.createRelationshipTo( random.among( nodes ), randomRelationshipType() ); if ( random.nextBoolean() ) relationship.delete(); node.delete(); nodes.remove( node ); } );