Changeset 19155 in josm for trunk/test/unit/org/openstreetmap/josm/data/imagery
- Timestamp:
- 2024-07-29T17:57:38+02:00 (12 months ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/data/imagery
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java
r19050 r19155 16 16 import java.util.regex.Pattern; 17 17 18 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 18 19 import org.apache.commons.jcs3.access.behavior.ICacheAccess; 19 20 import org.junit.jupiter.api.BeforeEach; … … 31 32 import org.openstreetmap.josm.tools.Utils; 32 33 33 import com.github.tomakehurst.wiremock.WireMockServer;34 34 import com.github.tomakehurst.wiremock.client.WireMock; 35 35 … … 43 43 * mocked tile server 44 44 */ 45 @BasicWiremock 46 WireMockServer tileServer; 45 private WireMockRuntimeInfo wireMockRuntimeInfo; 47 46 48 47 @BeforeEach 49 void clearCache() throws Exception{48 void clearCache() { 50 49 getCache().clear(); 50 } 51 52 @BeforeEach 53 void setup(WireMockRuntimeInfo wireMockRuntimeInfo) { 54 this.wireMockRuntimeInfo = wireMockRuntimeInfo; 51 55 } 52 56 … … 126 130 127 131 @Override 128 public String getTileUrl(int zoom, int tilex, int tiley) throws IOException{132 public String getTileUrl(int zoom, int tilex, int tiley) { 129 133 return url; 130 134 } … … 219 223 void testNoCacheHeaders() throws IOException { 220 224 long testStart = System.currentTimeMillis(); 221 tileServer.stubFor(225 wireMockRuntimeInfo.getWireMock().register( 222 226 WireMock.get(WireMock.urlEqualTo("/test")) 223 227 .willReturn(WireMock.aResponse() … … 226 230 ); 227 231 228 TestCachedTileLoaderJob job = submitJob(new MockTile( tileServer.url("/test")), "test", false);232 TestCachedTileLoaderJob job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", false); 229 233 assertExpirationAtLeast(testStart + TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get(), job); 230 234 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 231 job = submitJob(new MockTile( tileServer.url("/test")), "test", false); // submit another job for the same tile235 job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", false); // submit another job for the same tile 232 236 // only one request to tile server should be made, second should come from cache 233 tileServer.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test")));237 wireMockRuntimeInfo.getWireMock().verifyThat(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test"))); 234 238 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 235 239 } … … 257 261 private void noCacheHeadersMinimumExpires(int minimumExpires) throws IOException { 258 262 long testStart = System.currentTimeMillis(); 259 tileServer.stubFor(263 wireMockRuntimeInfo.getWireMock().register( 260 264 WireMock.get(WireMock.urlEqualTo("/test")) 261 265 .willReturn(WireMock.aResponse() … … 263 267 ) 264 268 ); 265 TestCachedTileLoaderJob job = submitJob(new MockTile( tileServer.url("/test")), "test", minimumExpires, false);269 TestCachedTileLoaderJob job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", minimumExpires, false); 266 270 assertExpirationAtLeast(testStart + minimumExpires, job); 267 271 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 268 job = submitJob(new MockTile( tileServer.url("/test")), "test", false); // submit another job for the same tile272 job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", false); // submit another job for the same tile 269 273 // only one request to tile server should be made, second should come from cache 270 tileServer.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test")));274 wireMockRuntimeInfo.getWireMock().verifyThat(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test"))); 271 275 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 272 276 } … … 280 284 long testStart = System.currentTimeMillis(); 281 285 long expires = TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get() / 2; 282 tileServer.stubFor(286 wireMockRuntimeInfo.getWireMock().register( 283 287 WireMock.get(WireMock.urlEqualTo("/test")) 284 288 .willReturn(WireMock.aResponse() … … 287 291 ) 288 292 ); 289 TestCachedTileLoaderJob job = submitJob(new MockTile( tileServer.url("/test")), "test", false);293 TestCachedTileLoaderJob job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", false); 290 294 assertExpirationAtLeast(testStart + TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get(), job); 291 295 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 292 job = submitJob(new MockTile( tileServer.url("/test")), "test", false); // submit another job for the same tile296 job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", false); // submit another job for the same tile 293 297 // only one request to tile server should be made, second should come from cache 294 tileServer.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test")));298 wireMockRuntimeInfo.getWireMock().verifyThat(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test"))); 295 299 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 296 300 } … … 312 316 long testStart = System.currentTimeMillis(); 313 317 long expires = TMSCachedTileLoaderJob.MAXIMUM_EXPIRES.get() * 2; 314 tileServer.stubFor(318 wireMockRuntimeInfo.getWireMock().register( 315 319 WireMock.get(WireMock.urlEqualTo("/test")) 316 320 .willReturn(WireMock.aResponse() … … 319 323 ) 320 324 ); 321 TestCachedTileLoaderJob job = submitJob(new MockTile( tileServer.url("/test")), "test", false);325 TestCachedTileLoaderJob job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", false); 322 326 // give 1 second margin 323 327 assertExpirationAtMost(testStart + TMSCachedTileLoaderJob.MAXIMUM_EXPIRES.get() + TimeUnit.SECONDS.toMillis(1), job); 324 328 325 329 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 326 job = submitJob(new MockTile( tileServer.url("/test")), "test", false); // submit another job for the same tile330 job = submitJob(new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/test"), "test", false); // submit another job for the same tile 327 331 // only one request to tile server should be made, second should come from cache 328 tileServer.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test")));332 wireMockRuntimeInfo.getWireMock().verifyThat(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test"))); 329 333 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 330 334 } -
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"))); -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
r19077 r19155 23 23 import java.util.concurrent.TimeUnit; 24 24 25 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 25 26 import org.junit.jupiter.api.Disabled; 26 27 import org.junit.jupiter.api.Test; … … 45 46 import org.openstreetmap.josm.tools.ReflectionUtils; 46 47 47 import com.github.tomakehurst.wiremock.WireMockServer;48 48 import com.github.tomakehurst.wiremock.client.WireMock; 49 49 … … 56 56 @Timeout(value = 5, unit = TimeUnit.MINUTES) 57 57 class WMTSTileSourceTest { 58 @BasicWiremock59 WireMockServer tileServer;60 61 58 private final ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null); 62 59 private final ImageryInfo testImageryPSEUDO_MERCATOR = getImagery(TestUtils.getTestDataRoot() + "wmts/getcapabilities-pseudo-mercator.xml"); … … 367 364 368 365 @Test 369 void testDefaultLayer() throws Exception { 366 void testDefaultLayer(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { 370 367 // https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/1.0.0/WMTSCapabilities.xml 371 368 // do not use withFileBody as it needs different directory layout :( 372 369 373 tileServer.stubFor(370 wireMockRuntimeInfo.getWireMock().register( 374 371 WireMock.get("/getcapabilities.xml") 375 372 .willReturn( … … 381 378 ); 382 379 383 tileServer.stubFor(380 wireMockRuntimeInfo.getWireMock().register( 384 381 WireMock.get("/other/maps") 385 382 .willReturn( … … 392 389 "<type>wmts</type>\n" + 393 390 "<category>photo</category>\n" + 394 "<url><![CDATA[" + tileServer.url("/getcapabilities.xml") + "]]></url>\n" +391 "<url><![CDATA[" + wireMockRuntimeInfo.getHttpBaseUrl() + "/getcapabilities.xml]]></url>\n" + 395 392 "<default-layers>" + 396 393 "<layer name=\"GEOGRAPHICALGRIDSYSTEMS.MAPS\" />" + … … 400 397 ))); 401 398 402 Config.getPref().putList("imagery.layers.sites", Collections.singletonList( tileServer.url("/other/maps")));399 Config.getPref().putList("imagery.layers.sites", Collections.singletonList(wireMockRuntimeInfo.getHttpBaseUrl() + "/other/maps")); 403 400 ImageryLayerInfo.instance.loadDefaults(true, null, false); 404 401
Note:
See TracChangeset
for help on using the changeset viewer.