public T get() { return get( true ); }
public static <T> TestData<T> producedThrough( Producer<T> transformation ) { Objects.requireNonNull( transformation ); return new TestData<>( transformation ); }
public RESTRequestGenerator gen() { return gen.get(); }
protected Node getNode( String name ) { return data.get().get( name ); }
protected String createScript( String template ) { for ( String key : data.get().keySet() ) { template = template.replace( "%" + key + "%", idFor( key ).toString() ); } return template; }
private Long idFor( String name ) { return data.get().get( name ).getId(); }
@Test public void havingNoGraphAnnotationCreatesAnEmptyDataCollection() { assertTrue( "collection was not empty", data.get().isEmpty() ); }
@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( "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 ); }
private void setEnabledAutoIndexingForType( String uriPartForType, boolean enabled ) { gen.get() .expectedStatus( 204 ) .payload( Boolean.toString( enabled ) ) .put( autoIndexURI( uriPartForType ) + "/status" ); }
@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\"" ) ) ); }
private void checkAndAssertAutoIndexerIsEnabled( String uriPartForType, boolean enabled ) { String result = gen.get() .expectedStatus( 200 ) .get( autoIndexURI( uriPartForType ) + "/status" ).entity(); assertEquals( enabled, Boolean.parseBoolean( result ) ); }
@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" ); }
/** * 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(); }
/** * Remove a property for autoindexing on nodes. */ @Test public void removeAutoIndexingPropertyForNodes() { gen.get() .expectedStatus( 204 ) .delete( autoIndexURI( "node" ) + "/properties/myProperty1" ); }
@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 ) ); }
@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() ); }
@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(); }
/** * 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") ); }