@Test public void removingNonExistentLabel() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; // When Node myNode; try ( Transaction tx = beansAPI.beginTx() ) { myNode = beansAPI.createNode(); myNode.removeLabel( label ); tx.success(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); }
@Test public void removingCommittedLabel() { // Given GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; Node myNode = createNode( graphDatabase, label ); // When try ( Transaction tx = graphDatabase.beginTx() ) { myNode.removeLabel( label ); tx.success(); } // Then assertThat( myNode, not( inTx( graphDatabase, hasLabel( label ) ) ) ); }
@Test public void removingExistingLabelFromUnlabeledNode() { // Given GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Label label = Labels.MY_LABEL; createNode( beansAPI, label ); Node myNode = createNode( beansAPI ); // When try ( Transaction tx = beansAPI.beginTx() ) { myNode.removeLabel( label ); tx.success(); } // THEN assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ); }
@Documented( "Removing a non-existent label from a node." ) @Test @GraphDescription.Graph( nodes = { @NODE( name = "Clint Eastwood", setNameProperty = true ) } ) public void removing_a_non_existent_label_from_a_node() { Map<String,Node> nodes = data.get(); Node node = nodes.get( "Clint Eastwood" ); String nodeUri = getNodeUri( node ); String labelName = "Person"; gen.get() .expectedStatus( 204 ) .delete( nodeUri + "/labels/" + labelName ); assertThat( node, inTx( graphdb(), not( hasLabel( label( labelName ) ) ) ) ); }
@Documented( "Removing a label from a node." ) @Test @GraphDescription.Graph( nodes = { @NODE( name = "Clint Eastwood", setNameProperty = true, labels = { @LABEL( "Person" ) } ) } ) public void removing_a_label_from_a_node() { Map<String,Node> nodes = data.get(); Node node = nodes.get( "Clint Eastwood" ); String nodeUri = getNodeUri( node ); String labelName = "Person"; gen.get() .expectedStatus( 204 ) .delete( nodeUri + "/labels/" + labelName ); assertThat( node, inTx( graphdb(), not( hasLabel( label( labelName ) ) ) ) ); }
@Test public void addingALabelUsingAValidIdentifierShouldSucceed() { // Given GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseAPI(); Node myNode = null; // When try ( Transaction tx = graphDatabase.beginTx() ) { myNode = graphDatabase.createNode(); myNode.addLabel( Labels.MY_LABEL ); tx.success(); } // Then assertThat( "Label should have been added to node", myNode, inTx( graphDatabase, hasLabel( Labels.MY_LABEL ) ) ); }
@Test public void addingALabelThatAlreadyExistsBehavesAsNoOp() { // Given GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseAPI(); Node myNode = null; // When try ( Transaction tx = graphDatabase.beginTx() ) { myNode = graphDatabase.createNode(); myNode.addLabel( Labels.MY_LABEL ); myNode.addLabel( Labels.MY_LABEL ); tx.success(); } // Then assertThat( "Label should have been added to node", myNode, inTx( graphDatabase, hasLabel( Labels.MY_LABEL ) ) ); }