Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master' into merge-osm
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java
  • Loading branch information
Andy2003 committed May 29, 2024
2 parents 3f31b94 + 12f6d46 commit 595c92f
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 54 deletions.
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>${neo4j.java.version}</source>
<target>${neo4j.java.version}</target>
Expand Down Expand Up @@ -304,12 +304,6 @@
</dependency>

<!-- The JUnit-Hamcrest-Mockito combo -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/neo4j/gis/spatial/LayerMergeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import static java.lang.String.format;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME;

import java.io.File;
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/neo4j/gis/spatial/LayersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME;

import java.io.File;
Expand Down Expand Up @@ -272,12 +272,12 @@ private String testSpecificEditableLayer(String layerName, Class<? extends Geome
inTx(tx -> {
Layer layer = spatial.createLayer(tx, layerName, geometryEncoderClass, layerClass);
assertNotNull(layer);
assertTrue(layer instanceof EditableLayer, "Should be an editable layer");
assertInstanceOf(EditableLayer.class, layer, "Should be an editable layer");
});
inTx(tx -> {
Layer layer = spatial.getLayer(tx, layerName);
assertNotNull(layer);
assertTrue(layer instanceof EditableLayer, "Should be an editable layer");
assertInstanceOf(EditableLayer.class, layer, "Should be an editable layer");
EditableLayer editableLayer = (EditableLayer) layer;

CoordinateList coordinates = new CoordinateList();
Expand Down Expand Up @@ -386,7 +386,7 @@ public void testIndexAccessAfterBulkInsertion() {
Result result = tx.execute(cypher);
// System.out.println(result.columns().toString());
Object obj = result.columnAs("count(p)").next();
assertTrue(obj instanceof Long);
assertInstanceOf(Long.class, obj);
assertEquals(1000L, (long) ((Long) obj));
tx.commit();
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/neo4j/gis/spatial/Neo4jTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
package org.neo4j.gis.spatial;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -117,7 +117,7 @@ public static void printTree(Node root, int depth) {

public static <T> void assertCollection(Collection<T> collection, T... expectedItems) {
String collectionString = join(", ", collection.toArray());
assertEquals(collectionString, expectedItems.length, collection.size());
assertEquals(expectedItems.length, collection.size(), collectionString);
for (T item : expectedItems) {
assertTrue(collection.contains(item));
}
Expand Down
29 changes: 16 additions & 13 deletions src/test/java/org/neo4j/gis/spatial/RTreeBulkInsertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME;
import static org.neo4j.gis.spatial.rtree.RTreeIndex.DEFAULT_MAX_NODE_REFERENCES;
import static org.neo4j.internal.helpers.collection.MapUtil.map;
Expand Down Expand Up @@ -1137,7 +1138,7 @@ public void shouldAccessIndexAfterBulkInsertion() throws Exception {
Result result = tx.execute(cypher);
// System.out.println(result.columns().toString());
Object obj = result.columnAs("count").next();
assertTrue(obj instanceof Long);
assertInstanceOf(Long.class, obj);
assertEquals((long) ((Long) obj), numNodes);
tx.commit();
}
Expand All @@ -1152,7 +1153,7 @@ public void shouldAccessIndexAfterBulkInsertion() throws Exception {
Result result = tx.execute(cypher);
// System.out.println(result.columns().toString());
Object obj = result.columnAs("count").next();
assertTrue(obj instanceof Long);
assertInstanceOf(Long.class, obj);
assertEquals((long) ((Long) obj), numNodes);
tx.commit();
}
Expand Down Expand Up @@ -1492,8 +1493,8 @@ private List<Node> queryIndex(Layer layer, TestStats stats) {
stats.put("Indexed", geometrySize);
System.out.println("Index contains " + geometrySize + " geometries");
}
assertEquals("Expected " + config.expectedGeometries + " nodes to be returned", config.expectedGeometries,
countGeometries);
assertEquals(config.expectedGeometries, countGeometries,
"Expected " + config.expectedGeometries + " nodes to be returned");
return nodes;
}

Expand Down Expand Up @@ -1529,7 +1530,8 @@ private void getRTreeIndexStats(RTreeIndex index, TreeMonitor monitor, TestStats
// unless the polygon is a rectangle, in which case they are not contained, leading to
// different numbers for expectedGeometries and expectedCount.
// See https://github.com/locationtech/jts/blob/master/modules/core/src/main/java/org/locationtech/jts/operation/predicate/RectangleContains.java#L70
assertEquals("Expected " + config.expectedCount + " nodes to be matched", config.expectedCount, matched);
assertEquals(config.expectedCount, matched,
"Expected " + config.expectedCount + " nodes to be matched");
int maxNodeReferences = stats.maxNodeReferences;
int maxExpectedGeometriesTouched = matched * maxNodeReferences;
if (countGeometries > 1 && assertTouches) {
Expand All @@ -1555,7 +1557,8 @@ private void getExplicitIndexBackedIndexStats(ExplicitIndexBackedPointIndex inde
// unless the polygon is a rectangle, in which case they are not contained, leading to
// different numbers for expectedGeometries and expectedCount.
// See https://github.com/locationtech/jts/blob/master/modules/core/src/main/java/org/locationtech/jts/operation/predicate/RectangleContains.java#L70
assertEquals("Expected " + config.expectedCount + " nodes to be matched", config.expectedCount, matched);
assertEquals(config.expectedCount, matched,
"Expected " + config.expectedCount + " nodes to be matched");
}

private class TimedLogger {
Expand Down Expand Up @@ -1599,17 +1602,17 @@ private void log(String line, long number) {

private void verifyGeohashIndex(Layer layer) {
LayerIndexReader index = layer.getIndex();
assertTrue("Index should be a geohash index", index instanceof LayerGeohashPointIndex);
assertInstanceOf(LayerGeohashPointIndex.class, index, "Index should be a geohash index");
}

private void verifyHilbertIndex(Layer layer) {
LayerIndexReader index = layer.getIndex();
assertTrue("Index should be a hilbert index", index instanceof LayerHilbertPointIndex);
assertInstanceOf(LayerHilbertPointIndex.class, index, "Index should be a hilbert index");
}

private void verifyZOrderIndex(Layer layer) {
LayerIndexReader index = layer.getIndex();
assertTrue("Index should be a Z-Order index", index instanceof LayerZOrderPointIndex);
assertInstanceOf(LayerZOrderPointIndex.class, index, "Index should be a Z-Order index");
}

private void verifyTreeStructure(Layer layer, String splitMode, TestStats stats) {
Expand Down Expand Up @@ -1650,7 +1653,7 @@ private void verifyTreeStructure(Layer layer, String splitMode, TestStats stats)
System.out.println("Tree depth to all geometries: " + depthMap);
}
}
assertEquals("All geometries should be at the same depth", 1, balanced);
assertEquals(1, balanced, "All geometries should be at the same depth");
Map<String, Object> leafMap;
try (Transaction tx = db.beginTx()) {
Result resultNumChildren = tx.execute(queryNumChildren, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import junit.framework.AssertionFailedError;
import org.geotools.data.neo4j.StyledImageExporter;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
Expand All @@ -48,6 +47,7 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.opentest4j.AssertionFailedError;

public class TestSimplePointLayer extends Neo4jTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public void extract_points() {

assertEquals(1, flow.getProperties().size());
String wkt = (String) flow.getProperties().get("WellKnownText");
assertTrue(wkt.indexOf("POINT") == 0);
assertEquals(0, wkt.indexOf("POINT"));
}

// every rectangle has 5 points, the last point is in the same position of the first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.gis.spatial.pipes;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -136,9 +136,9 @@ public void testQueryPerformance() {
count += rec.count;
System.out.println("\t" + rec);
float average = (float) rec.time / (float) rec.count;
assertTrue("Expected record average of " + rec.average()
assertTrue(rec.average() < 2 * average, "Expected record average of " + rec.average()
+ " to not be substantially larger than running average "
+ average, rec.average() < 2 * average);
+ average);
}
tx.commit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME;
import static org.neo4j.gis.spatial.Constants.LABEL_LAYER;
import static org.neo4j.gis.spatial.Constants.PROP_GEOMENCODER;
Expand Down Expand Up @@ -136,11 +140,11 @@ public static void testCallFails(GraphDatabaseService db, String call, Map<Strin
public static void testCall(GraphDatabaseService db, String call, Map<String, Object> params,
Consumer<Map<String, Object>> consumer, boolean onlyOne) {
testResult(db, call, params, (res) -> {
Assertions.assertTrue(res.hasNext(), "Expect at least one result but got none: " + call);
assertTrue(res.hasNext(), "Expect at least one result but got none: " + call);
Map<String, Object> row = res.next();
consumer.accept(row);
if (onlyOne) {
Assertions.assertFalse(res.hasNext(), "Expected only one result, but there are more");
assertFalse(res.hasNext(), "Expected only one result, but there are more");
}
});
}
Expand All @@ -154,7 +158,7 @@ public static void testCallCount(GraphDatabaseService db, String call, Map<Strin
res.next();
numLeft--;
}
Assertions.assertFalse(res.hasNext(), "Expected " + count + " results but there are more");
assertFalse(res.hasNext(), "Expected " + count + " results but there are more");
});
}

Expand Down Expand Up @@ -355,22 +359,22 @@ public void create_point_geometry_and_distance() {
@Test
public void create_point_and_return() {
Object geometry = executeObject("RETURN point({latitude: 5.0, longitude: 4.0}) as geometry", "geometry");
Assertions.assertTrue(geometry instanceof Geometry, "Should be Geometry type");
assertInstanceOf(Geometry.class, geometry, "Should be Geometry type");
}

@Test
public void create_point_geometry_return() {
Object geometry = executeObject(
"WITH point({latitude: 5.0, longitude: 4.0}) as geom RETURN spatial.asGeometry(geom) AS geometry",
"geometry");
Assertions.assertTrue(geometry instanceof Geometry, "Should be Geometry type");
assertInstanceOf(Geometry.class, geometry, "Should be Geometry type");
}

@Test
public void literal_geometry_return() {
Object geometry = executeObject(
"WITH spatial.asGeometry({latitude: 5.0, longitude: 4.0}) AS geometry RETURN geometry", "geometry");
Assertions.assertTrue(geometry instanceof Geometry, "Should be Geometry type");
assertInstanceOf(Geometry.class, geometry, "Should be Geometry type");
}

@Test
Expand All @@ -379,7 +383,7 @@ public void create_node_decode_to_geometry() {
Object geometry = executeObject(
"CREATE (n:Node {geom:'POINT(4.0 5.0)'}) RETURN spatial.decodeGeometry('geom',n) AS geometry",
"geometry");
Assertions.assertTrue(geometry instanceof Geometry, "Should be Geometry type");
assertInstanceOf(Geometry.class, geometry, "Should be Geometry type");
}

@Test
Expand Down Expand Up @@ -781,31 +785,31 @@ public void add_a_node_to_the_spatial_rtree_index_for_simple_points() {
execute("CALL spatial.addPointLayer('geom')");
Node node = createNode("CREATE (n:Node {latitude:60.1,longitude:15.2}) RETURN n", "n");
testCall(db, "MATCH (n:Node) WITH n CALL spatial.addNode('geom',n) YIELD node RETURN node",
r -> Assertions.assertEquals(node, r.get("node")));
r -> assertEquals(node, r.get("node")));
}

@Test
public void add_a_node_to_the_spatial_geohash_index_for_simple_points() {
execute("CALL spatial.addPointLayerGeohash('geom')");
Node node = createNode("CREATE (n:Node {latitude:60.1,longitude:15.2}) RETURN n", "n");
testCall(db, "MATCH (n:Node) WITH n CALL spatial.addNode('geom',n) YIELD node RETURN node",
r -> Assertions.assertEquals(node, r.get("node")));
r -> assertEquals(node, r.get("node")));
}

@Test
public void add_a_node_to_the_spatial_zorder_index_for_simple_points() {
execute("CALL spatial.addPointLayerZOrder('geom')");
Node node = createNode("CREATE (n:Node {latitude:60.1,longitude:15.2}) RETURN n", "n");
testCall(db, "MATCH (n:Node) WITH n CALL spatial.addNode('geom',n) YIELD node RETURN node",
r -> Assertions.assertEquals(node, r.get("node")));
r -> assertEquals(node, r.get("node")));
}

@Test
public void add_a_node_to_the_spatial_hilbert_index_for_simple_points() {
execute("CALL spatial.addPointLayerHilbert('geom')");
Node node = createNode("CREATE (n:Node {latitude:60.1,longitude:15.2}) RETURN n", "n");
testCall(db, "MATCH (n:Node) WITH n CALL spatial.addNode('geom',n) YIELD node RETURN node",
r -> Assertions.assertEquals(node, r.get("node")));
r -> assertEquals(node, r.get("node")));
}

@Test
Expand Down Expand Up @@ -836,7 +840,7 @@ public void add_a_node_to_multiple_different_indexes_for_both_simple_and_native_
for (String encoder : encoders) {
for (String indexType : indexes) {
String layerName = (encoder + indexType).toLowerCase();
testCall(db, "MATCH (node:Node) RETURN node", r -> Assertions.assertEquals(node, r.get("node")));
testCall(db, "MATCH (node:Node) RETURN node", r -> assertEquals(node, r.get("node")));
testCall(db, "MATCH (n:Node) WITH n CALL spatial.addNode('" + layerName + "',n) YIELD node RETURN node",
r -> Assertions.assertEquals(node, r.get("node")));
testCall(db, "CALL spatial.withinDistance('" + layerName + "',{lon:15.0,lat:60.0},100)",
Expand Down Expand Up @@ -908,15 +912,15 @@ public void add_a_node_to_the_spatial_index_short() {
execute("CALL spatial.addPointLayerXY('geom','lon','lat')");
Node node = createNode("CREATE (n:Node {lat:60.1,lon:15.2}) RETURN n", "n");
testCall(db, "MATCH (n:Node) WITH n CALL spatial.addNode('geom',n) YIELD node RETURN node",
r -> Assertions.assertEquals(node, r.get("node")));
r -> assertEquals(node, r.get("node")));
}

@Test
public void add_a_node_to_the_spatial_index_short_with_geohash() {
execute("CALL spatial.addPointLayerXY('geom','lon','lat','geohash')");
Node node = createNode("CREATE (n:Node {lat:60.1,lon:15.2}) RETURN n", "n");
testCall(db, "MATCH (n:Node) WITH n CALL spatial.addNode('geom',n) YIELD node RETURN node",
r -> Assertions.assertEquals(node, r.get("node")));
r -> assertEquals(node, r.get("node")));
}

@Test
Expand All @@ -931,7 +935,7 @@ public void add_two_nodes_to_the_spatial_layer() {
node1 = ((Node) row.get("n1")).getElementId();
node2 = ((Node) row.get("n2")).getElementId();
long count = (Long) row.get("count");
Assertions.assertEquals(2L, count);
assertEquals(2L, count);
result.close();
tx.commit();
}
Expand All @@ -947,7 +951,7 @@ public void add_two_nodes_to_the_spatial_layer() {
map("nodeId", node1)).next().get("node");
Result removeResult = tx.execute("CALL spatial.removeNode('geom',$node) YIELD nodeId RETURN nodeId",
map("node", node));
Assertions.assertEquals(node1, removeResult.next().get("nodeId"));
assertEquals(node1, removeResult.next().get("nodeId"));
removeResult.close();
tx.commit();
}
Expand All @@ -959,7 +963,7 @@ public void add_two_nodes_to_the_spatial_layer() {
try (Transaction tx = db.beginTx()) {
Result removeResult = tx.execute("CALL spatial.removeNode.byId('geom',$nodeId) YIELD nodeId RETURN nodeId",
map("nodeId", node2));
Assertions.assertEquals(node2, removeResult.next().get("nodeId"));
assertEquals(node2, removeResult.next().get("nodeId"));
removeResult.close();
tx.commit();
}
Expand Down Expand Up @@ -1227,10 +1231,10 @@ private void testCountQuery(String name, String query, long count, String column
}
long start = System.currentTimeMillis();
testResult(db, query, params, res -> {
Assertions.assertTrue(res.hasNext(), "Expected a single result");
Assertions.assertTrue(res.hasNext(), "Expected a single result");
long c = (Long) res.next().get(column);
Assertions.assertFalse(res.hasNext(), "Expected a single result");
Assertions.assertEquals(count, c, "Expected count of " + count + " nodes but got " + c);
assertFalse(res.hasNext(), "Expected a single result");
assertEquals(count, c, "Expected count of " + count + " nodes but got " + c);
}
);
System.out.println(name + " query took " + (System.currentTimeMillis() - start) + "ms - " + params);
Expand Down

0 comments on commit 595c92f

Please sign in to comment.