diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControl.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControl.java
index 1b69957..794b642 100644
--- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControl.java
+++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControl.java
@@ -129,7 +129,7 @@ public class MapWithAIRemoteControl extends RequestHandler.RawURLParseRequestHan
sb.append(tr("We will download data in ")).append(download.toStringCSV(",")).append(br);
}
if (crop != null) {
- sb.append(tr("We will crop the data to")).append(crop.toStringCSV(",")).append(br);
+ sb.append(tr("We will crop the data to ")).append(crop.toStringCSV(",")).append(br);
}
sb.append(tr("There is a maximum addition of {0} objects at one time", maxObj));
return sb.toString();
diff --git a/test/resources/wiremock/mappings/maps_ml_roads-2527ed5c-1fc5-49c3-93b4-5c38323770f2.json b/test/resources/wiremock/mappings/maps_ml_roads-2527ed5c-1fc5-49c3-93b4-5c38323770f2.json
new file mode 100644
index 0000000..eeb9e06
--- /dev/null
+++ b/test/resources/wiremock/mappings/maps_ml_roads-2527ed5c-1fc5-49c3-93b4-5c38323770f2.json
@@ -0,0 +1,30 @@
+{
+ "id" : "2527ed5c-1fc5-49c3-93b4-5c38323770f2",
+ "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.4625,39.0621,-108.4594,39.0633",
+ "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 \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" : "4wfqXkCFMY11jcj4ckGFU9f8MP58lzqCIt8FlBXS1U+3QeVYgL5mmQMpNCSYiWm+D1cUufTvpzt44eAPpa8wCA==",
+ "Date" : "Wed, 20 Nov 2019 14:34:44 GMT",
+ "Alt-Svc" : "h3-23=\":443\"; ma=3600",
+ "Connection" : "keep-alive"
+ }
+ },
+ "uuid" : "2527ed5c-1fc5-49c3-93b4-5c38323770f2",
+ "persistent" : true,
+ "scenarioName" : "scenario-1-maps-ml_roads",
+ "requiredScenarioState" : "scenario-1-maps-ml_roads-2",
+ "insertionIndex" : 15
+}
\ No newline at end of file
diff --git a/test/resources/wiremock/mappings/maps_ml_roads-506ca06e-8d07-4762-ad45-32f69a0f3ecb.json b/test/resources/wiremock/mappings/maps_ml_roads-506ca06e-8d07-4762-ad45-32f69a0f3ecb.json
new file mode 100644
index 0000000..1ce100e
--- /dev/null
+++ b/test/resources/wiremock/mappings/maps_ml_roads-506ca06e-8d07-4762-ad45-32f69a0f3ecb.json
@@ -0,0 +1,31 @@
+{
+ "id" : "506ca06e-8d07-4762-ad45-32f69a0f3ecb",
+ "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.4625,39.0621,-108.4594,39.0633",
+ "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 \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" : "hNbBk003KWeBO3dOsB+94Y8uPRYJFURLqHqCLP7w1pwAVI2c38OkpZ7VBBCC5M4TVLar8VRjD7KFlC1Ero3avA==",
+ "Date" : "Wed, 20 Nov 2019 14:34:42 GMT",
+ "Alt-Svc" : "h3-23=\":443\"; ma=3600",
+ "Connection" : "keep-alive"
+ }
+ },
+ "uuid" : "506ca06e-8d07-4762-ad45-32f69a0f3ecb",
+ "persistent" : true,
+ "scenarioName" : "scenario-1-maps-ml_roads",
+ "requiredScenarioState" : "Started",
+ "newScenarioState" : "scenario-1-maps-ml_roads-2",
+ "insertionIndex" : 13
+}
\ No newline at end of file
diff --git a/test/resources/wiremock/mappings/maps_ml_roads-65180ede-85cf-4fc0-94b4-8ae6ecd4c8c0.json b/test/resources/wiremock/mappings/maps_ml_roads-65180ede-85cf-4fc0-94b4-8ae6ecd4c8c0.json
new file mode 100644
index 0000000..d70701d
--- /dev/null
+++ b/test/resources/wiremock/mappings/maps_ml_roads-65180ede-85cf-4fc0-94b4-8ae6ecd4c8c0.json
@@ -0,0 +1,28 @@
+{
+ "id" : "65180ede-85cf-4fc0-94b4-8ae6ecd4c8c0",
+ "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=0.0,0.0,0.001,0.001&crop_bbox=0.0,0.0,0.001,0.001",
+ "method" : "GET"
+ },
+ "response" : {
+ "status" : 200,
+ "body" : "\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" : "8mHqShqG9xtWOu9e6u4iVvAadFNyNs3qT/T5BmQnE7UnM4CtSFX6G1MtUN9d7ajrR2B7tAn9cAfwoNYau90EQA==",
+ "Date" : "Wed, 20 Nov 2019 14:34:44 GMT",
+ "Alt-Svc" : "h3-23=\":443\"; ma=3600",
+ "Connection" : "keep-alive"
+ }
+ },
+ "uuid" : "65180ede-85cf-4fc0-94b4-8ae6ecd4c8c0",
+ "persistent" : true,
+ "insertionIndex" : 14
+}
\ No newline at end of file
diff --git a/test/resources/wiremock/wiremock-standalone-2.25.1.jar b/test/resources/wiremock/wiremock-standalone-2.25.1.jar
deleted file mode 100644
index 7505507..0000000
Binary files a/test/resources/wiremock/wiremock-standalone-2.25.1.jar and /dev/null differ
diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControlTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControlTest.java
index 03f84f2..23671e9 100644
--- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControlTest.java
+++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIRemoteControlTest.java
@@ -3,11 +3,15 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.openstreetmap.josm.tools.I18n.tr;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -15,6 +19,7 @@ import org.junit.rules.ExpectedException;
import org.openstreetmap.josm.data.osm.BBox;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
+import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.tools.Utils;
@@ -87,21 +92,21 @@ public class MapWithAIRemoteControlTest {
public void testNominalRequest() throws Exception {
newHandler("https://localhost?url="
+ Utils.encodeUrl(MapWithAIPreferenceHelper.getMapWithAIUrl().get(0).get("url"))).handle();
- Assert.assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
+ assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
- Assert.assertTrue(MapWithAIDataUtils.getLayer(false).getDataSet().getDataSourceBounds().isEmpty());
+ assertTrue(MapWithAIDataUtils.getLayer(false).getDataSet().getDataSourceBounds().isEmpty());
}
@Test
public void testTemporaryUrl() throws Exception {
final String badUrl = "https://bad.url";
newHandler("https://localhost?url=" + Utils.encodeUrl(badUrl)).handle();
- Assert.assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
+ assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
- Assert.assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
+ assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
.anyMatch(map -> badUrl.equals(map.get("url"))));
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
- Assert.assertNotEquals(badUrl, MapWithAIPreferenceHelper.getMapWithAIUrl());
+ assertNotEquals(badUrl, MapWithAIPreferenceHelper.getMapWithAIUrl());
final String badUrl2 = "NothingToSeeHere";
thrown.expect(RequestHandlerBadRequestException.class);
@@ -115,11 +120,11 @@ public class MapWithAIRemoteControlTest {
final Integer maxObj = 1;
newHandler("http://127.0.0.1:8111/mapwithai?bbox=" + getTestBBox().toStringCSV(",") + "&max_obj="
+ maxObj.toString()).handle();
- Assert.assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
+ assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
- Assert.assertEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
+ assertEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
- Assert.assertNotEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
+ assertNotEquals(maxObj.intValue(), MapWithAIPreferenceHelper.getMaximumAddition());
thrown.expect(RequestHandlerBadRequestException.class);
thrown.expectMessage("NumberFormatException (For input string: \"BAD_VALUE\")");
@@ -132,13 +137,13 @@ public class MapWithAIRemoteControlTest {
public void testBBox() throws Exception {
BBox temp = getTestBBox();
newHandler("http://127.0.0.1:8111/mapwithai?bbox={bbox}".replace("{bbox}", temp.toStringCSV(","))).handle();
- Assert.assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
+ assertFalse(MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).isEmpty());
await().atMost(10, TimeUnit.SECONDS)
.until(() -> !MapWithAIDataUtils.getLayer(false).getDataSet().getDataSourceBounds().isEmpty());
final BBox added = MapWithAIDataUtils.getLayer(false).getDataSet().getDataSourceBounds().iterator().next().toBBox();
- Assert.assertTrue(temp.bounds(added));
+ assertTrue(temp.bounds(added));
MainApplication.getLayerManager().removeLayer(MapWithAIDataUtils.getLayer(false));
temp = new BBox(39.0621223, -108.4625421, 39.0633059, -108.4594728);
@@ -147,4 +152,48 @@ public class MapWithAIRemoteControlTest {
"Bad bbox: 39.0621223,-108.4625421,39.0633059,-108.4594728 (converted to [ x: 39.0621223 -> 39.0633059, y: -108.4625421 -> -108.4594728 ])");
newHandler("http://127.0.0.1:8111/mapwithai?bbox={bbox}".replace("{bbox}", temp.toStringCSV(","))).handle();
}
+
+ @Test
+ public void testGetUsage() throws Exception {
+ assertEquals(tr("downloads {0} data", MapWithAIPlugin.NAME), newHandler(null).getUsage());
+ }
+
+ @Test
+ public void testGetPermissionMessage() throws Exception {
+ MapWithAIRemoteControl handler = newHandler(null);
+ assertEquals(tr(
+ "Remote Control has been asked to load data from the API. (null)
MapWithAI will automatically switch layers.
There is a maximum addition of null objects at one time"),
+ handler.getPermissionMessage());
+ handler = newHandler("http://127.0.0.1:8111/mapwithai?switch_layer=false");
+ handler.handle();
+ assertEquals(tr(
+ "Remote Control has been asked to load data from the API. (null)
MapWithAI will not automatically switch layers.
There is a maximum addition of null objects at one time"),
+ handler.getPermissionMessage());
+ handler = newHandler("http://127.0.0.1:8111/mapwithai?switch_layer=true");
+ handler.handle();
+ assertEquals(tr(
+ "Remote Control has been asked to load data from the API. (null)
MapWithAI will automatically switch layers.
There is a maximum addition of null objects at one time"),
+ handler.getPermissionMessage());
+ handler = newHandler("http://127.0.0.1:8111/mapwithai?max_obj=1");
+ handler.handle();
+ assertEquals(tr(
+ "Remote Control has been asked to load data from the API. (null)
MapWithAI will automatically switch layers.
There is a maximum addition of 1 objects at one time"),
+ handler.getPermissionMessage());
+ handler = newHandler("http://127.0.0.1:8111/mapwithai?max_obj=5");
+ handler.handle();
+ assertEquals(tr(
+ "Remote Control has been asked to load data from the API. (null)
MapWithAI will automatically switch layers.
There is a maximum addition of 5 objects at one time"),
+ handler.getPermissionMessage());
+ BBox crop = new BBox(0, 0, 0.001, 0.001);
+ handler = newHandler("http://127.0.0.1:8111/mapwithai?crop_bbox=".concat(crop.toStringCSV(",")));
+ handler.handle();
+ assertEquals(tr(
+ "Remote Control has been asked to load data from the API. (null)
MapWithAI will automatically switch layers.
We will crop the data to 0.0,0.0,0.001,0.001
There is a maximum addition of null objects at one time"),
+ handler.getPermissionMessage());
+ }
+
+ @Test
+ public void testGetUsageExamples() throws Exception {
+ assertEquals(6, newHandler(null).getUsageExamples().length);
+ }
}