More tests for MapWithAIRemoteControl

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head v0.1.19
Taylor Smock 2019-11-20 07:38:17 -07:00
rodzic f659ca1f46
commit 2a94c3e04b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
6 zmienionych plików z 150 dodań i 12 usunięć

Wyświetl plik

@ -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();

Wyświetl plik

@ -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" : "<?xml version=\"1.0\"?>\n<osm attribution=\"http://www.openstreetmap.org/copyright\" copyright=\"OpenStreetMap and contributors\" generator=\"fb_conflation_service\" version=\"0.6\">\n <bounds maxlat=\"39.06329\" maxlon=\"-108.45941287902\" minlat=\"39.06211\" minlon=\"-108.46248712098\"/>\n <node action=\"modify\" id=\"-507451533360537\" lat=\"39.0627986\" lon=\"-108.4607434\" visible=\"true\">\n <tag k=\"conn\" v=\"w489117884,n1337868173,n2390205409\"/>\n </node>\n <node action=\"modify\" id=\"-447607076088874\" lat=\"39.0627944\" lon=\"-108.4614409\" visible=\"true\">\n <tag k=\"conn\" v=\"w489117884,n176212515,n1337868173\"/>\n </node>\n <node action=\"modify\" id=\"-367646030587413\" lat=\"39.0621490\" lon=\"-108.4614409\" visible=\"true\"/>\n <node action=\"modify\" id=\"-512424752862157\" lat=\"39.0621073\" lon=\"-108.4614624\" visible=\"true\"/>\n <node action=\"modify\" id=\"-2661924864034455\" lat=\"39.0618533\" lon=\"-108.4614677\" visible=\"true\"/>\n <node action=\"modify\" id=\"-1359413207542142\" lat=\"39.0624696\" lon=\"-108.4607273\" visible=\"true\"/>\n <node action=\"modify\" id=\"-480100986137751\" lat=\"39.0624363\" lon=\"-108.4607434\" visible=\"true\"/>\n <node action=\"modify\" id=\"-2324123227677172\" lat=\"39.0618533\" lon=\"-108.4607542\" visible=\"true\"/>\n <node action=\"modify\" id=\"-1665763650222613\" lat=\"39.0621573\" lon=\"-108.4610439\" visible=\"true\"/>\n <node action=\"modify\" id=\"-516655755810722\" lat=\"39.0624530\" lon=\"-108.4599172\" visible=\"true\"/>\n <way action=\"modify\" id=\"-3490187867011827995\" orig_id=\"-487611782050068\" visible=\"true\">\n <nd ref=\"-367646030587413\"/>\n <nd ref=\"-512424752862157\"/>\n <nd ref=\"-2661924864034455\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-580832622321925\" visible=\"true\">\n <nd ref=\"-367646030587413\"/>\n <nd ref=\"-1665763650222613\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-3490187867011827994\" orig_id=\"-487611782050068\" visible=\"true\">\n <nd ref=\"-367646030587413\"/>\n <nd ref=\"-447607076088874\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-414732926053825\" visible=\"true\">\n <nd ref=\"-507451533360537\"/>\n <nd ref=\"-1359413207542142\"/>\n <nd ref=\"-480100986137751\"/>\n <nd ref=\"-2324123227677172\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-2431015640267087\" visible=\"true\">\n <nd ref=\"-1359413207542142\"/>\n <nd ref=\"-516655755810722\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n</osm>\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
}

Wyświetl plik

@ -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" : "<?xml version=\"1.0\"?>\n<osm attribution=\"http://www.openstreetmap.org/copyright\" copyright=\"OpenStreetMap and contributors\" generator=\"fb_conflation_service\" version=\"0.6\">\n <bounds maxlat=\"39.06329\" maxlon=\"-108.45941287902\" minlat=\"39.06211\" minlon=\"-108.46248712098\"/>\n <node action=\"modify\" id=\"-507451533360537\" lat=\"39.0627986\" lon=\"-108.4607434\" visible=\"true\">\n <tag k=\"conn\" v=\"w489117884,n1337868173,n2390205409\"/>\n </node>\n <node action=\"modify\" id=\"-447607076088874\" lat=\"39.0627944\" lon=\"-108.4614409\" visible=\"true\">\n <tag k=\"conn\" v=\"w489117884,n176212515,n1337868173\"/>\n </node>\n <node action=\"modify\" id=\"-367646030587413\" lat=\"39.0621490\" lon=\"-108.4614409\" visible=\"true\"/>\n <node action=\"modify\" id=\"-512424752862157\" lat=\"39.0621073\" lon=\"-108.4614624\" visible=\"true\"/>\n <node action=\"modify\" id=\"-2661924864034455\" lat=\"39.0618533\" lon=\"-108.4614677\" visible=\"true\"/>\n <node action=\"modify\" id=\"-1359413207542142\" lat=\"39.0624696\" lon=\"-108.4607273\" visible=\"true\"/>\n <node action=\"modify\" id=\"-480100986137751\" lat=\"39.0624363\" lon=\"-108.4607434\" visible=\"true\"/>\n <node action=\"modify\" id=\"-2324123227677172\" lat=\"39.0618533\" lon=\"-108.4607542\" visible=\"true\"/>\n <node action=\"modify\" id=\"-1665763650222613\" lat=\"39.0621573\" lon=\"-108.4610439\" visible=\"true\"/>\n <node action=\"modify\" id=\"-516655755810722\" lat=\"39.0624530\" lon=\"-108.4599172\" visible=\"true\"/>\n <way action=\"modify\" id=\"-3490187867011827994\" orig_id=\"-487611782050068\" visible=\"true\">\n <nd ref=\"-367646030587413\"/>\n <nd ref=\"-512424752862157\"/>\n <nd ref=\"-2661924864034455\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-580832622321925\" visible=\"true\">\n <nd ref=\"-367646030587413\"/>\n <nd ref=\"-1665763650222613\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-3490187867011827995\" orig_id=\"-487611782050068\" visible=\"true\">\n <nd ref=\"-367646030587413\"/>\n <nd ref=\"-447607076088874\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-414732926053825\" visible=\"true\">\n <nd ref=\"-507451533360537\"/>\n <nd ref=\"-1359413207542142\"/>\n <nd ref=\"-480100986137751\"/>\n <nd ref=\"-2324123227677172\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <way action=\"modify\" id=\"-2431015640267087\" visible=\"true\">\n <nd ref=\"-1359413207542142\"/>\n <nd ref=\"-516655755810722\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n</osm>\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
}

Wyświetl plik

@ -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" : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<osm generator=\"NS_ROADS_SERVICE\" version=\"0.6\"><bounds maxlat=\"0.00099\" maxlon=\"0.00098999999999962\" minlat=\"1.0E-5\" minlon=\"1.0000000000381E-5\"/></osm>\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
}

Wyświetl plik

@ -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)<br />MapWithAI will automatically switch layers.<br />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)<br />MapWithAI will not automatically switch layers.<br />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)<br />MapWithAI will automatically switch layers.<br />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)<br />MapWithAI will automatically switch layers.<br />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)<br />MapWithAI will automatically switch layers.<br />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)<br />MapWithAI will automatically switch layers.<br />We will crop the data to 0.0,0.0,0.001,0.001<br />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);
}
}