public static TypeSafeDiagnosingMatcher<Node> hasNoLabels() { return hasLabels( emptySet() ); }
public static TypeSafeDiagnosingMatcher<Node> hasLabels( String... expectedLabels ) { return hasLabels( asSet( expectedLabels ) ); }
public static TypeSafeDiagnosingMatcher<Node> hasLabels( Label... expectedLabels ) { Set<String> labelNames = new HashSet<>( expectedLabels.length ); for ( Label l : expectedLabels ) { labelNames.add( l.name() ); } return hasLabels( labelNames ); }
@Test public void createNodeWithLabels() { // GIVEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); // WHEN Node node = null; try ( Transaction tx = db.beginTx() ) { node = db.createNode( Labels.values() ); tx.success(); } // THEN Set<String> names = Stream.of( Labels.values() ).map( Labels::name ).collect( toSet() ); assertThat( node, inTx( db, hasLabels( names ) ) ); }
@Documented( "Adding multiple labels to a node." ) @Test @GraphDescription.Graph( nodes = { @NODE( name = "Clint Eastwood", setNameProperty = true ) } ) public void adding_multiple_labels_to_a_node() { Map<String,Node> nodes = data.get(); String nodeUri = getNodeUri( nodes.get( "Clint Eastwood" ) ); gen.get() .expectedStatus( 204 ) .payload( createJsonFrom( new String[]{"Person", "Actor"} ) ) .post( nodeUri + "/labels" ); // Then assertThat( nodes.get( "Clint Eastwood" ), inTx( graphdb(), hasLabels( "Person", "Actor" ) ) ); }
@Documented( "Replacing labels on a node.\n" + "\n" + "This removes any labels currently on a node, and replaces them with the labels passed in as the\n" + "request body." ) @Test @GraphDescription.Graph( nodes = { @NODE( name = "Clint Eastwood", setNameProperty = true, labels = {@LABEL( "Person" )} )} ) public void replacing_labels_on_a_node() { Map<String,Node> nodes = data.get(); String nodeUri = getNodeUri( nodes.get( "Clint Eastwood" ) ); // When gen.get() .expectedStatus( 204 ) .payload( createJsonFrom( new String[]{"Actor", "Director"}) ) .put( nodeUri + "/labels" ); // Then assertThat( nodes.get( "Clint Eastwood" ), inTx(graphdb(), hasLabels("Actor", "Director")) ); }
@Test public void shouldBeAbleToListLabelsForANode() { // GIVEN GraphDatabaseService beansAPI = dbRule.getGraphDatabaseAPI(); Node node = null; Set<String> expected = asSet( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() ); try ( Transaction tx = beansAPI.beginTx() ) { node = beansAPI.createNode(); for ( String label : expected ) { node.addLabel( label( label ) ); } tx.success(); } assertThat( node, inTx( beansAPI, hasLabels( expected ) ) ); }