kopia lustrzana https://github.com/JOSM/MapWithAI
Add test for DownloadMapWithAITask and fix some tests
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
ac885c04bb
commit
900737bd1b
|
@ -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" : "<?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.0738691\" maxlon=\"-108.57072358101\" minlat=\"39.0734262\" minlon=\"-108.57155941899\"/>\n <node action=\"modify\" id=\"-3625810361941368501\" lat=\"39.0736017\" lon=\"-108.5707451\" visible=\"true\">\n <tag k=\"conn\" v=\"w626760817,n5917002841,n5917002155\"/>\n </node>\n <node action=\"modify\" id=\"-373066400259132\" lat=\"39.0735933\" lon=\"-108.5709927\" visible=\"true\"/>\n <way action=\"modify\" id=\"-4444230471161502072\" orig_id=\"-1203473873173507\" visible=\"true\">\n <nd ref=\"-710999622096597555\"/>\n <nd ref=\"-373066400259132\"/>\n <nd ref=\"-3625810361941368501\"/>\n <tag k=\"highway\" v=\"residential\"/>\n <tag k=\"source\" v=\"digitalglobe\"/>\n </way>\n <node action=\"modify\" id=\"-710999622096597555\" lat=\"39.0736112\" lon=\"-108.5710852\" visible=\"true\">\n <tag k=\"dupe\" v=\"n6815623346\"/>\n </node>\n <node action=\"modify\" id=\"-2406517166226748\" lat=\"39.0736540\" lon=\"-108.5718322\" visible=\"true\">\n <tag k=\"dupe\" v=\"n5907055578\"/>\n </node>\n <node action=\"modify\" id=\"-2406517166226748\" lat=\"39.0736540\" lon=\"-108.5718322\" visible=\"true\">\n <tag k=\"dupe\" v=\"n6815623345\"/>\n </node>\n <way action=\"modify\" id=\"-4444230471161502073\" orig_id=\"-1203473873173507\" visible=\"true\">\n <nd ref=\"-2406517166226748\"/>\n <nd ref=\"-2406517166226748\"/>\n <tag k=\"highway\" v=\"service\"/>\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" : "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
|
||||
}
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
|
@ -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"));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue