2727
2828import org .neo4j .driver .v1 .Record ;
2929import org .neo4j .driver .v1 .Value ;
30- import org .neo4j .driver .v1 .types .Point ;
30+ import org .neo4j .driver .v1 .types .Point2D ;
3131import org .neo4j .driver .v1 .util .TestNeo4jSession ;
3232
33- import static java .util .Arrays .asList ;
3433import static java .util .Collections .singletonMap ;
3534import static org .junit .Assert .assertEquals ;
3635import static org .junit .Assume .assumeTrue ;
3736import static org .neo4j .driver .internal .util .ServerVersion .v3_4_0 ;
38- import static org .neo4j .driver .v1 .Values .point ;
37+ import static org .neo4j .driver .v1 .Values .point2D ;
3938
40- public class PointTypeIT
39+ public class PointsIT
4140{
42- private static final int EPSG_TABLE_ID = 1 ;
43- private static final int WGS_84_CRS_CODE = 4326 ;
44-
45- private static final int SR_ORG_TABLE_ID = 2 ;
46- private static final int CARTESIAN_CRS_CODE = 7203 ;
41+ private static final long WGS_84_CRS_CODE = 4326 ;
42+ private static final long CARTESIAN_CRS_CODE = 7203 ;
43+ private static final double DELTA = 0.00001 ;
4744
4845 @ Rule
4946 public final TestNeo4jSession session = new TestNeo4jSession ();
@@ -59,33 +56,33 @@ public void shouldReceivePoint()
5956 {
6057 Record record = session .run ( "RETURN point({x: 39.111748, y:-76.775635})" ).single ();
6158
62- Point point = record .get ( 0 ).asPoint ();
59+ Point2D point = record .get ( 0 ).asPoint2D ();
6360
64- assertEquals ( SR_ORG_TABLE_ID , point .crsTableId () );
65- assertEquals ( CARTESIAN_CRS_CODE , point .crsCode () );
66- assertEquals ( asList ( 39.111748 , -76.775635 ) , point .coordinate (). values () );
61+ assertEquals ( CARTESIAN_CRS_CODE , point .srid () );
62+ assertEquals ( 39.111748 , point .x (), DELTA );
63+ assertEquals ( -76.775635 , point .y (), DELTA );
6764 }
6865
6966 @ Test
7067 public void shouldSendPoint ()
7168 {
72- Value pointValue = point ( EPSG_TABLE_ID , WGS_84_CRS_CODE , 38.8719 , 77.0563 );
69+ Value pointValue = point2D ( WGS_84_CRS_CODE , 38.8719 , 77.0563 );
7370 Record record1 = session .run ( "CREATE (n:Node {location: $point}) RETURN 42" , singletonMap ( "point" , pointValue ) ).single ();
7471
7572 assertEquals ( 42 , record1 .get ( 0 ).asInt () );
7673
7774 Record record2 = session .run ( "MATCH (n:Node) RETURN n.location" ).single ();
78- Point point = record2 .get ( 0 ).asPoint ();
75+ Point2D point = record2 .get ( 0 ).asPoint2D ();
7976
80- assertEquals ( EPSG_TABLE_ID , point .crsTableId () );
81- assertEquals ( WGS_84_CRS_CODE , point .crsCode () );
82- assertEquals ( asList ( 38.8719 , 77.0563 ) , point .coordinate (). values () );
77+ assertEquals ( WGS_84_CRS_CODE , point .srid () );
78+ assertEquals ( 38.8719 , point .x (), DELTA );
79+ assertEquals ( 77.0563 , point .y (), DELTA );
8380 }
8481
8582 @ Test
8683 public void shouldSendAndReceivePoint ()
8784 {
88- testPointSendAndReceive ( SR_ORG_TABLE_ID , CARTESIAN_CRS_CODE , 40.7624 , 73.9738 );
85+ testPointSendAndReceive ( point2D ( CARTESIAN_CRS_CODE , 40.7624 , 73.9738 ) );
8986 }
9087
9188 @ Test
@@ -94,34 +91,27 @@ public void shouldSendAndReceiveRandomPoints()
9491 Stream <Value > randomPoints = ThreadLocalRandom .current ()
9592 .ints ( 1_000 , 0 , 2 )
9693 .mapToObj ( idx -> idx % 2 == 0
97- ? point ( EPSG_TABLE_ID , WGS_84_CRS_CODE , randomCoordinate () )
98- : point ( SR_ORG_TABLE_ID , CARTESIAN_CRS_CODE , randomCoordinate () ) );
94+ ? point2D ( WGS_84_CRS_CODE , randomDouble (), randomDouble () )
95+ : point2D ( CARTESIAN_CRS_CODE , randomDouble (), randomDouble () ) );
9996
10097 randomPoints .forEach ( this ::testPointSendAndReceive );
10198 }
10299
103- private void testPointSendAndReceive ( long crsTableId , long crsCode , double ... coordinate )
104- {
105- testPointSendAndReceive ( point ( crsTableId , crsCode , coordinate ) );
106- }
107-
108100 private void testPointSendAndReceive ( Value pointValue )
109101 {
110- Point originalPoint = pointValue .asPoint ();
102+ Point2D originalPoint = pointValue .asPoint2D ();
111103
112104 Record record = session .run ( "CREATE (n {p:$point}) return n.p" , singletonMap ( "point" , pointValue ) ).single ();
113- Point receivedPoint = record .get ( 0 ).asPoint ();
105+ Point2D receivedPoint = record .get ( 0 ).asPoint2D ();
114106
115107 String message = "Failed for " + originalPoint ;
116- assertEquals ( message , originalPoint .crsTableId (), receivedPoint .crsTableId () );
117- assertEquals ( message , originalPoint .crsCode (), receivedPoint .crsCode () );
118- assertEquals ( message , originalPoint .coordinate (). values () , receivedPoint .coordinate (). values () );
108+ assertEquals ( message , originalPoint .srid (), receivedPoint .srid () );
109+ assertEquals ( message , originalPoint .x (), receivedPoint .x (), DELTA );
110+ assertEquals ( message , originalPoint .y () , receivedPoint .y (), DELTA );
119111 }
120112
121- private static double [] randomCoordinate ()
113+ private static double randomDouble ()
122114 {
123- ThreadLocalRandom random = ThreadLocalRandom .current ();
124- int count = random .nextInt ( 2 , 4 ); // either 2D or 3D point
125- return random .doubles ( count , -180.0 , 180 ).toArray ();
115+ return ThreadLocalRandom .current ().nextDouble ( -180.0 , 180 );
126116 }
127- }
117+ }
0 commit comments