From 12f6d46b0ecd1e020a1d3f2b94a2ac0a7f40daa1 Mon Sep 17 00:00:00 2001 From: Andreas Berger Date: Wed, 29 May 2024 18:28:13 +0200 Subject: [PATCH] migrate all tests to junit jupiter (#402) --- pom.xml | 8 +- .../org/neo4j/gis/spatial/LayersTest.java | 8 +- .../org/neo4j/gis/spatial/Neo4jTestUtils.java | 6 +- .../gis/spatial/RTreeBulkInsertTest.java | 93 ++++++++++--------- .../gis/spatial/TestSimplePointLayer.java | 2 +- .../gis/spatial/pipes/GeoPipesDocTest.java | 2 +- .../pipes/GeoPipesPerformanceTest.java | 6 +- .../procedures/SpatialProceduresTest.java | 93 ++++++++++--------- 8 files changed, 112 insertions(+), 106 deletions(-) diff --git a/pom.xml b/pom.xml index 4ea17a55..01274b05 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.13.0 ${neo4j.java.version} ${neo4j.java.version} @@ -304,12 +304,6 @@ - - org.junit.vintage - junit-vintage-engine - ${junit.version} - test - org.junit.jupiter junit-jupiter-engine diff --git a/src/test/java/org/neo4j/gis/spatial/LayersTest.java b/src/test/java/org/neo4j/gis/spatial/LayersTest.java index 535740c9..058e4f5b 100644 --- a/src/test/java/org/neo4j/gis/spatial/LayersTest.java +++ b/src/test/java/org/neo4j/gis/spatial/LayersTest.java @@ -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; @@ -274,12 +274,12 @@ private String testSpecificEditableLayer(String layerName, Class { 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(); @@ -388,7 +388,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(); } diff --git a/src/test/java/org/neo4j/gis/spatial/Neo4jTestUtils.java b/src/test/java/org/neo4j/gis/spatial/Neo4jTestUtils.java index aceb0802..174ae01a 100644 --- a/src/test/java/org/neo4j/gis/spatial/Neo4jTestUtils.java +++ b/src/test/java/org/neo4j/gis/spatial/Neo4jTestUtils.java @@ -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; @@ -117,7 +117,7 @@ public static void printTree(Node root, int depth) { public static void assertCollection(Collection 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)); } diff --git a/src/test/java/org/neo4j/gis/spatial/RTreeBulkInsertTest.java b/src/test/java/org/neo4j/gis/spatial/RTreeBulkInsertTest.java index 2e9e7250..94386c3b 100644 --- a/src/test/java/org/neo4j/gis/spatial/RTreeBulkInsertTest.java +++ b/src/test/java/org/neo4j/gis/spatial/RTreeBulkInsertTest.java @@ -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; @@ -49,11 +50,11 @@ import org.geotools.api.referencing.crs.CoordinateReferenceSystem; import org.geotools.data.neo4j.Neo4jFeatureBuilder; import org.geotools.referencing.crs.DefaultEngineeringCRS; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; import org.neo4j.dbms.api.DatabaseManagementService; @@ -94,17 +95,17 @@ public class RTreeBulkInsertTest { // While the current lucene index implmentation is so slow (16n/s) we disable all benchmarks for lucene backed indexes private static final boolean enableLucene = false; - @Before + @BeforeEach public void before() throws IOException { restart(); } - @After + @AfterEach public void after() throws IOException { doCleanShutdown(); } - @Ignore + @Disabled public void shouldDeleteRecursiveTree() { int depth = 5; int width = 2; @@ -185,7 +186,7 @@ private EditableLayer getOrCreateSimplePointLayer(String name, String index, Str } } - @Ignore + @Disabled public void shouldInsertSimpleRTree() { int width = 20; int blockSize = 10000; @@ -603,12 +604,12 @@ public void shouldInsertManyNodesInBulkWithHilbert_small() throws FactoryExcepti insertManyNodesInBulk(new HilbertIndexMaker("Coordinates", "Bulk", testConfigs.get("small")), 5000); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_small_10() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("small")); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesIndividuallyGreenesSplit_small_10() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("small")); } @@ -627,12 +628,12 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_small_10() throws Factor * Small model 250*250 nodes (shallow tree) */ - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_small_100() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("small")); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesIndividuallyGreenesSplit_small_100() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("small")); } @@ -681,12 +682,12 @@ public void shouldInsertManyNodesInBulkWithHilbert_medium() throws FactoryExcept insertManyNodesInBulk(new HilbertIndexMaker("Coordinates", "Bulk", testConfigs.get("medium")), 5000); } - @Ignore + @Disabled public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_medium_10() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("medium")); } - @Ignore + @Disabled public void shouldInsertManyNodesIndividuallyGreenesSplit_medium_10() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("medium")); } @@ -701,12 +702,12 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_10() throws Facto insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("medium")); } - @Ignore + @Disabled public void shouldInsertManyNodesInBulkWithQuadraticSplit_medium_10_merge() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("medium"), true); } - @Ignore + @Disabled public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_10_merge() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("medium"), true); } @@ -715,17 +716,17 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_10_merge() throws * Medium model 500*500 nodes (shallow tree - factor 100) */ - @Ignore + @Disabled public void shouldInsertManyNodesIndividuallyWithQuadraticSplit_medium_100() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("medium")); } - @Ignore + @Disabled public void shouldInsertManyNodesIndividuallyGreenesSplit_medium_100() throws FactoryException, IOException { insertManyNodesIndividually(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("medium")); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesInBulkWithQuadraticSplit_medium_100() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("medium")); } @@ -735,12 +736,12 @@ public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_100() throws Fact insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("medium")); } - @Ignore + @Disabled public void shouldInsertManyNodesInBulkWithQuadraticSplit_medium_100_merge() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("medium"), true); } - @Ignore + @Disabled public void shouldInsertManyNodesInBulkWithGreenesSplit_medium_100_merge() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("medium"), true); } @@ -779,22 +780,22 @@ public void shouldInsertManyNodesInBulkWithHilbert_large() throws FactoryExcepti insertManyNodesInBulk(new HilbertIndexMaker("Coordinates", "Bulk", testConfigs.get("large")), 5000); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesInBulkWithQuadraticSplit_large_10() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 10, testConfigs.get("large")); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesInBulkWithGreenesSplit_large_10() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 10, testConfigs.get("large")); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesInBulkWithQuadraticSplit_large_100() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.QUADRATIC_SPLIT, 5000, 100, testConfigs.get("large")); } - @Ignore // takes too long, change to @Test when benchmarking + @Disabled // takes too long, change to @Test when benchmarking public void shouldInsertManyNodesInBulkWithGreenesSplit_large_100() throws FactoryException, IOException { insertManyNodesInBulk(RTreeIndex.GREENES_SPLIT, 5000, 100, testConfigs.get("large")); } @@ -916,7 +917,7 @@ private void insertManyNodesIndividually(IndexMaker indexMaker, int blockSize) { * Run this manually to generate images of RTree that can be used for animation. * ffmpeg -f image2 -r 12 -i rtree-single/rtree-%d.png -r 12 -s 1280x960 rtree-single2_12fps.mp4 */ - @Ignore + @Disabled public void shouldInsertManyNodesIndividuallyAndGenerateImagesForAnimation() throws FactoryException, IOException { IndexTestConfig config = testConfigs.get("medium"); int blockSize = 5; @@ -1029,7 +1030,7 @@ private void insertManyNodesInBulk(IndexMaker indexMaker, int blockSize) { * Run this manually to generate images of RTree that can be used for animation. * ffmpeg -f image2 -r 12 -i rtree-single/rtree-%d.png -r 12 -s 1280x960 rtree-single2_12fps.mp4 */ - @Ignore + @Disabled public void shouldInsertManyNodesInBulkAndGenerateImagesForAnimation() throws FactoryException, IOException { IndexTestConfig config = testConfigs.get("medium"); int blockSize = 1000; @@ -1085,7 +1086,7 @@ public void shouldInsertManyNodesInBulkAndGenerateImagesForAnimation() throws Fa // debugIndexTree((RTreeIndex) layer.getIndex()); } - @Ignore + @Disabled public void shouldAccessIndexAfterBulkInsertion() throws Exception { // Use these two lines if you want to examine the output. // File dbPath = new File("target/var/BulkTest"); @@ -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(); } @@ -1152,14 +1153,14 @@ 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(); } System.out.println("\t" + (System.currentTimeMillis() - start) + "ms"); } - @Ignore + @Disabled public void shouldBuildTreeFromScratch() throws Exception { //GraphDatabaseService db = this.databases.database("BultTest2"); GraphDatabaseService db = this.db; @@ -1215,7 +1216,7 @@ public void shouldBuildTreeFromScratch() throws Exception { } } - @Ignore + @Disabled public void shouldPerformRTreeBulkInsertion() throws Exception { // Use this line if you want to examine the output. //GraphDatabaseService db = databases.database("BulkTest"); @@ -1492,8 +1493,8 @@ private List 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; } @@ -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) { @@ -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 { @@ -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) { @@ -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 leafMap; try (Transaction tx = db.beginTx()) { Result resultNumChildren = tx.execute(queryNumChildren, params); @@ -1803,7 +1806,7 @@ public String toString() { private static final LinkedHashSet allStats = new LinkedHashSet<>(); - @AfterClass + @AfterAll public static void afterClass() { System.out.println("\n\nComposite stats for " + allStats.size() + " tests run"); System.out.println(TestStats.headerString()); diff --git a/src/test/java/org/neo4j/gis/spatial/TestSimplePointLayer.java b/src/test/java/org/neo4j/gis/spatial/TestSimplePointLayer.java index fa984878..84d1d726 100644 --- a/src/test/java/org/neo4j/gis/spatial/TestSimplePointLayer.java +++ b/src/test/java/org/neo4j/gis/spatial/TestSimplePointLayer.java @@ -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; @@ -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 { diff --git a/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesDocTest.java b/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesDocTest.java index 0a2b9268..be7e8d13 100644 --- a/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesDocTest.java +++ b/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesDocTest.java @@ -630,7 +630,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 diff --git a/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesPerformanceTest.java b/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesPerformanceTest.java index 6903b86f..ade57e2c 100644 --- a/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesPerformanceTest.java +++ b/src/test/java/org/neo4j/gis/spatial/pipes/GeoPipesPerformanceTest.java @@ -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; @@ -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(); } 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 e5e4d379..eef17156 100644 --- a/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java +++ b/src/test/java/org/neo4j/gis/spatial/procedures/SpatialProceduresTest.java @@ -26,10 +26,11 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasKey; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +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.junit.jupiter.api.Assertions.fail; 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; @@ -46,11 +47,10 @@ import java.util.Map; import java.util.function.Consumer; import org.hamcrest.MatcherAssert; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.neo4j.configuration.GraphDatabaseInternalSettings; import org.neo4j.configuration.GraphDatabaseSettings; import org.neo4j.dbms.api.DatabaseManagementService; @@ -80,7 +80,7 @@ public class SpatialProceduresTest { private DatabaseManagementService databases; private GraphDatabaseService db; - @Before + @BeforeEach public void setUp() throws KernelException, IOException { Path dbRoot = new File("target/procedures").toPath(); FileUtils.deleteDirectory(dbRoot); @@ -92,7 +92,7 @@ public void setUp() throws KernelException, IOException { registerProceduresAndFunctions(db, SpatialProcedures.class); } - @After + @AfterEach public void tearDown() { databases.shutdown(); } @@ -130,11 +130,11 @@ public static void testCallFails(GraphDatabaseService db, String call, Map params, Consumer> consumer, boolean onlyOne) { testResult(db, call, params, (res) -> { - Assert.assertTrue("Expect at least one result but got none: " + call, res.hasNext()); + assertTrue(res.hasNext(), "Expect at least one result but got none: " + call); Map row = res.next(); consumer.accept(row); if (onlyOne) { - Assert.assertFalse("Expected only one result, but there are more", res.hasNext()); + assertFalse(res.hasNext(), "Expected only one result, but there are more"); } }); } @@ -143,11 +143,12 @@ public static void testCallCount(GraphDatabaseService db, String call, Map { int numLeft = count; while (numLeft > 0) { - assertTrue("Expected " + count + " results but found only " + (count - numLeft), res.hasNext()); + assertTrue(res.hasNext(), + "Expected " + count + " results but found only " + (count - numLeft)); res.next(); numLeft--; } - Assert.assertFalse("Expected " + count + " results but there are more", res.hasNext()); + assertFalse(res.hasNext(), "Expected " + count + " results but there are more"); }); } @@ -317,7 +318,7 @@ public void add_node_point_layer_and_search_multiple_points_precision_geohash() // assertEquals("Expected two nodes when using low precision", countLow, equalTo(2L)); long countHigh = execute( "call spatial.withinDistance('bar', {latitude:52.2029252,longitude:0.0905302}, 100) YIELD node RETURN node"); - assertEquals("Expected two nodes when using high precision", 2L, countHigh); + assertEquals(2L, countHigh, "Expected two nodes when using high precision"); } // @@ -344,7 +345,7 @@ 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"); - assertTrue("Should be Geometry type", geometry instanceof Geometry); + assertInstanceOf(Geometry.class, geometry, "Should be Geometry type"); } @Test @@ -352,14 +353,14 @@ 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"); - assertTrue("Should be Geometry type", geometry instanceof Geometry); + 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"); - assertTrue("Should be Geometry type", geometry instanceof Geometry); + assertInstanceOf(Geometry.class, geometry, "Should be Geometry type"); } @Test @@ -368,7 +369,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"); - assertTrue("Should be Geometry type", geometry instanceof Geometry); + assertInstanceOf(Geometry.class, geometry, "Should be Geometry type"); } @Test @@ -552,7 +553,8 @@ public void create_a_simple_pointlayer_using_named_encoder() { testCall(db, "CALL spatial.addLayerWithEncoder('geom','SimplePointEncoder','')", (r) -> { Node node = dump((Node) r.get("node")); assertEquals("geom", node.getProperty("layer")); - assertEquals("org.neo4j.gis.spatial.encoders.SimplePointEncoder", node.getProperty("geomencoder")); + assertEquals("org.neo4j.gis.spatial.encoders.SimplePointEncoder", + node.getProperty("geomencoder")); assertEquals("org.neo4j.gis.spatial.SimplePointLayer", node.getProperty("layer_class")); assertFalse(node.hasProperty(PROP_GEOMENCODER_CONFIG)); }); @@ -563,7 +565,8 @@ public void create_a_simple_pointlayer_using_named_and_configured_encoder() { testCall(db, "CALL spatial.addLayerWithEncoder('geom','SimplePointEncoder','x:y:mbr')", (r) -> { Node node = dump((Node) r.get("node")); assertEquals("geom", node.getProperty(PROP_LAYER)); - assertEquals("org.neo4j.gis.spatial.encoders.SimplePointEncoder", node.getProperty(PROP_GEOMENCODER)); + assertEquals("org.neo4j.gis.spatial.encoders.SimplePointEncoder", + node.getProperty(PROP_GEOMENCODER)); assertEquals("org.neo4j.gis.spatial.SimplePointLayer", node.getProperty(PROP_LAYER_CLASS)); assertEquals("x:y:mbr", node.getProperty(PROP_GEOMENCODER_CONFIG)); }); @@ -574,7 +577,8 @@ public void create_a_native_pointlayer_using_named_encoder() { testCall(db, "CALL spatial.addLayerWithEncoder('geom','NativePointEncoder','')", (r) -> { Node node = dump((Node) r.get("node")); assertEquals("geom", node.getProperty(PROP_LAYER)); - assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", node.getProperty(PROP_GEOMENCODER)); + assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", + node.getProperty(PROP_GEOMENCODER)); assertEquals("org.neo4j.gis.spatial.SimplePointLayer", node.getProperty(PROP_LAYER_CLASS)); assertFalse(node.hasProperty(PROP_GEOMENCODER_CONFIG)); }); @@ -585,7 +589,8 @@ public void create_a_native_pointlayer_using_named_and_configured_encoder() { testCall(db, "CALL spatial.addLayerWithEncoder('geom','NativePointEncoder','pos:mbr')", (r) -> { Node node = dump((Node) r.get("node")); assertEquals("geom", node.getProperty(PROP_LAYER)); - assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", node.getProperty(PROP_GEOMENCODER)); + assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", + node.getProperty(PROP_GEOMENCODER)); assertEquals("org.neo4j.gis.spatial.SimplePointLayer", node.getProperty(PROP_LAYER_CLASS)); assertEquals("pos:mbr", node.getProperty(PROP_GEOMENCODER_CONFIG)); }); @@ -596,7 +601,8 @@ public void create_a_native_pointlayer_using_named_and_configured_encoder_with_c testCall(db, "CALL spatial.addLayerWithEncoder('geom','NativePointEncoder','pos:mbr:Cartesian')", (r) -> { Node node = dump((Node) r.get("node")); assertEquals("geom", node.getProperty(PROP_LAYER)); - assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", node.getProperty(PROP_GEOMENCODER)); + assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", + node.getProperty(PROP_GEOMENCODER)); assertEquals("org.neo4j.gis.spatial.SimplePointLayer", node.getProperty(PROP_LAYER_CLASS)); assertEquals("pos:mbr:Cartesian", node.getProperty(PROP_GEOMENCODER_CONFIG)); }); @@ -607,7 +613,8 @@ public void create_a_native_pointlayer_using_named_and_configured_encoder_with_g testCall(db, "CALL spatial.addLayerWithEncoder('geom','NativePointEncoder','pos:mbr:WGS-84')", (r) -> { Node node = dump((Node) r.get("node")); assertEquals("geom", node.getProperty(PROP_LAYER)); - assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", node.getProperty(PROP_GEOMENCODER)); + assertEquals("org.neo4j.gis.spatial.encoders.NativePointEncoder", + node.getProperty(PROP_GEOMENCODER)); assertEquals("org.neo4j.gis.spatial.SimplePointLayer", node.getProperty(PROP_LAYER_CLASS)); assertEquals("pos:mbr:WGS-84", node.getProperty(PROP_GEOMENCODER_CONFIG)); }); @@ -682,9 +689,11 @@ public void list_spatial_procedures() { } assertEquals("spatial.procedures() :: (name :: STRING, signature :: STRING)", procs.get("spatial.procedures")); - assertEquals("spatial.layers() :: (name :: STRING, signature :: STRING)", procs.get("spatial.layers")); + assertEquals("spatial.layers() :: (name :: STRING, signature :: STRING)", + procs.get("spatial.layers")); assertEquals("spatial.layer(name :: STRING) :: (node :: NODE)", procs.get("spatial.layer")); - assertEquals("spatial.addLayer(name :: STRING, type :: STRING, encoderConfig :: STRING) :: (node :: NODE)", + assertEquals( + "spatial.addLayer(name :: STRING, type :: STRING, encoderConfig :: STRING) :: (node :: NODE)", procs.get("spatial.addLayer")); assertEquals("spatial.addNode(layerName :: STRING, node :: NODE) :: (node :: NODE)", procs.get("spatial.addNode")); @@ -755,7 +764,7 @@ 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 -> Assert.assertEquals(node, r.get("node"))); + r -> assertEquals(node, r.get("node"))); } @Test @@ -763,7 +772,7 @@ 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 -> Assert.assertEquals(node, r.get("node"))); + r -> assertEquals(node, r.get("node"))); } @Test @@ -771,7 +780,7 @@ 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 -> Assert.assertEquals(node, r.get("node"))); + r -> assertEquals(node, r.get("node"))); } @Test @@ -779,7 +788,7 @@ 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 -> Assert.assertEquals(node, r.get("node"))); + r -> assertEquals(node, r.get("node"))); } @Test @@ -810,7 +819,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 -> Assert.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 -> assertEquals(node, r.get("node"))); testCall(db, "CALL spatial.withinDistance('" + layerName + "',{lon:15.0,lat:60.0},100)", @@ -882,7 +891,7 @@ 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 -> Assert.assertEquals(node, r.get("node"))); + r -> assertEquals(node, r.get("node"))); } @Test @@ -890,7 +899,7 @@ 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 -> Assert.assertEquals(node, r.get("node"))); + r -> assertEquals(node, r.get("node"))); } @Test @@ -905,7 +914,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"); - Assert.assertEquals(2L, count); + assertEquals(2L, count); result.close(); tx.commit(); } @@ -921,7 +930,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)); - Assert.assertEquals(node1, removeResult.next().get("nodeId")); + assertEquals(node1, removeResult.next().get("nodeId")); removeResult.close(); tx.commit(); } @@ -933,7 +942,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)); - Assert.assertEquals(node2, removeResult.next().get("nodeId")); + assertEquals(node2, removeResult.next().get("nodeId")); removeResult.close(); tx.commit(); } @@ -1101,7 +1110,7 @@ public void import_osm_twice_should_pass_with_different_layers() { 217); } - @Ignore + @Disabled public void import_cracow_to_layer() { execute("CALL spatial.addLayer('geom','OSM','')"); testCountQuery("importCracowToLayer", "CALL spatial.importOSMToLayer('geom','issue-347/cra.osm')", 256253, @@ -1201,10 +1210,10 @@ private void testCountQuery(String name, String query, long count, String column } long start = System.currentTimeMillis(); testResult(db, query, params, res -> { - assertTrue("Expected a single result", res.hasNext()); + assertTrue(res.hasNext(), "Expected a single result"); long c = (Long) res.next().get(column); - assertFalse("Expected a single result", res.hasNext()); - Assert.assertEquals("Expected count of " + count + " nodes but got " + c, count, 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);