Skip to content

Commit

Permalink
Add tests for using resultDataContent: "graph"
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Oct 12, 2018
1 parent 0fe57dc commit 8ffdf4f
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public static ValueRepresentation string( String value )

public static ValueRepresentation point( Point value )
{
//TODO sending in the point here looks like it will use Jackson object mapper
// to serialize, maybe send in a Map instead
return new ValueRepresentation( RepresentationType.POINT, value );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ public void shouldHandlePointsUsingRestResultDataContent() throws Exception
assertCrsEqual( WGS84, row );
}

@Test
public void shouldHandlePointsUsingGraphResultDataContent() throws Exception
{
//Given
GraphDatabaseFacade db = server().getDatabase().getGraph();
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( label( "N" ) );
node.setProperty( "coordinates", pointValue( WGS84, 30.655691, 104.081602 ) );
tx.success();
}

//When
HTTP.Response response = runQuery( "MATCH (n:N) RETURN n", "graph" );

assertEquals( 200, response.status() );
assertNoErrors( response );

//Then
JsonNode row = response.get( "results" ).get( 0 ).get( "data" ).get( 0 ).get( "graph" )
.get("nodes").get( 0 ).get( "properties" ).get( "coordinates" );
assertGeometryTypeEqual( GeometryType.GEOMETRY_POINT, row );
assertCoordinatesEqual( new double[]{30.655691, 104.081602}, row );
assertCrsEqual( WGS84, row );
}

@Test
public void shouldHandleArrayOfPointsUsingRestResultDataContent() throws Exception
{
Expand All @@ -164,6 +190,32 @@ public void shouldHandleArrayOfPointsUsingRestResultDataContent() throws Excepti
assertCrsEqual( WGS84, row );
}

@Test
public void shouldHandleArrayOfPointsUsingGraphResultDataContent() throws Exception
{
//Given
GraphDatabaseFacade db = server().getDatabase().getGraph();
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( label( "N" ) );
node.setProperty( "coordinates", new Point[]{pointValue( WGS84, 30.655691, 104.081602 )});
tx.success();
}

//When
HTTP.Response response = runQuery( "MATCH (n:N) RETURN n", "graph" );

assertEquals( 200, response.status() );
assertNoErrors( response );

//Then
JsonNode row = response.get( "results" ).get( 0 ).get( "data" ).get( 0 ).get( "graph" )
.get("nodes").get( 0 ).get( "properties" ).get( "coordinates" ).get( 0 );
assertGeometryTypeEqual( GeometryType.GEOMETRY_POINT, row );
assertCoordinatesEqual( new double[]{30.655691, 104.081602}, row );
assertCrsEqual( WGS84, row );
}

private static void testPoint( String query, double[] expectedCoordinate, CoordinateReferenceSystem expectedCrs, String expectedType ) throws Exception
{
HTTP.Response response = runQuery( query );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,109 @@ public void shouldHandleDurationArraysUsingRestResultDataContent() throws Except
assertEquals( "\"PT1M13S\"", row.toString() );
}

@Test
public void shouldHandleTemporalUsingGraphResultDataContent() throws Exception
{
//Given
GraphDatabaseFacade db = server().getDatabase().getGraph();
ZonedDateTime date = ZonedDateTime.of( 1980, 3, 11, 0, 0,
0, 0, ZoneId.of( "Europe/Stockholm" ) );
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( label( "N" ) );
node.setProperty( "date", date );
tx.success();
}

//When
HTTP.Response response = runQuery( "MATCH (n:N) RETURN n", "graph" );

//Then
assertEquals( 200, response.status() );
assertNoErrors( response );
JsonNode row = response.get( "results" ).get( 0 ).get( "data" ).get( 0 ).get( "graph" )
.get("nodes").get( 0 ).get( "properties" ).get( "date" );
assertEquals( "\"1980-03-11T00:00+01:00[Europe/Stockholm]\"", row.toString() );
}

@Test
public void shouldHandleDurationUsingGraphResultDataContent() throws Exception
{
//Given
GraphDatabaseFacade db = server().getDatabase().getGraph();
Duration duration = Duration.ofSeconds( 73 );

try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( label( "N" ) );
node.setProperty( "duration", duration );
tx.success();
}

//When
HTTP.Response response = runQuery( "MATCH (n:N) RETURN n", "graph" );

//Then
assertEquals( 200, response.status() );
assertNoErrors( response );

JsonNode row = response.get( "results" ).get( 0 ).get( "data" ).get( 0 ).get( "graph" )
.get("nodes").get( 0 ).get( "properties" ).get( "duration" );
assertEquals( "\"PT1M13S\"", row.toString() );
}

@Test
public void shouldHandleTemporalArraysUsingGraphResultDataContent() throws Exception
{
//Given
GraphDatabaseFacade db = server().getDatabase().getGraph();
ZonedDateTime date = ZonedDateTime.of( 1980, 3, 11, 0, 0,
0, 0, ZoneId.of( "Europe/Stockholm" ) );
try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( label( "N" ) );
node.setProperty( "dates", new ZonedDateTime[]{date} );
tx.success();
}

//When
HTTP.Response response = runQuery( "MATCH (n:N) RETURN n", "graph" );

//Then
assertEquals( 200, response.status() );
assertNoErrors( response );

JsonNode row = response.get( "results" ).get( 0 ).get( "data" ).get( 0 ).get( "graph" )
.get( "nodes" ).get( 0 ).get( "properties" ).get( "dates" ).get( 0 );
assertEquals( "\"1980-03-11T00:00+01:00[Europe/Stockholm]\"", row.toString() );
}

@Test
public void shouldHandleDurationArraysUsingGraphResultDataContent() throws Exception
{
//Given
GraphDatabaseFacade db = server().getDatabase().getGraph();
Duration duration = Duration.ofSeconds( 73 );

try ( Transaction tx = db.beginTx() )
{
Node node = db.createNode( label( "N" ) );
node.setProperty( "durations", new Duration[]{duration} );
tx.success();
}

//When
HTTP.Response response = runQuery( "MATCH (n:N) RETURN n", "graph" );

//Then
assertEquals( 200, response.status() );
assertNoErrors( response );

JsonNode row = response.get( "results" ).get( 0 ).get( "data" ).get( 0 ).get( "graph" )
.get("nodes").get( 0 ).get( "properties" ).get( "durations" ).get( 0 );
assertEquals( "\"PT1M13S\"", row.toString() );
}

private HTTP.RawPayload queryAsJsonGraph( String query )
{
return quotedJson( "{ 'statements': [ { 'statement': '" + query + "', 'resultDataContents': [ 'graph' ] } ] }" );
Expand Down

0 comments on commit 8ffdf4f

Please sign in to comment.