/** * Ensure that order of data and column is ok. */ @Test @Graph( nodes = {@NODE( name = "I", setNameProperty = true ), @NODE( name = "you", setNameProperty = true ), @NODE( name = "him", setNameProperty = true, properties = { @PROP( key = "age", value = "25", type = GraphDescription.PropType.INTEGER )} )}, relationships = { @REL( start = "I", end = "him", type = "know", properties = {} ), @REL( start = "I", end = "you", type = "know", properties = {} )} ) public void testDataColumnOrder() { String script = createScript( "MATCH (x)-[r]->(n) WHERE id(x) = %I% RETURN type(r), n.name, n.age" ); String response = cypherRestCall( script, Status.OK ); assertThat( response.indexOf( "columns" ) < response.indexOf( "data" ), is( true ) ); }
@Test @Graph( nodes = {@NODE( name = "I", properties = { @PROP( key = "prop", value = "Hello", type = GraphDescription.PropType.STRING )} ), @NODE( name = "you" )}, relationships = {@REL( start = "I", end = "him", type = "know", properties = { @PROP( key = "prop", value = "World", type = GraphDescription.PropType.STRING )} )} ) public void nodes_are_represented_as_nodes() { data.get(); String script = "MATCH (n)-[r]->() WHERE id(n) = %I% RETURN n, r"; String response = cypherRestCall( script, Status.OK ); assertThat( response, containsString( "Hello" ) ); assertThat( response, containsString( "World" ) ); }
@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( "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 ) ) ) ) ); }
/** * See the example request. */ @Test @Graph( nodes = {@NODE( name = "I" ), @NODE( name = "you" )}, relationships = {@REL( start = "I", end = "you", type = "know", properties = {@PROP( key = "since", value = "today" )} )}, autoIndexRelationships = true ) public void Find_relationship_by_query_from_an_automatic_index() { data.get(); assertSize( 1, gen.get() .expectedStatus( 200 ) .get( relationshipAutoIndexUri() + "?query=since:today" ) .entity() ); }
/** * The automatic relationship index can not be removed. */ @Test @Graph( nodes = {@NODE( name = "I", setNameProperty = true )}, autoIndexNodes = true ) public void Relationship_AutoIndex_is_not_removable() { data.get(); gen.get() .expectedStatus( 405 ) .delete( relationshipAutoIndexUri() ) .entity(); }
/** * Find node by query from an automatic index. * <p/> * See Find node by query for the actual query syntax. */ @Test @Graph( nodes = {@NODE( name = "I", setNameProperty = true )}, autoIndexNodes = true ) public void shouldRetrieveFromAutoIndexByQuery() { data.get(); assertSize( 1, gen.get() .expectedStatus( 200 ) .get( nodeAutoIndexUri() + "?query=name:I" ) .entity() ); }
@Test @Title( "Remove non-existent property from a relationship" ) @Documented( "Attempting to remove a property that doesn't exist results in an error." ) @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} ) public void shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationship() { data.get(); Relationship loves = getFirstRelationshipFromRomeoNode(); gen().expectedStatus( Status.NOT_FOUND.getStatusCode() ) .delete( getPropertiesUri( loves ) + "/non-existent" ).entity(); }
/** * Automatic index nodes can be found via exact lookups with normal Index * REST syntax. */ @Test @Graph( nodes = {@NODE( name = "I", setNameProperty = true )}, autoIndexNodes = true ) public void find_node_by_exact_match_from_an_automatic_index() { data.get(); assertSize( 1, gen.get() .expectedStatus( 200 ) .get( nodeAutoIndexUri() + "name/I" ) .entity() ); }
@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 @Title( "Remove properties from a relationship" ) @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} ) public void shouldReturn204WhenPropertiesAreRemovedFromRelationship() { Relationship loves = getFirstRelationshipFromRomeoNode(); gen().expectedStatus( Status.NO_CONTENT.getStatusCode() ) .delete( functionalTestHelper.relationshipPropertiesUri( loves.getId() ) ).entity(); }
/** * The automatic node index can not be removed. */ @Test @Graph( nodes = {@NODE( name = "I", setNameProperty = true )}, autoIndexNodes = true ) public void AutoIndex_is_not_removable() { gen.get() .expectedStatus( 405 ) .delete( nodeAutoIndexUri() ) .entity(); }
@Test @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} ) @Title( "Delete relationship" ) public void removeRelationship() { data.get(); Relationship loves = getFirstRelationshipFromRomeoNode(); gen().expectedStatus( Status.NO_CONTENT.getStatusCode() ).delete( getRelationshipUri( loves ) ).entity(); }
@Test @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} ) public void shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationshipStreaming() { data.get(); Relationship loves = getFirstRelationshipFromRomeoNode(); gen().withHeader( StreamingFormat.STREAM_HEADER, "true" ) .expectedStatus( Status.NOT_FOUND.getStatusCode() ) .delete( getPropertiesUri( loves ) + "/non-existent" ) .entity(); }
@Test @Title( "Remove property from a relationship" ) @Documented( "See the example request below." ) @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} ) public void shouldReturn204WhenPropertyIsRemovedFromRelationship() { data.get(); Relationship loves = getFirstRelationshipFromRomeoNode(); gen().expectedStatus( Status.NO_CONTENT.getStatusCode() ).delete( getPropertiesUri( loves ) + "/cost" ).entity(); }
@Test @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} ) public void set_single_property_on_a_relationship() { Relationship loves = getFirstRelationshipFromRomeoNode(); assertThat( loves, inTx( graphdb(), hasProperty( "cost" ).withValue( "high" ) ) ); gen().expectedStatus( ClientResponse.Status.NO_CONTENT ).payload( "\"deadly\"" ).put( getRelPropURI( loves, "cost" ) ).entity(); assertThat( loves, inTx( graphdb(), hasProperty( "cost" ).withValue( "deadly" ) ) ); }
@Documented( "Adding a label to a node." ) @Test @GraphDescription.Graph( nodes = { @NODE( name = "Clint Eastwood", setNameProperty = true ) } ) public void adding_a_label_to_a_node() { Map<String,Node> nodes = data.get(); String nodeUri = getNodeUri( nodes.get( "Clint Eastwood" ) ); gen.get() .expectedStatus( 204 ) .payload( createJsonFrom( "Person" ) ) .post( nodeUri + "/labels" ); }
@Test @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING ), @PROP( key = "since", value = "1day", type = GraphDescription.PropType.STRING )} )} ) public void get_all_properties_on_a_relationship() { Relationship loves = getFirstRelationshipFromRomeoNode(); String response = gen().expectedStatus( ClientResponse.Status.OK ).get( getRelPropsURI( loves ) ).entity(); assertTrue( response.contains( "high" ) ); }
@Test @Graph( nodes = {@NODE( name = "I", setNameProperty = true, properties = { @PROP( key = "name", value = "I" )} )}, autoIndexNodes = true ) public void canAutoIndexNodesExplicitProps() { data.get(); try ( Transaction ignored = graphdb.beginTx(); IndexHits<Node> nodes = graphdb().index().getNodeAutoIndexer().getAutoIndex().get( "name", "I" ) ) { assertTrue( "can't look up node.", nodes.hasNext() ); } }
@Test @Graph( nodes = {@NODE( name = "Romeo", setNameProperty = true ), @NODE( name = "Juliet", setNameProperty = true )}, relationships = { @REL( start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP( key = "cost", value = "high", type = GraphDescription.PropType.STRING )} )} ) public void get_single_property_on_a_relationship() { Relationship loves = getFirstRelationshipFromRomeoNode(); String response = gen().expectedStatus( ClientResponse.Status.OK ).get( getRelPropURI( loves, "cost" ) ).entity(); assertTrue( response.contains( "high" ) ); }