diff --git a/test/resources/wiremock/mappings/maps_ml_roads-5547df42-8d64-4a75-8a27-d598b4de5968.json b/test/resources/wiremock/mappings/maps_ml_roads-5547df42-8d64-4a75-8a27-d598b4de5968.json new file mode 100644 index 0000000..177ef96 --- /dev/null +++ b/test/resources/wiremock/mappings/maps_ml_roads-5547df42-8d64-4a75-8a27-d598b4de5968.json @@ -0,0 +1,28 @@ +{ + "id" : "5547df42-8d64-4a75-8a27-d598b4de5968", + "name" : "maps_ml_roads", + "request" : { + "url" : "/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=josm&token=ASb3N5o9HbX8QWn8G_NtHIRQaYv3nuG2r7_f3vnGld3KhZNCxg57IsaQyssIaEw5rfRNsPpMwg4TsnrSJtIJms5m&hash=ASawRla3rBcwEjY4HIY&bbox=-108.5715723,39.0734162,-108.5707107,39.0738791", + "method" : "GET" + }, + "response" : { + "status" : 200, + "body" : "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", + "headers" : { + "Content-Type" : "text/xml; charset=UTF-8", + "Strict-Transport-Security" : "max-age=15552000; preload", + "Vary" : "Accept-Encoding", + "X-Content-Type-Options" : "nosniff", + "X-Frame-Options" : "DENY", + "X-XSS-Protection" : "0", + "Access-Control-Allow-Origin" : "https://facebook.com", + "X-FB-Debug" : "PO3X3PMMLb3HV54QiTBVn22/bnfz0ZqWTjvT4wBDXxjrZCbSWSX8/uGfQ7ItzmBiQQJ0ytFBpHWmvZm48YWdUQ==", + "Date" : "Wed, 18 Dec 2019 20:28:03 GMT", + "Alt-Svc" : "h3-24=\":443\"; ma=3600", + "Connection" : "keep-alive" + } + }, + "uuid" : "5547df42-8d64-4a75-8a27-d598b4de5968", + "persistent" : true, + "insertionIndex" : 18 +} \ No newline at end of file diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITaskTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITaskTest.java new file mode 100644 index 0000000..a5bba46 --- /dev/null +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/DownloadMapWithAITaskTest.java @@ -0,0 +1,67 @@ +// License: GPL. For details, see LICENSE file. +package org.openstreetmap.josm.plugins.mapwithai.backend; + +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; +import static org.junit.jupiter.api.Assertions.assertAll; +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 java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.stream.Collectors; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; +import org.openstreetmap.josm.gui.progress.NullProgressMonitor; +import org.openstreetmap.josm.testutils.JOSMTestRules; + +import com.github.tomakehurst.wiremock.WireMockServer; + +public class DownloadMapWithAITaskTest { + @Rule + public JOSMTestRules rule = new JOSMTestRules().preferences().fakeAPI().projection(); + WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")); + + @Before + public void setUp() { + wireMock.start(); + MapWithAIPreferenceHelper.setMapWithAIURLs(MapWithAIPreferenceHelper.getMapWithAIURLs().stream().map(map -> { + map.put("url", GetDataRunnableTest.getDefaultMapWithAIAPIForTest(wireMock, + map.getOrDefault("url", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API))); + return map; + }).collect(Collectors.toList())); + } + + @After + public void tearDown() { + wireMock.stop(); + } + + @Test + public void testDownloadOsmServerReaderDownloadParamsBoundsProgressMonitor() + throws InterruptedException, ExecutionException { + DownloadMapWithAITask task = new DownloadMapWithAITask(); + Future future = task.download( + new BoundingBoxMapWithAIDownloader(MapWithAIDataUtilsTest.getTestBounds(), + MapWithAIPreferenceHelper.getMapWithAIUrl().get(0).get("url"), false), + new DownloadParams(), MapWithAIDataUtilsTest.getTestBounds(), NullProgressMonitor.INSTANCE); + future.get(); + assertNotNull(task.getDownloadedData(), "Data should be downloaded"); + } + + @Test + public void testGetConfirmationMessage() throws MalformedURLException { + DownloadMapWithAITask task = new DownloadMapWithAITask(); + assertAll( + () -> assertTrue(task.getConfirmationMessage(new URL("https://fake.api")).contains("fake.api"), + "We should get a confirmation message"), + () -> assertNull(task.getConfirmationMessage(null), "The message should be null if the URL is null")); + } + +} 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 e707ab5..c011fa1 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnableTest.java @@ -37,7 +37,7 @@ import com.github.tomakehurst.wiremock.WireMockServer; public class GetDataRunnableTest { @Rule - public JOSMTestRules rule = new JOSMTestRules().projection(); + public JOSMTestRules rule = new JOSMTestRules().projection().fakeAPI(); WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock")); 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 e9d73c5..29acd36 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtilsTest.java @@ -122,7 +122,7 @@ public class MapWithAIDataUtilsTest { } public static Bounds getTestBounds() { - Bounds bound = new Bounds(39.0734162, -108.5707107); + Bounds bound = new Bounds(new LatLon(39.0734162, -108.5707107)); bound.extend(39.0738791, -108.5715723); return bound; }