Skip to content

Commit

Permalink
Fix tests broken by r19152
Browse files Browse the repository at this point in the history
git-svn-id: https://josm.openstreetmap.de/svn/trunk@19155 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Jul 29, 2024
1 parent eecb39d commit 3401be9
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.List;

import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import org.junit.jupiter.api.Test;
import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
import org.openstreetmap.josm.data.imagery.ImageryInfo;
Expand All @@ -20,8 +21,6 @@
import org.openstreetmap.josm.testutils.annotations.OsmApi;
import org.openstreetmap.josm.testutils.annotations.Projection;

import com.github.tomakehurst.wiremock.WireMockServer;

/**
* Unit tests for class {@link AddImageryLayerAction}.
*/
Expand All @@ -30,12 +29,6 @@
@OsmApi(OsmApi.APIType.FAKE)
@Projection
final class AddImageryLayerActionTest {
/**
* HTTP mock.
*/
@BasicWiremock
WireMockServer wireMockServer;

/**
* Unit test of {@link AddImageryLayerAction#updateEnabledState}.
*/
Expand Down Expand Up @@ -64,22 +57,22 @@ void testActionPerformedEnabledTms() {
* Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases for WMS.
*/
@Test
void testActionPerformedEnabledWms() {
wireMockServer.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))
void testActionPerformedEnabledWms(WireMockRuntimeInfo wireMockRuntimeInfo) {
wireMockRuntimeInfo.getWireMock().register(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBodyFile("imagery/wms-capabilities.xml")));
wireMockServer.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities"))
wireMockRuntimeInfo.getWireMock().register(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities"))
.willReturn(aResponse()
.withStatus(404)));
wireMockServer.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))
wireMockRuntimeInfo.getWireMock().register(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))
.willReturn(aResponse()
.withStatus(404)));

try {
FeatureAdapter.registerApiKeyAdapter(id -> "random_key");
final ImageryInfo imageryInfo = new ImageryInfo("localhost", wireMockServer.url("/wms?apikey={apikey}"),
final ImageryInfo imageryInfo = new ImageryInfo("localhost", wireMockRuntimeInfo.getHttpBaseUrl() + "/wms?apikey={apikey}",
"wms_endpoint", null, null);
imageryInfo.setId("testActionPerformedEnabledWms");
new AddImageryLayerAction(imageryInfo).actionPerformed(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;

import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import org.junit.jupiter.api.BeforeEach;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.HTTPS;

import com.github.tomakehurst.wiremock.WireMockServer;

/**
* Superclass of {@link DownloadGpsTaskTest}, {@link DownloadOsmTaskTest} and {@link DownloadNotesTaskTest}.
*/
@BasicWiremock
@HTTPS
public abstract class AbstractDownloadTaskTestParent {
/**
* HTTP mock.
*/
@BasicWiremock
WireMockServer wireMockServer;
WireMockRuntimeInfo wireMockServer;
@BeforeEach
void setup(WireMockRuntimeInfo wireMockRuntimeInfo) {
this.wireMockServer = wireMockRuntimeInfo;
}

/**
* Returns the path to remote test file to download via http.
Expand All @@ -42,14 +42,18 @@ protected String getRemoteContentType() {
* @return the http URL to remote test file to download
*/
protected final String getRemoteFileUrl() {
return wireMockServer.url(getRemoteFile());
final String remote = getRemoteFile();
if (remote.startsWith("/")) {
return wireMockServer.getHttpBaseUrl() + getRemoteFile();
}
return wireMockServer.getHttpBaseUrl() + '/' + getRemoteFile();
}

/**
* Mock the HTTP server.
*/
protected final void mockHttp() {
wireMockServer.stubFor(get(urlEqualTo("/" + getRemoteFile()))
wireMockServer.getWireMock().register(get(urlEqualTo("/" + getRemoteFile()))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", getRemoteContentType())
Expand Down
Loading

0 comments on commit 3401be9

Please sign in to comment.