kopia lustrzana https://github.com/JOSM/MapWithAI
Add basic test for conflation (BoundingBoxMapWithAIDownloaderTest)
Signed-off-by: Taylor Smock <tsmock@fb.com>pull/1/head
rodzic
a739e55eb7
commit
62f43c10ff
|
@ -81,7 +81,7 @@ def versions = [
|
|||
junit: "5.8.2",
|
||||
pmd: "6.20.0",
|
||||
spotbugs: "4.5.0",
|
||||
wiremock: "2.27.2",
|
||||
wiremock: "2.32.0",
|
||||
findsecbugs: "1.11.0",
|
||||
]
|
||||
|
||||
|
@ -99,7 +99,7 @@ dependencies {
|
|||
testImplementation("org.jmockit:jmockit:${versions.jmockit}")
|
||||
testImplementation("com.github.spotbugs:spotbugs-annotations:${versions.spotbugs}")
|
||||
testImplementation("org.openstreetmap.josm:josm-unittest:"){changing=true}
|
||||
testImplementation("com.github.tomakehurst:wiremock:${versions.wiremock}")
|
||||
testImplementation("com.github.tomakehurst:wiremock-jre8:${versions.wiremock}")
|
||||
testImplementation("org.awaitility:awaitility:${versions.awaitility}")
|
||||
}
|
||||
|
||||
|
|
|
@ -3,15 +3,12 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonValue;
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import java.awt.geom.Area;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
@ -20,6 +17,10 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonValue;
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import org.openstreetmap.josm.data.Bounds;
|
||||
import org.openstreetmap.josm.data.DataSource;
|
||||
import org.openstreetmap.josm.data.osm.DataSet;
|
||||
|
@ -176,8 +177,7 @@ public class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
|
|||
protected DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
|
||||
DataSet ds;
|
||||
String contentType = this.activeConnection.getResponse().getContentType();
|
||||
if (contentType.contains("text/json") || contentType.contains("application/json")
|
||||
|| contentType.contains("application/geo+json")
|
||||
if (Arrays.asList("text/json", "application/json", "application/geo+json").contains(contentType)
|
||||
// Fall back to Esri Feature Server check. They don't always indicate a json
|
||||
// return type. :(
|
||||
|| this.info.getSourceType() == MapWithAIType.ESRI_FEATURE_SERVER) {
|
||||
|
|
|
@ -3,19 +3,23 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.openstreetmap.josm.data.Bounds;
|
||||
import org.openstreetmap.josm.data.osm.DataSet;
|
||||
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAIConfig;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
|
||||
|
@ -26,7 +30,12 @@ import org.openstreetmap.josm.testutils.annotations.HTTP;
|
|||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
import com.github.tomakehurst.wiremock.admin.model.GetServeEventsResult;
|
||||
import com.github.tomakehurst.wiremock.admin.model.ServeEventQuery;
|
||||
import com.github.tomakehurst.wiremock.client.WireMock;
|
||||
import com.github.tomakehurst.wiremock.http.Request;
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
|
||||
|
||||
/**
|
||||
* Test class for {@link BoundingBoxMapWithAIDownloader}
|
||||
|
@ -49,7 +58,7 @@ class BoundingBoxMapWithAIDownloaderTest {
|
|||
void testEsriExceededTransferLimit(String responseType) {
|
||||
final Bounds downloadBounds = new Bounds(10, 10, 20, 20);
|
||||
final MapWithAIInfo info = new MapWithAIInfo("testEsriExceededTransferLimit",
|
||||
wireMockServer.baseUrl() + "/esriExceededLimit");
|
||||
this.wireMockServer.baseUrl() + "/esriExceededLimit");
|
||||
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
|
||||
downloadBounds, info, false);
|
||||
final JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
|
||||
|
@ -73,4 +82,34 @@ class BoundingBoxMapWithAIDownloaderTest {
|
|||
assertTrue(errors.get(0).contains("Could not fully download"));
|
||||
assertTrue(ds.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThirdPartyConflation() {
|
||||
MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
|
||||
final MapWithAIInfo info = new MapWithAIInfo("testThirdPartyConflation",
|
||||
this.wireMockServer.baseUrl() + "/testThirdPartyConflation");
|
||||
// ADDRESS has a default /conflate endpoint from a mocked copy of conflation
|
||||
// servers.
|
||||
info.setCategory(MapWithAICategory.ADDRESS);
|
||||
final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
|
||||
final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
|
||||
downloadBounds, info, false);
|
||||
this.wireMockServer.stubFor(WireMock.get("/testThirdPartyConflation").willReturn(WireMock.aResponse().withBody(
|
||||
"<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/><node id=\"2\" lat=\"1\" lon=\"1\" version=\"1\"/></osm>")));
|
||||
final StubMapping conflationStub = this.wireMockServer
|
||||
.stubFor(WireMock.post("/conflate").willReturn(WireMock.aResponse()
|
||||
.withBody("<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/></osm>")));
|
||||
final DataSet ds = assertDoesNotThrow(
|
||||
() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
|
||||
assertEquals(1, ds.allPrimitives().size());
|
||||
assertEquals(1L, ds.allPrimitives().iterator().next().getPrimitiveId().getUniqueId());
|
||||
|
||||
final GetServeEventsResult serveEvents = this.wireMockServer
|
||||
.getServeEvents(ServeEventQuery.forStubMapping(conflationStub));
|
||||
assertEquals(1, serveEvents.getRequests().size());
|
||||
final LoggedRequest request = serveEvents.getRequests().get(0).getRequest();
|
||||
assertEquals(1, request.getParts().size(),
|
||||
request.getParts().stream().map(Request.Part::getName).collect(Collectors.joining(",")));
|
||||
assertNotNull(request.getPart("external"));
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue