Skip to content

Commit

Permalink
Merge pull request #10783 from tinwelint/3.4-unflake-RetrieveNodeIT
Browse files Browse the repository at this point in the history
Test 404 reply on guaranteed non-existent node
  • Loading branch information
tinwelint committed Jan 12, 2018
2 parents d13cf7f + 704a11c commit ed2de02
Showing 1 changed file with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;
Expand All @@ -50,26 +49,26 @@
public class RetrieveNodeIT extends AbstractRestFunctionalDocTestBase
{
private URI nodeUri;
private GraphDbHelper helper;
private static FunctionalTestHelper functionalTestHelper;

@BeforeClass
public static void setupServer() throws IOException
public static void setupServer()
{
functionalTestHelper = new FunctionalTestHelper( server() );
}

@Before
public void cleanTheDatabaseAndInitialiseTheNodeUri() throws Exception
{
nodeUri = new URI( functionalTestHelper.nodeUri() + "/"
+ new GraphDbHelper( server().getDatabase() ).createNode() );
helper = new GraphDbHelper( server().getDatabase() );
nodeUri = new URI( functionalTestHelper.nodeUri() + "/" + helper.createNode() );
}

@Test
public void shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue() throws Exception
{
HttpClient httpclient = new DefaultHttpClient();
try
try ( CloseableHttpClient httpclient = HttpClientBuilder.create().build() )
{
HttpGet httpget = new HttpGet( nodeUri );

Expand All @@ -83,17 +82,12 @@ public void shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue() thro
assertThat( entityBody, containsString( "http://dummy.neo4j.org/db/data/node/" ) );

}
finally
{
httpclient.getConnectionManager().shutdown();
}
}

@Test
public void shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequestUri() throws Exception
{
HttpClient httpclient = new DefaultHttpClient();
try
try ( CloseableHttpClient httpclient = HttpClientBuilder.create().build() )
{
HttpGet httpget = new HttpGet( nodeUri );

Expand All @@ -105,10 +99,6 @@ public void shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequ

assertThat( entityBody, containsString( nodeUri.toString() ) );
}
finally
{
httpclient.getConnectionManager().shutdown();
}
}

@Documented( "Get node.\n" +
Expand Down Expand Up @@ -171,12 +161,13 @@ public void shouldHaveJsonDataInResponse() throws Exception
@Test
public void shouldGet404WhenRetrievingNonExistentNode() throws Exception
{
//We need to add something to the nodeUri that works also
//when the nodeUri points to node with id 0, hence just adding
//a bunch of zeros will not always work since
long nonExistentNode = helper.createNode();
helper.deleteNode( nonExistentNode );
URI nonExistentNodeUri = new URI( functionalTestHelper.nodeUri() + "/" + nonExistentNode );

gen.get()
.expectedStatus( 404 )
.get( nodeUri + "123456" );
.get( nonExistentNodeUri.toString() );
}

private JaxRsResponse retrieveNodeFromService( final String uri )
Expand Down

0 comments on commit ed2de02

Please sign in to comment.