diff --git a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloaderTest.java b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloaderTest.java
index d2fec266..182735a2 100644
--- a/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloaderTest.java
+++ b/src/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/BoundingBoxMapWithAIDownloaderTest.java
@@ -14,6 +14,7 @@
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.data.mapwithai.MapWithAIType;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAIConfig;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
import org.openstreetmap.josm.testutils.JOSMTestRules;
@@ -26,6 +27,10 @@
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.matching.AbsentPattern;
+import com.github.tomakehurst.wiremock.matching.AnythingPattern;
+import com.github.tomakehurst.wiremock.matching.EqualToPattern;
+import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
@@ -39,6 +44,7 @@
@Wiremock
@MapWithAIConfig
class BoundingBoxMapWithAIDownloaderTest {
+ private static final String TEST_DATA = "";
@RegisterExtension
JOSMTestRules josmTestRules = new JOSMTestRules().fakeAPI();
@@ -56,8 +62,9 @@ void testThirdPartyConflation() {
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(
- "")));
+ this.wireMockServer.stubFor(
+ WireMock.get("/testThirdPartyConflation").willReturn(WireMock.aResponse().withBody(TEST_DATA)));
+
final StubMapping conflationStub = this.wireMockServer
.stubFor(WireMock.post("/conflate").willReturn(WireMock.aResponse()
.withBody("")));
@@ -74,4 +81,35 @@ void testThirdPartyConflation() {
request.getParts().stream().map(Request.Part::getName).collect(Collectors.joining(",")));
assertNotNull(request.getPart("external"));
}
+
+ /**
+ * Non-regression test for #22624: Improperly added resultOffset to URLs sent to
+ * MapWithAI servers
+ */
+ @Test
+ void testNonRegression22624() {
+ MapWithAIInfo.THIRD_PARTY_CONFLATE.put(true);
+ MapWithAIInfo info = new MapWithAIInfo("testNonRegression22624",
+ this.wireMockServer.baseUrl() + "/no-conflation?bbox={bbox}",
+ MapWithAIType.ESRI_FEATURE_SERVER.getTypeString(), null, "testNonRegression22624");
+ info.setConflationUrl(this.wireMockServer.baseUrl() + "/conflation?bbox={bbox}");
+ info.setConflation(true);
+ final Bounds downloadBounds = new Bounds(-10, -10, 10, 10);
+ final BoundingBoxMapWithAIDownloader boundingBoxMapWithAIDownloader = new BoundingBoxMapWithAIDownloader(
+ downloadBounds, info, false);
+
+ StubMapping noConflation = this.wireMockServer
+ .stubFor(WireMock.get("/no-conflation").willReturn(WireMock.badRequest()));
+ StubMapping resultOffset = this.wireMockServer.stubFor(
+ WireMock.get(WireMock.urlPathEqualTo("/conflation")).withQueryParam("bbox", new AnythingPattern())
+ .withQueryParam("resultOffset", new EqualToPattern("0")).willReturn(WireMock.badRequest()));
+ StubMapping noResultOffset = this.wireMockServer.stubFor(WireMock.get(WireMock.urlPathEqualTo("/conflation"))
+ .withQueryParam("bbox", new AnythingPattern()).withQueryParam("resultOffset", AbsentPattern.ABSENT)
+ .willReturn(WireMock.aResponse().withBody(TEST_DATA)));
+
+ assertDoesNotThrow(() -> boundingBoxMapWithAIDownloader.parseOsm(NullProgressMonitor.INSTANCE));
+ this.wireMockServer.verify(0, RequestPatternBuilder.forCustomMatcher(noConflation.getRequest()));
+ this.wireMockServer.verify(0, RequestPatternBuilder.forCustomMatcher(resultOffset.getRequest()));
+ this.wireMockServer.verify(1, RequestPatternBuilder.forCustomMatcher(noResultOffset.getRequest()));
+ }
}