@Documented( "Get node.\n" + "\n" + "Note that the response contains URI/templates for the available\n" + "operations for getting properties and relationships." ) @Test public void shouldGet200WhenRetrievingNode() { String uri = nodeUri.toString(); gen.get() .expectedStatus( 200 ) .get( uri ); }
@Test @Documented( "When sending queries that\n" + "return nested results like list and maps,\n" + "these will get serialized into nested JSON representations\n" + "according to their types." ) @Graph( value = {"I know you"}, autoIndexNodes = true ) public void nested_results() throws Exception { data.get(); String script = "MATCH (n) WHERE n.name in ['I', 'you'] RETURN collect(n.name)"; String response = cypherRestCall( script, Status.OK ); Map<String,Object> resultMap = jsonToMap( response ); assertEquals( 2, resultMap.size() ); assertThat( response, anyOf( containsString( "\"I\",\"you\"" ), containsString( "\"you\",\"I\"" ), containsString( "\"I\", \"you\"" ), containsString( "\"you\", \"I\"" ) ) ); }
@Test @Graph( "jim knows joe" ) public void shouldReturn400WhenSendinIncompatibleJsonProperties() { Map<String, Object> map = new HashMap<>(); map.put( "jim", new HashMap<String, Object>() ); gen.get().payload( JsonHelper.createJsonFrom( map ) ).expectedStatus( 400 ).put( getPropertiesUri( data.get().get( "jim" ) ) ); }
@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" ); }
@Documented( "Delete all properties from node." ) @Test public void shouldReturn204WhenAllPropertiesAreRemoved() { long nodeId = helper.createNode(); Map<String, Object> map = new HashMap<>(); map.put( "jim", "tobias" ); helper.setNodeProperties( nodeId, map ); gen.get().expectedStatus( 204 ) .delete( functionalTestHelper.nodePropertiesUri( nodeId ) ); }
@Test @Graph( { "a TO b", "b TO c", "c TO a" } ) public void canCreateGraphFromMultipleStrings() { Map<String,Node> graph = data.get(); Set<Node> unique = new HashSet<>(); Node n = graph.get( "a" ); while ( unique.add( n ) ) { try ( Transaction ignored = graphdb.beginTx() ) { n = n.getSingleRelationship( RelationshipType.withName( "TO" ), Direction.OUTGOING ).getEndNode(); } } assertEquals( graph.size(), unique.size() ); }
@Documented( "Get non-existent node." ) @Test public void shouldGet404WhenRetrievingNonExistentNode() throws Exception { long nonExistentNode = helper.createNode(); helper.deleteNode( nonExistentNode ); URI nonExistentNodeUri = new URI( functionalTestHelper.nodeUri() + "/" + nonExistentNode ); gen.get() .expectedStatus( 404 ) .get( nonExistentNodeUri.toString() ); }
/** * 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(); }
@Documented( "Property values can not be null.\n" + "\n" + "This example shows the response you get when trying to set a property to +null+." ) @Test public void shouldGet400WhenSupplyingNullValueForAProperty() { gen.get() .payload( "{\"foo\":null}" ) .expectedStatus( 400 ) .post( functionalTestHelper.nodeUri() ); }
@Documented( "Property values can not be nested.\n" + "\n" + "Nesting properties is not supported. You could for example store the\n" + "nested JSON as a string instead." ) @Test public void shouldReturn400WhenSendinIncompatibleJsonProperty() { gen.get() .payload( "{\"foo\" : {\"bar\" : \"baz\"}}" ) .expectedStatus( 400 ).post( getDataUri() + "node/" ); }
/** * 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( "To delete a single property\n" + "from a node, see the example below" ) @Test public void delete_a_named_property_from_a_node() { long nodeId = helper.createNode(); Map<String, Object> map = new HashMap<>(); map.put( "name", "tobias" ); helper.setNodeProperties( nodeId, map ); gen.get() .expectedStatus( 204 ) .delete( functionalTestHelper.nodePropertyUri( nodeId, "name") ); }
@Test @Graph( "Joe knows Sara" ) public void providing_bad_JSON() { String jsonString = "{\"to\" : \"" + getNodeUri( data.get().get( "Joe" ) ) + "\", \"type\" : \"LOVES\", \"data\" : {\"foo\" : **BAD JSON HERE*** \"bar\"}}"; gen.get().expectedStatus( Status.BAD_REQUEST.getStatusCode() ).payload( jsonString ).post( getNodeUri( getNode( "Joe" ) ) + "/relationships" ).entity(); }
@Documented( "Delete node." ) @Test public void shouldRespondWith204WhenNodeDeleted() { long node = helper.createNode(); gen.get().expectedStatus( 204 ) .delete( functionalTestHelper.dataUri() + "node/" + node ); }
/** * 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 @Documented( "When auth is disabled\n" + "\n" + "When auth has been disabled in the configuration, requests can be sent without an +Authorization+ header." ) public void auth_disabled() throws IOException { // Given startServer( false ); // Document gen.get() .expectedStatus( 200 ) .get( dataURL() ); }