Skip to content

Commit

Permalink
Remove remaining docs-related stuff from server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benbc committed Oct 20, 2016
1 parent 1d314f3 commit dfb003d
Show file tree
Hide file tree
Showing 28 changed files with 85 additions and 276 deletions.
Expand Up @@ -19,16 +19,15 @@
*/
package org.neo4j.server.rest;

import org.junit.Before;
import org.junit.Rule;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import javax.ws.rs.core.Response.Status;

import org.junit.Rule;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
Expand All @@ -45,15 +44,16 @@

import static java.lang.String.format;
import static java.net.URLEncoder.encode;

import static org.junit.Assert.assertEquals;

import static org.neo4j.server.rest.domain.JsonHelper.createJsonFrom;
import static org.neo4j.server.rest.web.Surface.PATH_NODES;
import static org.neo4j.server.rest.web.Surface.PATH_NODE_INDEX;
import static org.neo4j.server.rest.web.Surface.PATH_RELATIONSHIPS;
import static org.neo4j.server.rest.web.Surface.PATH_RELATIONSHIP_INDEX;
import static org.neo4j.server.rest.web.Surface.PATH_SCHEMA_CONSTRAINT;
import static org.neo4j.server.rest.web.Surface.PATH_SCHEMA_INDEX;
import static org.neo4j.server.rest.web.Surface.PATH_SCHEMA_RELATIONSHIP_CONSTRAINT;

public class AbstractRestFunctionalTestBase extends SharedServerTestBase implements GraphHolder
{
Expand All @@ -63,14 +63,7 @@ public class AbstractRestFunctionalTestBase extends SharedServerTestBase impleme
TestData<Map<String, Node>> data = TestData.producedThrough( GraphDescription.createGraphFor( this, true ) );

public @Rule
TestData<RESTDocsGenerator> gen = TestData.producedThrough( RESTDocsGenerator.PRODUCER );

@Before
public void setUp()
{
gen().setSection( getDocumentationSectionName() );
gen().setGraph( graphdb() );
}
TestData<RESTRequestGenerator> gen = TestData.producedThrough( RESTRequestGenerator.PRODUCER );

@SafeVarargs
public final String doCypherRestCall( String endpoint, String scriptTemplate, Status status,
Expand All @@ -88,10 +81,8 @@ public String doCypherRestCall( String endpoint, String scriptTemplate, Status s
String script = createScript( scriptTemplate );
String queryString = "{\"query\": \"" + script + "\",\"params\":{" + parameterString + "}}";

String snippet = org.neo4j.cypher.internal.compiler.v3_0.prettifier.Prettifier$.MODULE$.apply( script );
gen().expectedStatus( status.getStatusCode() )
.payload( queryString )
.description( AsciidocHelper.createAsciiDocSnippet( "cypher", snippet ) );
.payload( queryString );
return gen().post( endpoint ).entity();
}

Expand Down Expand Up @@ -234,20 +225,10 @@ public String getPropertiesUri( Node node )
return getNodeUri( node )+ "/properties";
}

public RESTDocsGenerator gen() {
public RESTRequestGenerator gen() {
return gen.get();
}

public void description( String description )
{
gen().description( description );

}

protected String getDocumentationSectionName() {
return "dev/rest-api";
}

public String getLabelsUri()
{
return format( "%slabels", getDataUri() );
Expand Down Expand Up @@ -299,28 +280,8 @@ public String getSchemaConstraintLabelUniquenessUri( String label )
return getDataUri() + PATH_SCHEMA_CONSTRAINT + "/" + label + "/uniqueness/";
}

public String getSchemaConstraintLabelExistenceUri( String label )
{
return getDataUri() + PATH_SCHEMA_CONSTRAINT + "/" + label + "/existence/";
}

public String getSchemaRelationshipConstraintTypeExistenceUri( String type )
{
return getDataUri() + PATH_SCHEMA_RELATIONSHIP_CONSTRAINT + "/" + type + "/existence/";
}

public String getSchemaConstraintLabelUniquenessPropertyUri( String label, String property )
{
return getDataUri() + PATH_SCHEMA_CONSTRAINT + "/" + label + "/uniqueness/" + property;
}

public String getSchemaConstraintLabelExistencePropertyUri( String label, String property )
{
return getDataUri() + PATH_SCHEMA_CONSTRAINT + "/" + label + "/existence/" + property;
}

public String getSchemaRelationshipConstraintTypeExistencePropertyUri( String type, String property )
{
return getDataUri() + PATH_SCHEMA_RELATIONSHIP_CONSTRAINT + "/" + type + "/existence/" + property;
}
}
Expand Up @@ -49,13 +49,7 @@ public class AutoIndexWithNonDefaultConfigurationThroughRESTAPIIT extends Exclus

public
@Rule
TestData<RESTDocsGenerator> gen = TestData.producedThrough( RESTDocsGenerator.PRODUCER );

@Before
public void setUp()
{
gen.get().setSection( "dev/rest-api" );
}
TestData<RESTRequestGenerator> gen = TestData.producedThrough( RESTRequestGenerator.PRODUCER );

@BeforeClass
public static void allocateServer() throws IOException
Expand Down
Expand Up @@ -108,7 +108,6 @@ public void shouldPerformMultipleOperations() throws Exception


String entity = gen.get()
.description( startGraph( "execute multiple operations in batch" ) )
.payload(jsonString)
.expectedStatus(200)
.post(batchUri()).entity();
Expand Down
Expand Up @@ -50,7 +50,6 @@ public void create_a_relationship_with_properties() throws Exception
+ getNode( "Sara" ).getId()
+ "\", \"type\" : \"LOVES\", \"data\" : {\"foo\" : \"bar\"}}";
Node i = getNode( "Joe" );
gen.get().description( startGraph( "Add relationship with properties before" ) );
gen.get().expectedStatus(
Status.CREATED.getStatusCode() ).payload( jsonString ).post(
getNodeUri( i ) + "/relationships" );
Expand All @@ -74,7 +73,6 @@ public void create_relationship() throws Exception
Node i = getNode( "Joe" );
String entity = gen.get().expectedStatus(
Status.CREATED.getStatusCode() ).payload( jsonString )
.description( startGraph( "create relationship" ) )
.post( getNodeUri( i ) + "/relationships" ).entity();
try ( Transaction tx = graphdb().beginTx() )
{
Expand Down
Expand Up @@ -44,7 +44,7 @@ public void get_degree() throws JsonParseException
String nodeUri = getNodeUri( nodes.get( "Root" ) );

// Document
RESTDocsGenerator.ResponseEntity response = gen.get()
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.get( nodeUri + "/degree/all" );

Expand All @@ -64,7 +64,7 @@ public void get_degree_by_direction() throws JsonParseException
String nodeUri = getNodeUri( nodes.get( "Root" ) );

// Document
RESTDocsGenerator.ResponseEntity response = gen.get()
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.get( nodeUri + "/degree/out" );

Expand All @@ -84,7 +84,7 @@ public void get_degree_by_direction_and_type() throws JsonParseException
String nodeUri = getNodeUri( nodes.get( "Root" ) );

// Document
RESTDocsGenerator.ResponseEntity response = gen.get()
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.get( nodeUri + "/degree/out/KNOWS&LIKES" );

Expand Down
Expand Up @@ -25,7 +25,7 @@

import org.neo4j.kernel.impl.annotations.Documented;
import org.neo4j.kernel.internal.Version;
import org.neo4j.server.rest.RESTDocsGenerator.ResponseEntity;
import org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity;
import org.neo4j.server.rest.domain.JsonHelper;
import org.neo4j.server.rest.repr.StreamingFormat;
import org.neo4j.test.GraphDescription.Graph;
Expand Down
Expand Up @@ -31,7 +31,6 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -42,7 +41,7 @@
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.impl.annotations.Documented;
import org.neo4j.server.helpers.FunctionalTestHelper;
import org.neo4j.server.rest.RESTDocsGenerator.ResponseEntity;
import org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity;
import org.neo4j.server.rest.domain.GraphDbHelper;
import org.neo4j.server.rest.domain.JsonHelper;
import org.neo4j.server.rest.domain.JsonParseException;
Expand Down Expand Up @@ -72,12 +71,6 @@ public static void setupServer()
helper = functionalTestHelper.getGraphDbHelper();
}

@Before
public void setup()
{
gen().setGraph( server().getDatabase().getGraph() );
}

@Documented( "List node indexes." )
@Test
public void shouldGetListOfNodeIndexesWhenOneExist() throws JsonParseException
Expand Down
Expand Up @@ -41,7 +41,7 @@
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.impl.annotations.Documented;
import org.neo4j.server.helpers.FunctionalTestHelper;
import org.neo4j.server.rest.RESTDocsGenerator.ResponseEntity;
import org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity;
import org.neo4j.server.rest.domain.GraphDbHelper;
import org.neo4j.server.rest.domain.JsonHelper;
import org.neo4j.server.rest.domain.JsonParseException;
Expand Down
Expand Up @@ -67,7 +67,6 @@ public void adding_a_label_to_a_node() throws PropertyValueException
String nodeUri = getNodeUri( nodes.get( "Clint Eastwood" ) );

gen.get()
.description( startGraph( "adding a label to a node" ) )
.expectedStatus( 204 )
.payload( createJsonFrom( "Person" ) )
.post( nodeUri + "/labels" );
Expand All @@ -82,7 +81,6 @@ public void adding_multiple_labels_to_a_node() throws PropertyValueException
String nodeUri = getNodeUri( nodes.get( "Clint Eastwood" ) );

gen.get()
.description( startGraph( "adding multiple labels to a node" ) )
.expectedStatus( 204 )
.payload( createJsonFrom( new String[]{"Person", "Actor"} ) )
.post( nodeUri + "/labels" );
Expand Down Expand Up @@ -122,7 +120,6 @@ public void replacing_labels_on_a_node() throws PropertyValueException

// When
gen.get()
.description( startGraph( "replacing labels on a node" ) )
.expectedStatus( 204 )
.payload( createJsonFrom( new String[]{"Actor", "Director"}) )
.put( nodeUri + "/labels" );
Expand Down Expand Up @@ -159,7 +156,6 @@ public void removing_a_label_from_a_node() throws PropertyValueException

String labelName = "Person";
gen.get()
.description( startGraph( "removing a label from a node" ) )
.expectedStatus( 204 )
.delete( nodeUri + "/labels/" + labelName );

Expand All @@ -177,7 +173,6 @@ public void removing_a_non_existent_label_from_a_node() throws PropertyValueExce

String labelName = "Person";
gen.get()
.description( startGraph( "removing a non-existent label from a node" ) )
.expectedStatus( 204 )
.delete( nodeUri + "/labels/" + labelName );

Expand Down
Expand Up @@ -232,8 +232,7 @@ public void shouldGetValidNodeRepresentationWhenCreatingNode() throws Exception
public void shouldRespondWith204WhenNodeDeleted() throws Exception
{
long node = helper.createNode();
gen.get().description( startGraph( "delete node" ) )
.expectedStatus( 204 )
gen.get().expectedStatus( 204 )
.delete( functionalTestHelper.dataUri() + "node/" + node );
}

Expand Down Expand Up @@ -265,8 +264,7 @@ public void shouldRespondWith409AndSensibleEntityBodyWhenNodeCannotBeDeleted() t
assertThat( jsonMap, hasKey( "message" ) );
assertNotNull( jsonMap.get( "message" ) );

gen.get().description( startGraph( "nodes with rels can not be deleted" ) )
.expectedStatus( 409 )
gen.get().expectedStatus( 409 )
.delete( functionalTestHelper.dataUri() + "node/" + id );
}

Expand Down Expand Up @@ -327,15 +325,9 @@ public static class CommunityVersionAndEditionServiceDocIT extends ExclusiveServ

public
@Rule
TestData<RESTDocsGenerator> gen = TestData.producedThrough( RESTDocsGenerator.PRODUCER );
TestData<RESTRequestGenerator> gen = TestData.producedThrough( RESTRequestGenerator.PRODUCER );
private static FakeClock clock;

@Before
public void setUp()
{
gen.get().setSection( "dev/rest-api/database-version" );
}

@BeforeClass
public static void setupServer() throws Exception
{
Expand Down

0 comments on commit dfb003d

Please sign in to comment.