diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java index 3d7c963..8342278 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataAvailability.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.mapwithai.backend; import java.io.IOException; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java index 649f2a8..2f7c8f8 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITask.java @@ -1,3 +1,4 @@ +// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.mapwithai.backend; import static org.openstreetmap.josm.tools.I18n.tr; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java index de5c5fb..f5fc651 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java @@ -59,7 +59,6 @@ public class GetDataRunnable extends RecursiveTask { private static final int MAX_NUMBER_OF_BBOXES_TO_PROCESS = 1; private static final String SERVER_ID_KEY = "server_id"; - private static final int DEFAULT_TIMEOUT = 50_000; // 50 seconds private static final double ARTIFACT_ANGLE = 0.1745; // 10 degrees in radians diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java index 0afd492..e707ab5 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java @@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai.backend; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -27,6 +28,8 @@ import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.data.osm.WaySegment; import org.openstreetmap.josm.data.projection.ProjectionRegistry; +import org.openstreetmap.josm.gui.MainApplication; +import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.tools.Geometry; @@ -42,7 +45,7 @@ public class GetDataRunnableTest { public void setUp() { wireMock.start(); MapWithAIPreferenceHelper.setMapWithAIURLs(MapWithAIPreferenceHelper.getMapWithAIURLs().stream().map(map -> { - map.put("url", getDefaultMapWithAIAPIForTest( + map.put("url", getDefaultMapWithAIAPIForTest(wireMock, map.getOrDefault("url", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API))); return map; }).collect(Collectors.toList())); @@ -53,11 +56,11 @@ public class GetDataRunnableTest { wireMock.stop(); } - private String getDefaultMapWithAIAPIForTest(String url) { - return getDefaultMapWithAIAPIForTest(url, "https://www.facebook.com"); + public static String getDefaultMapWithAIAPIForTest(WireMockServer wireMock, String url) { + return getDefaultMapWithAIAPIForTest(wireMock, url, "https://www.facebook.com"); } - private String getDefaultMapWithAIAPIForTest(String url, String wireMockReplace) { + public static String getDefaultMapWithAIAPIForTest(WireMockServer wireMock, String url, String wireMockReplace) { return url.replace(wireMockReplace, wireMock.baseUrl()); } @@ -121,4 +124,29 @@ public class GetDataRunnableTest { assertFalse(ds.isEmpty()); assertFalse(ds.allNonDeletedPrimitives().isEmpty()); } + + @Test + public void testAlreadyAddedElements() { + Way addedWay = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 1))); + Way duplicateWay = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 1))); + Way nonDuplicateWay = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 2))); + + DataSet osm = new DataSet(); + addedWay.getNodes().forEach(osm::addPrimitive); + osm.addPrimitive(addedWay); + + DataSet conflationDs = new DataSet(); + for (Way way : Arrays.asList(duplicateWay, nonDuplicateWay)) { + way.getNodes().forEach(conflationDs::addPrimitive); + conflationDs.addPrimitive(way); + } + + MainApplication.getLayerManager().addLayer(new OsmDataLayer(osm, "OSM Layer", null)); + GetDataRunnable.removeAlreadyAddedData(conflationDs); + + assertAll(() -> assertTrue(duplicateWay.isDeleted(), "The duplicate way should be deleted"), + () -> duplicateWay.getNodes() + .forEach(node -> assertTrue(node.isDeleted(), "The duplicate way nodes should be deleted")), + () -> assertFalse(nonDuplicateWay.isDeleted(), "The non-duplicate way should not be deleted")); + } } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java index 8291e20..e9d73c5 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java @@ -22,6 +22,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.openstreetmap.josm.TestUtils; +import org.openstreetmap.josm.data.Bounds; import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.gpx.GpxData; import org.openstreetmap.josm.data.gpx.WayPoint; @@ -117,10 +118,13 @@ public class MapWithAIDataUtilsTest { } public static BBox getTestBBox() { - final BBox testBBox = new BBox(); - testBBox.add(new LatLon(39.0734162, -108.5707107)); - testBBox.add(new LatLon(39.0738791, -108.5715723)); - return testBBox; + return getTestBounds().toBBox(); + } + + public static Bounds getTestBounds() { + Bounds bound = new Bounds(39.0734162, -108.5707107); + bound.extend(39.0738791, -108.5715723); + return bound; } @Test