27
27
28
28
import org .neo4j .driver .v1 .Record ;
29
29
import org .neo4j .driver .v1 .Value ;
30
- import org .neo4j .driver .v1 .types .Point ;
30
+ import org .neo4j .driver .v1 .types .Point2D ;
31
31
import org .neo4j .driver .v1 .util .TestNeo4jSession ;
32
32
33
- import static java .util .Arrays .asList ;
34
33
import static java .util .Collections .singletonMap ;
35
34
import static org .junit .Assert .assertEquals ;
36
35
import static org .junit .Assume .assumeTrue ;
37
36
import 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 ;
39
38
40
- public class PointTypeIT
39
+ public class PointsIT
41
40
{
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 ;
47
44
48
45
@ Rule
49
46
public final TestNeo4jSession session = new TestNeo4jSession ();
@@ -59,33 +56,33 @@ public void shouldReceivePoint()
59
56
{
60
57
Record record = session .run ( "RETURN point({x: 39.111748, y:-76.775635})" ).single ();
61
58
62
- Point point = record .get ( 0 ).asPoint ();
59
+ Point2D point = record .get ( 0 ).asPoint2D ();
63
60
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 );
67
64
}
68
65
69
66
@ Test
70
67
public void shouldSendPoint ()
71
68
{
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 );
73
70
Record record1 = session .run ( "CREATE (n:Node {location: $point}) RETURN 42" , singletonMap ( "point" , pointValue ) ).single ();
74
71
75
72
assertEquals ( 42 , record1 .get ( 0 ).asInt () );
76
73
77
74
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 ();
79
76
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 );
83
80
}
84
81
85
82
@ Test
86
83
public void shouldSendAndReceivePoint ()
87
84
{
88
- testPointSendAndReceive ( SR_ORG_TABLE_ID , CARTESIAN_CRS_CODE , 40.7624 , 73.9738 );
85
+ testPointSendAndReceive ( point2D ( CARTESIAN_CRS_CODE , 40.7624 , 73.9738 ) );
89
86
}
90
87
91
88
@ Test
@@ -94,34 +91,27 @@ public void shouldSendAndReceiveRandomPoints()
94
91
Stream <Value > randomPoints = ThreadLocalRandom .current ()
95
92
.ints ( 1_000 , 0 , 2 )
96
93
.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 () ) );
99
96
100
97
randomPoints .forEach ( this ::testPointSendAndReceive );
101
98
}
102
99
103
- private void testPointSendAndReceive ( long crsTableId , long crsCode , double ... coordinate )
104
- {
105
- testPointSendAndReceive ( point ( crsTableId , crsCode , coordinate ) );
106
- }
107
-
108
100
private void testPointSendAndReceive ( Value pointValue )
109
101
{
110
- Point originalPoint = pointValue .asPoint ();
102
+ Point2D originalPoint = pointValue .asPoint2D ();
111
103
112
104
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 ();
114
106
115
107
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 );
119
111
}
120
112
121
- private static double [] randomCoordinate ()
113
+ private static double randomDouble ()
122
114
{
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 );
126
116
}
127
117
}
0 commit comments