diff --git a/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java b/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java index eef17156..61386096 100644 --- a/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java +++ b/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java @@ -101,14 +101,6 @@ public static void testCall(GraphDatabaseService db, String call, Consumer map(Object... values) { - Map map = new LinkedHashMap<>(); - for (int i = 0; i < values.length; i += 2) { - map.put(values[i].toString(), values[i + 1]); - } - return map; - } - public static void testCall(GraphDatabaseService db, String call, Map params, Consumer> consumer) { testCall(db, call, params, consumer, true); @@ -159,7 +151,7 @@ public static void testResult(GraphDatabaseService db, String call, Consumer params, Consumer resultConsumer) { try (Transaction tx = db.beginTx()) { - Map p = (params == null) ? map() : params; + Map p = (params == null) ? Map.of() : params; resultConsumer.accept(tx.execute(call, p)); tx.commit(); } @@ -231,7 +223,7 @@ public void old_spatial_model_can_be_upgraded() { public void add_node_to_non_existing_layer() { execute("CALL spatial.addPointLayer('some_name')"); Node node = createNode("CREATE (n:Point {latitude:60.1,longitude:15.2}) RETURN n", "n"); - testCallFails(db, "CALL spatial.addNode.byId('wrong_name',$nodeId)", map("nodeId", node.getElementId()), + testCallFails(db, "CALL spatial.addNode.byId('wrong_name',$nodeId)", Map.of("nodeId", node.getElementId()), "No such layer 'wrong_name'"); } @@ -380,7 +372,7 @@ public void create_node_and_convert_to_geometry() { "CREATE (n:Node {geom:'POINT(4.0 5.0)'}) RETURN spatial.decodeGeometry('geom',n) AS geometry", "geometry"); double distance = (Double) executeObject("RETURN point.distance($geom, point({y: 6.0, x: 4.0})) as distance", - map("geom", geom), "distance"); + Map.of("geom", geom), "distance"); MatcherAssert.assertThat("Expected the cartesian distance of 1.0", distance, closeTo(1.0, 0.00001)); } @@ -391,7 +383,7 @@ public void create_point_and_pass_as_param() { "geometry"); double distance = (Double) executeObject( "WITH spatial.asGeometry($geom) AS geometry RETURN point.distance(geometry, point({latitude: 5.1, longitude: 4.0})) as distance", - map("geom", geom), "distance"); + Map.of("geom", geom), "distance"); MatcherAssert.assertThat("Expected the geographic distance of 11132km", distance, closeTo(11132.0, 1.0)); } @@ -443,7 +435,7 @@ private Object executeObject(String call, String column) { private Object executeObject(String call, Map params, String column) { Object obj; try (Transaction tx = db.beginTx()) { - Map p = (params == null) ? map() : params; + Map p = (params == null) ? Map.of() : params; ResourceIterator values = tx.execute(call, p).columnAs(column); obj = values.next(); values.close(); @@ -630,7 +622,7 @@ public void create_a_wkt_layer_using_know_format() { public void list_layer_names() { String wkt = "LINESTRING (15.2 60.1, 15.3 60.1)"; execute("CALL spatial.addWKTLayer('geom','wkt')"); - execute("CALL spatial.addWKT('geom',$wkt)", map("wkt", wkt)); + execute("CALL spatial.addWKT('geom',$wkt)", Map.of("wkt", wkt)); testCall(db, "CALL spatial.layers()", (r) -> { assertEquals("geom", r.get("name")); @@ -654,14 +646,14 @@ public void add_and_remove_multiple_layers() { for (int i = 0; i < NUM_LAYERS; i++) { String name = "wktLayer_" + i; testCallCount(db, "CALL spatial.layers()", null, i); - execute("CALL spatial.addWKTLayer($layerName,'wkt')", map("layerName", name)); - execute("CALL spatial.addWKT($layerName,$wkt)", map("wkt", wkt, "layerName", name)); + execute("CALL spatial.addWKTLayer($layerName,'wkt')", Map.of("layerName", name)); + execute("CALL spatial.addWKT($layerName,$wkt)", Map.of("wkt", wkt, "layerName", name)); testCallCount(db, "CALL spatial.layers()", null, i + 1); } for (int i = 0; i < NUM_LAYERS; i++) { String name = "wktLayer_" + i; testCallCount(db, "CALL spatial.layers()", null, NUM_LAYERS - i); - execute("CALL spatial.removeLayer($layerName)", map("layerName", name)); + execute("CALL spatial.removeLayer($layerName)", Map.of("layerName", name)); testCallCount(db, "CALL spatial.layers()", null, NUM_LAYERS - i - 1); } testCallCount(db, "CALL spatial.layers()", null, 0); @@ -752,7 +744,7 @@ public void list_layer_types() { public void find_layer() { String wkt = "LINESTRING (15.2 60.1, 15.3 60.1)"; execute("CALL spatial.addWKTLayer('geom','wkt')"); - execute("CALL spatial.addWKT('geom',$wkt)", map("wkt", wkt)); + execute("CALL spatial.addWKT('geom',$wkt)", Map.of("wkt", wkt)); testCall(db, "CALL spatial.layer('geom')", (r) -> assertEquals("geom", (dump((Node) r.get("node"))).getProperty("layer"))); @@ -927,9 +919,9 @@ public void add_two_nodes_to_the_spatial_layer() { }); try (Transaction tx = db.beginTx()) { Node node = (Node) tx.execute("MATCH (node) WHERE elementId(node) = $nodeId RETURN node", - map("nodeId", node1)).next().get("node"); + Map.of("nodeId", node1)).next().get("node"); Result removeResult = tx.execute("CALL spatial.removeNode('geom',$node) YIELD nodeId RETURN nodeId", - map("node", node)); + Map.of("node", node)); assertEquals(node1, removeResult.next().get("nodeId")); removeResult.close(); tx.commit(); @@ -941,7 +933,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)); + Map.of("nodeId", node2)); assertEquals(node2, removeResult.next().get("nodeId")); removeResult.close(); tx.commit(); @@ -960,7 +952,7 @@ public void add_many_nodes_to_the_simple_point_layer_using_addNodes() { "WITH collect(n) as points\n" + "CALL spatial.addNodes('simple_poi',points) YIELD count\n" + "RETURN count"; - testCountQuery("addNodes", query, count, "count", map("count", count)); + testCountQuery("addNodes", query, count, "count", Map.of("count", count)); testRemoveNodes("simple_poi", count); } @@ -974,7 +966,7 @@ public void add_many_nodes_to_the_simple_point_layer_using_addNode() { "WITH n\n" + "CALL spatial.addNode('simple_poi',n) YIELD node\n" + "RETURN count(node)"; - testCountQuery("addNode", query, count, "count(node)", map("count", count)); + testCountQuery("addNode", query, count, "count(node)", Map.of("count", count)); testRemoveNode("simple_poi", count); } @@ -989,7 +981,7 @@ public void add_many_nodes_to_the_native_point_layer_using_addNodes() { "WITH collect(n) as points\n" + "CALL spatial.addNodes('native_poi',points) YIELD count\n" + "RETURN count"; - testCountQuery("addNodes", query, count, "count", map("count", count)); + testCountQuery("addNodes", query, count, "count", Map.of("count", count)); testRemoveNodes("native_poi", count); } @@ -1004,7 +996,7 @@ public void add_many_nodes_to_the_native_point_layer_using_addNode() { "WITH n\n" + "CALL spatial.addNode('native_poi',n) YIELD node\n" + "RETURN count(node)"; - testCountQuery("addNode", query, count, "count(node)", map("count", count)); + testCountQuery("addNode", query, count, "count(node)", Map.of("count", count)); testRemoveNode("native_poi", count); } @@ -1019,7 +1011,7 @@ private void testRemoveNode(String layer, int count) { "WITH n\n" + "CALL spatial.removeNode('" + layer + "',n) YIELD nodeId\n" + "RETURN count(nodeId)"; - testCountQuery("removeNode", remove, count / 2, "count(nodeId)", map("count", count / 2)); + testCountQuery("removeNode", remove, count / 2, "count(nodeId)", Map.of("count", count / 2)); // Check that only half remain testCountQuery("withinDistance", "CALL spatial.withinDistance('" + layer + "',{lon:15.0,lat:60.0},1000) YIELD node RETURN count(node)", @@ -1037,7 +1029,7 @@ private void testRemoveNodes(String layer, int count) { "WITH collect(n) as points\n" + "CALL spatial.removeNodes('" + layer + "',points) YIELD count\n" + "RETURN count"; - testCountQuery("removeNodes", remove, count / 2, "count", map("count", count / 2)); + testCountQuery("removeNodes", remove, count / 2, "count", Map.of("count", count / 2)); // Check that only half remain testCountQuery("withinDistance", "CALL spatial.withinDistance('" + layer + "',{lon:15.0,lat:60.0},1000) YIELD node RETURN count(node)", @@ -1146,7 +1138,7 @@ public void import_osm_and_add_geometry() { @Test public void import_osm_and_polygons_withinDistance() { - Map params = map("osmFile", "withinDistance.osm", "busShelterID", 2938842290L); + Map params = Map.of("osmFile", "withinDistance.osm", "busShelterID", 2938842290L); execute("CALL spatial.addLayer('geom','OSM','')"); testCountQuery("importOSMAndPolygonsWithinDistance", "CALL spatial.importOSMToLayer('geom',$osmFile)", 74, "count", params); @@ -1204,18 +1196,17 @@ public void import_osm_and_polygons_withinDistance() { private void testCountQuery(String name, String query, long count, String column, Map params) { // warmup try (Transaction tx = db.beginTx()) { - Result results = tx.execute("EXPLAIN " + query, params == null ? map() : params); + Result results = tx.execute("EXPLAIN " + query, params == null ? Map.of() : params); results.close(); tx.commit(); } long start = System.currentTimeMillis(); testResult(db, query, params, res -> { assertTrue(res.hasNext(), "Expected a single result"); - long c = (Long) res.next().get(column); + long c = (Long) res.next().get(column); 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); } @@ -1326,7 +1317,7 @@ public void add_a_WKT_geometry_to_a_layer() { String lineString = "LINESTRING (15.2 60.1, 15.3 60.1)"; execute("CALL spatial.addWKTLayer('geom','wkt')"); - testCall(db, "CALL spatial.addWKT('geom',$wkt)", map("wkt", lineString), + testCall(db, "CALL spatial.addWKT('geom',$wkt)", Map.of("wkt", lineString), r -> assertEquals(lineString, dump(((Node) r.get("node"))).getProperty("wkt"))); } @@ -1334,7 +1325,7 @@ public void add_a_WKT_geometry_to_a_layer() { public void find_geometries_close_to_a_point_wkt() { String lineString = "LINESTRING (15.2 60.1, 15.3 60.1)"; execute("CALL spatial.addLayer('geom','WKT','wkt')"); - execute("CALL spatial.addWKT('geom',$wkt)", map("wkt", lineString)); + execute("CALL spatial.addWKT('geom',$wkt)", Map.of("wkt", lineString)); testCall(db, "CALL spatial.closest('geom',{lon:15.2, lat:60.1}, 1.0)", r -> assertEquals(lineString, (dump((Node) r.get("node"))).getProperty("wkt"))); } @@ -1343,7 +1334,7 @@ public void find_geometries_close_to_a_point_wkt() { public void find_geometries_close_to_a_point_geohash() { String lineString = "POINT (15.2 60.1)"; execute("CALL spatial.addLayer('geom','geohash','lon:lat')"); - execute("CALL spatial.addWKT('geom',$wkt)", map("wkt", lineString)); + execute("CALL spatial.addWKT('geom',$wkt)", Map.of("wkt", lineString)); testCallCount(db, "CALL spatial.closest('geom',{lon:15.2, lat:60.1}, 1.0)", null, 1); } @@ -1351,7 +1342,7 @@ public void find_geometries_close_to_a_point_geohash() { public void find_geometries_close_to_a_point_zorder() { String lineString = "POINT (15.2 60.1)"; execute("CALL spatial.addLayer('geom','zorder','lon:lat')"); - execute("CALL spatial.addWKT('geom',$wkt)", map("wkt", lineString)); + execute("CALL spatial.addWKT('geom',$wkt)", Map.of("wkt", lineString)); testCallCount(db, "CALL spatial.closest('geom',{lon:15.2, lat:60.1}, 1.0)", null, 1); } @@ -1359,7 +1350,7 @@ public void find_geometries_close_to_a_point_zorder() { public void find_geometries_close_to_a_point_hilbert() { String lineString = "POINT (15.2 60.1)"; execute("CALL spatial.addLayer('geom','hilbert','lon:lat')"); - execute("CALL spatial.addWKT('geom',$wkt)", map("wkt", lineString)); + execute("CALL spatial.addWKT('geom',$wkt)", Map.of("wkt", lineString)); testCallCount(db, "CALL spatial.closest('geom',{lon:15.2, lat:60.1}, 1.0)", null, 1); }