Refine search
@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 @Title( "Errors" ) @Documented( "Errors on the server will be reported as a JSON-formatted message, exception name and stacktrace." ) @Graph( "I know you" ) public void error_gets_returned_as_json() throws Exception { String response = cypherRestCall( "MATCH (x {name: 'I'}) RETURN x.dummy/0", Status.BAD_REQUEST ); Map<String,Object> output = jsonToMap( response ); assertTrue( output.toString(), output.containsKey( "message" ) ); assertTrue( output.containsKey( "exception" ) ); assertTrue( output.containsKey( "stackTrace" ) ); }
@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 @Title( "Return paths" ) @Documented( "Paths can be returned just like other return types." ) @Graph( "I know you" ) public void return_paths() throws Exception { String script = "MATCH path = (x {name: 'I'})--(friend) RETURN path, friend.name"; String response = cypherRestCall( script, Status.OK ); assertEquals( 2, (jsonToMap( response )).size() ); assertThat( response, containsString( "data" ) ); assertThat( response, containsString( "you" ) ); }
@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 @Title( "Retrieve query metadata" ) @Documented( "By passing in an additional GET parameter when you execute Cypher queries, metadata about the " + "query will be returned, such as how many labels were added or removed by the query." ) @Graph( nodes = {@NODE( name = "I", setNameProperty = true, labels = {@LABEL( "Director" )} )} ) public void testQueryStatistics() throws JsonParseException { // Given String script = createScript( "MATCH (n {name: 'I'}) SET n:Actor REMOVE n:Director RETURN labels(n)" ); // When Map<String,Object> output = jsonToMap( doCypherRestCall( cypherUri() + "?includeStats=true", script, Status.OK ) ); // Then @SuppressWarnings( "unchecked" ) Map<String,Object> stats = (Map<String,Object>) output.get( "stats" ); assertThat( stats, isA( Map.class ) ); assertThat( stats.get( "contains_updates" ), is( true ) ); assertThat( stats.get( "labels_added" ), is( 1 ) ); assertThat( stats.get( "labels_removed" ), is( 1 ) ); assertThat( stats.get( "nodes_created" ), is( 0 ) ); assertThat( stats.get( "nodes_deleted" ), is( 0 ) ); assertThat( stats.get( "properties_set" ), is( 0 ) ); assertThat( stats.get( "relationships_created" ), is( 0 ) ); assertThat( stats.get( "relationship_deleted" ), is( 0 ) ); }
@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() ); }
@Documented( "Delete node index." ) @Test public void shouldReturn204WhenRemovingNodeIndexes() { final String indexName = indexes.newInstance(); helper.createNodeIndex( indexName ); gen() .expectedStatus( 204 ) .delete( functionalTestHelper.indexNodeUri( indexName ) ); }
@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( "List node indexes." ) @Test public void shouldGetListOfNodeIndexesWhenOneExist() throws JsonParseException { String indexName = indexes.newInstance(); helper.createNodeIndex( indexName ); String entity = gen() .expectedStatus( 200 ) .get( functionalTestHelper.nodeIndexUri() ) .entity(); Map<String, Object> map = JsonHelper.jsonToMap( entity ); assertNotNull( map.get( indexName ) ); HashMap<String,Object> theIndex = new HashMap<>(); theIndex.put( indexName, map.get( indexName ) ); assertEquals( "Was: " + theIndex + ", no-auto-index:" + functionalTestHelper.removeAnyAutoIndex( theIndex ), 1, functionalTestHelper.removeAnyAutoIndex( theIndex ).size() ); }
@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/" ); }
@Test @Title( "Send a query" ) @Documented( "A simple query returning all nodes connected to some node, returning the node and the name " + "property, if it exists, otherwise `NULL`:" ) @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 testPropertyColumn() { String script = createScript( "MATCH (x {name: 'I'})-[r]->(n) RETURN type(r), n.name, n.age" ); String response = cypherRestCall( script, Status.OK ); assertThat( response, containsString( "you" ) ); assertThat( response, containsString( "him" ) ); assertThat( response, containsString( "25" ) ); assertThat( response, not( containsString( "\"x\"" ) ) ); }
@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 @Title( "Profile a query" ) @Documented( "By passing in an extra parameter, you can ask the cypher executor to return a profile of the " + "query as it is executed. This can help in locating bottlenecks." ) @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 testProfiling() throws Exception { String script = createScript( "MATCH (x)-[r]->(n) WHERE id(x) = %I% RETURN type(r), n.name, n.age" ); // WHEN String response = doCypherRestCall( cypherUri() + "?profile=true", script, Status.OK ); // THEN Map<String,Object> des = jsonToMap( response ); assertThat( des.get( "plan" ), instanceOf( Map.class ) ); @SuppressWarnings( "unchecked" ) Map<String,Object> plan = (Map<String,Object>) des.get( "plan" ); assertThat( plan.get( "name" ), instanceOf( String.class ) ); assertThat( plan.get( "children" ), instanceOf( Collection.class ) ); assertThat( plan.get( "rows" ), instanceOf( Number.class ) ); assertThat( plan.get( "dbHits" ), instanceOf( Number.class ) ); }
@Documented( "Delete node." ) @Test public void shouldRespondWith204WhenNodeDeleted() { long node = helper.createNode(); gen.get().expectedStatus( 204 ) .delete( functionalTestHelper.dataUri() + "node/" + node ); }
@Documented( "Create node index with configuration.\n\n" + "This request is only necessary if you want to customize the index settings. \n" + "If you are happy with the defaults, you can just start indexing nodes/relationships, as\n" + "non-existent indexes will automatically be created as you do. See\n" + "<<indexing-create-advanced>> for more information on index configuration." ) @Test public void shouldCreateANamedNodeIndexWithConfiguration() { int expectedIndexes = helper.getNodeIndexes().length + 1; gen() .payload( "{\"name\":\"fulltext\", \"config\":{\"type\":\"fulltext\",\"provider\":\"lucene\"}}" ) .expectedStatus( 201 ) .expectedHeader( "Location" ) .post( functionalTestHelper.nodeIndexUri() ); assertEquals( expectedIndexes, helper.getNodeIndexes().length ); assertThat( helper.getNodeIndexes(), FunctionalTestHelper.arrayContains( "fulltext" ) ); }
@Test @Title( "Create a node with multiple properties" ) @Documented( "Create a node with a label and multiple properties using Cypher. See the request for the parameter " + "sent with the query." ) @Graph public void send_query_to_create_a_node_from_a_map() { data.get(); String script = "CREATE (n:Person { props } ) RETURN n"; String params = "\"props\" : { \"position\" : \"Developer\", \"name\" : \"Michael\", \"awesome\" : true, \"children\" : 3 }"; String response = cypherRestCall( script, Status.OK, params ); assertTrue( response.contains( "name" ) ); assertTrue( response.contains( "Michael" ) ); }
/** * This example is showing a group count in Gremlin, for instance the * counting of the different relationship types connected to some the start * node. The result is collected into a variable that then is returned. */ @Test @Documented @Graph( { "Peter knows Ian", "Ian knows Peter", "Peter likes Bikes" } ) public void group_count() throws UnsupportedEncodingException, Exception { String script = "m = [:];" + "g.v(%Peter%).bothE().label.groupCount(m).iterate();m"; String response = doRestCall( script, OK ); assertTrue( response.contains( "\"knows\" : 2" ) ); }
@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() ); }
/** * Multiple traversals can be combined into a single result, using splitting * and merging pipes in a lazy fashion. */ @Test @Documented @Graph( value = { "Peter knows Ian", "Ian knows Peter", "Marie likes Peter" }, autoIndexNodes = true ) public void collect_multiple_traversal_results() throws UnsupportedEncodingException, Exception { String script = "g.idx('node_auto_index')[[name:'Peter']].copySplit(_().out('knows'), _().in('likes')).fairMerge.name"; String response = doRestCall( script, OK ); assertTrue( response.contains( "Marie" ) ); assertTrue( response.contains( "Ian" ) ); }