Changeset 19155 in josm for trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java
- Timestamp:
- 2024-07-29T17:57:38+02:00 (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java
r19052 r19155 11 11 import java.util.Collections; 12 12 13 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 14 import org.junit.jupiter.api.BeforeEach; 13 15 import org.junit.jupiter.api.Test; 14 16 import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource; … … 22 24 import org.openstreetmap.josm.testutils.annotations.Projection; 23 25 24 import com.github.tomakehurst.wiremock.WireMockServer;25 26 import com.github.tomakehurst.wiremock.client.WireMock; 26 27 … … 29 30 @Projection 30 31 class WMSEndpointTileSourceTest implements TileSourceTest { 31 @BasicWiremock 32 WireMockServer tileServer; 32 WireMockRuntimeInfo tileServer; 33 @BeforeEach 34 void setup(WireMockRuntimeInfo wireMockRuntimeInfo) { 35 this.tileServer = wireMockRuntimeInfo; 36 } 33 37 34 38 private void basicMock() { 35 39 final byte[] response = assertDoesNotThrow(() -> Files.readAllBytes( 36 40 Paths.get(TestUtils.getTestDataRoot() + "wms/geofabrik-osm-inspector.xml"))); 37 tileServer. stubFor(41 tileServer.getWireMock().register( 38 42 WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities")) 39 43 .willReturn(WireMock.aResponse().withBody(response)) … … 45 49 this.basicMock(); 46 50 final ImageryInfo info = new ImageryInfo("WMSEndpointTileSourceTest"); 47 info.setExtendedUrl(tileServer. url("/capabilities"));51 info.setExtendedUrl(tileServer.getHttpBaseUrl() + "/capabilities"); 48 52 info.setDefaultLayers(Collections.singletonList(new DefaultLayer(ImageryType.WMS_ENDPOINT, 49 53 "single_node_in_way", "default", null))); … … 60 64 void testDefaultLayerSetInMaps() throws Exception { 61 65 62 tileServer. stubFor(66 tileServer.getWireMock().register( 63 67 WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities")) 64 68 .willReturn( … … 68 72 ); 69 73 70 tileServer. stubFor(WireMock.get(WireMock.urlEqualTo("/other/maps")).willReturn(WireMock.aResponse().withBody(74 tileServer.getWireMock().register(WireMock.get(WireMock.urlEqualTo("/other/maps")).willReturn(WireMock.aResponse().withBody( 71 75 "<?xml version='1.0' encoding='UTF-8'?>\n" + 72 76 "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" + … … 76 80 "<type>wms_endpoint</type>\n" + 77 81 "<category>qa</category>\n" + 78 "<url><![CDATA[" + tileServer. url("/capabilities") + "]]></url>\n" +82 "<url><![CDATA[" + tileServer.getHttpBaseUrl() + "/capabilities]]></url>\n" + 79 83 "<icon>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsSAAALEgHS3X78AAAB5UlEQVQ4y4WTwWsTURDG" + 80 84 "fy8W1yYmXZOqtGJJFyGw6KF7CEigwYuS0kthrYUi4i0iORS9BU9hQdA/ILcixVBrwENKLz1FUBB0wWOwYFAqxUNYTZq6BfM8yC5d05iBObz3vfnmm3kz4sqDh/zP" + … … 95 99 ))); 96 100 97 Config.getPref().putList("imagery.layers.sites", Collections.singletonList(tileServer. url("/other/maps")));101 Config.getPref().putList("imagery.layers.sites", Collections.singletonList(tileServer.getHttpBaseUrl() + "/other/maps")); 98 102 ImageryLayerInfo.instance.loadDefaults(true, null, false); 99 103 assertEquals(1, ImageryLayerInfo.instance.getDefaultLayers().size()); … … 110 114 @Test 111 115 void testCustomHeadersServerSide() throws IOException { 112 tileServer. stubFor(116 tileServer.getWireMock().register( 113 117 WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities")) 114 118 .willReturn( … … 118 122 ); 119 123 120 tileServer. stubFor(WireMock.get(WireMock.urlEqualTo("/other/maps")).willReturn(WireMock.aResponse().withBody(124 tileServer.getWireMock().register(WireMock.get(WireMock.urlEqualTo("/other/maps")).willReturn(WireMock.aResponse().withBody( 121 125 "<?xml version='1.0' encoding='UTF-8'?>\n" + 122 126 "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" + … … 129 133 " <country-code>NO</country-code>\n" + 130 134 " <description lang=\"en\">Historic Norwegian orthophotos and maps, courtesy of Geovekst and Norkart.</description>\n" + 131 " <url><![CDATA[" + tileServer. url("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities") + "]]></url>\n" +135 " <url><![CDATA[" + tileServer.getHttpBaseUrl() + "/capabilities?SERVICE=WMS&REQUEST=GetCapabilities]]></url>\n" + 132 136 " <custom-http-header header-name=\"X-WAAPI-TOKEN\" header-value=\"b8e36d51-119a-423b-b156-d744d54123d5\" />\n" + 133 137 " <attribution-text>© Geovekst</attribution-text>\n" + … … 141 145 ))); 142 146 143 Config.getPref().putList("imagery.layers.sites", Collections.singletonList(tileServer. url("/other/maps")));147 Config.getPref().putList("imagery.layers.sites", Collections.singletonList(tileServer.getHttpBaseUrl() + "/other/maps")); 144 148 ImageryLayerInfo.instance.loadDefaults(true, null, false); 145 149 ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0); … … 150 154 assertEquals("b8e36d51-119a-423b-b156-d744d54123d5", tileSource.getHeaders().get("X-WAAPI-TOKEN")); 151 155 assertTrue(wmsImageryInfo.isGeoreferenceValid()); 152 tileServer. verify(156 tileServer.getWireMock().verifyThat( 153 157 WireMock.getRequestedFor(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities")) 154 158 .withHeader("X-WAAPI-TOKEN", WireMock.equalTo("b8e36d51-119a-423b-b156-d744d54123d5")));
Note:
See TracChangeset
for help on using the changeset viewer.