From a94e19c2fc10fcdaeb5962956ef1d0e9772b3857 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Fri, 12 Jul 2024 06:39:27 -0600 Subject: [PATCH] Fix tests for JOSM Jenkins Signed-off-by: Taylor Smock --- src/test/data | 1 + .../maproulette/util/MapRouletteConfig.java | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) create mode 120000 src/test/data diff --git a/src/test/data b/src/test/data new file mode 120000 index 0000000..07cf801 --- /dev/null +++ b/src/test/data @@ -0,0 +1 @@ +resources/ \ No newline at end of file diff --git a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java index df1c68b..3feb51f 100644 --- a/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java +++ b/src/test/unit/org/openstreetmap/josm/plugins/maproulette/util/MapRouletteConfig.java @@ -12,17 +12,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.List; +import java.util.Objects; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; import com.github.tomakehurst.wiremock.common.FileSource; -import com.github.tomakehurst.wiremock.extension.Parameters; -import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer; +import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformerV2; import com.github.tomakehurst.wiremock.http.Body; import com.github.tomakehurst.wiremock.http.ContentTypeHeader; -import com.github.tomakehurst.wiremock.http.Request; import com.github.tomakehurst.wiremock.http.ResponseDefinition; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.stubbing.ServeEvent; +import com.github.tomakehurst.wiremock.verification.LoggedRequest; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.platform.commons.util.ReflectionUtils; import org.openstreetmap.josm.plugins.maproulette.gui.ModifiedObjects; @@ -43,7 +45,7 @@ class Extension extends WireMockExtension { */ private static String getDirectory() { final var basePath = Paths.get("src", "test", "resources"); - final var maproulette = Path.of("maproulette"); + final var maproulette = Path.of("MapRoulette"); if (Files.isDirectory(maproulette) && Files.isDirectory(maproulette.resolve(basePath))) { return maproulette.resolve(basePath).toString(); } @@ -52,7 +54,7 @@ private static String getDirectory() { public Extension() { super(extensionOptions().options(options().dynamicPort().usingFilesUnderDirectory(getDirectory()) - .extensions(new MapRouletteExtension()))); + .extensions(services -> List.of(new MapRouletteExtension(services.getFiles()))))); } @Override @@ -82,11 +84,18 @@ protected void onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo) { /** * A wiremock extension that allows us to return responses for maproulette APIs */ - class MapRouletteExtension extends ResponseDefinitionTransformer { + class MapRouletteExtension implements ResponseDefinitionTransformerV2 { + private final FileSource files; + + public MapRouletteExtension(FileSource files) { + Objects.requireNonNull(files, "files"); + this.files = files; + } @Override - public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource files, - Parameters parameters) { + public ResponseDefinition transform(ServeEvent serveEvent) { + final LoggedRequest request = serveEvent.getRequest(); + final ResponseDefinition responseDefinition = serveEvent.getResponseDefinition(); if (request.getUrl().startsWith("/api/v2/task/") && request.getUrl().matches("/api/v2/task/\\d+")) { final var file = files.getTextFileNamed(request.getUrl().substring(1) + "/start"); if (file != null) { @@ -106,10 +115,5 @@ public ResponseDefinition transform(Request request, ResponseDefinition response public String getName() { return "MapRouletteExtension"; } - - @Override - public boolean applyGlobally() { - return super.applyGlobally(); - } } }