Skip to content

Commit

Permalink
Fix tests for JOSM Jenkins
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Jul 12, 2024
1 parent 197357c commit a94e19c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/test/data
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -106,10 +115,5 @@ public ResponseDefinition transform(Request request, ResponseDefinition response
public String getName() {
return "MapRouletteExtension";
}

@Override
public boolean applyGlobally() {
return super.applyGlobally();
}
}
}

0 comments on commit a94e19c

Please sign in to comment.