Changeset 19155 in josm
- Timestamp:
- 2024-07-29T17:57:38+02:00 (4 months ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java
r18870 r19155 10 10 import java.util.List; 11 11 12 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 12 13 import org.junit.jupiter.api.Test; 13 14 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; … … 21 22 import org.openstreetmap.josm.testutils.annotations.Projection; 22 23 23 import com.github.tomakehurst.wiremock.WireMockServer;24 25 24 /** 26 25 * Unit tests for class {@link AddImageryLayerAction}. … … 31 30 @Projection 32 31 final class AddImageryLayerActionTest { 33 /**34 * HTTP mock.35 */36 @BasicWiremock37 WireMockServer wireMockServer;38 39 32 /** 40 33 * Unit test of {@link AddImageryLayerAction#updateEnabledState}. … … 65 58 */ 66 59 @Test 67 void testActionPerformedEnabledWms( ) {68 wireMock Server.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))60 void testActionPerformedEnabledWms(WireMockRuntimeInfo wireMockRuntimeInfo) { 61 wireMockRuntimeInfo.getWireMock().register(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1")) 69 62 .willReturn(aResponse() 70 63 .withStatus(200) 71 64 .withHeader("Content-Type", "text/xml") 72 65 .withBodyFile("imagery/wms-capabilities.xml"))); 73 wireMock Server.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities"))66 wireMockRuntimeInfo.getWireMock().register(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities")) 74 67 .willReturn(aResponse() 75 68 .withStatus(404))); 76 wireMock Server.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))69 wireMockRuntimeInfo.getWireMock().register(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0")) 77 70 .willReturn(aResponse() 78 71 .withStatus(404))); … … 80 73 try { 81 74 FeatureAdapter.registerApiKeyAdapter(id -> "random_key"); 82 final ImageryInfo imageryInfo = new ImageryInfo("localhost", wireMock Server.url("/wms?apikey={apikey}"),75 final ImageryInfo imageryInfo = new ImageryInfo("localhost", wireMockRuntimeInfo.getHttpBaseUrl() + "/wms?apikey={apikey}", 83 76 "wms_endpoint", null, null); 84 77 imageryInfo.setId("testActionPerformedEnabledWms"); -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTaskTestParent.java
r18893 r19155 6 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 7 8 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 9 import org.junit.jupiter.api.BeforeEach; 8 10 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 9 11 import org.openstreetmap.josm.testutils.annotations.HTTPS; 10 11 import com.github.tomakehurst.wiremock.WireMockServer;12 12 13 13 /** … … 17 17 @HTTPS 18 18 public abstract class AbstractDownloadTaskTestParent { 19 /**20 * HTTP mock.21 */22 @BasicWiremock23 WireMockServer wireMockServer;19 WireMockRuntimeInfo wireMockServer; 20 @BeforeEach 21 void setup(WireMockRuntimeInfo wireMockRuntimeInfo) { 22 this.wireMockServer = wireMockRuntimeInfo; 23 } 24 24 25 25 /** … … 43 43 */ 44 44 protected final String getRemoteFileUrl() { 45 return wireMockServer.url(getRemoteFile()); 45 final String remote = getRemoteFile(); 46 if (remote.startsWith("/")) { 47 return wireMockServer.getHttpBaseUrl() + getRemoteFile(); 48 } 49 return wireMockServer.getHttpBaseUrl() + '/' + getRemoteFile(); 46 50 } 47 51 … … 50 54 */ 51 55 protected final void mockHttp() { 52 wireMockServer. stubFor(get(urlEqualTo("/" + getRemoteFile()))56 wireMockServer.getWireMock().register(get(urlEqualTo("/" + getRemoteFile())) 53 57 .willReturn(aResponse() 54 58 .withStatus(200) -
trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java
r19050 r19155 21 21 import java.util.concurrent.TimeUnit; 22 22 23 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 23 24 import org.apache.commons.jcs3.access.behavior.ICacheAccess; 24 25 import org.apache.commons.jcs3.engine.behavior.ICacheElement; … … 33 34 import org.openstreetmap.josm.tools.Logging; 34 35 35 import com.github.tomakehurst.wiremock.WireMockServer;36 36 import com.github.tomakehurst.wiremock.matching.UrlPattern; 37 37 … … 47 47 * mocked tile server 48 48 */ 49 @BasicWiremock 50 WireMockServer tileServer; 49 WireMockRuntimeInfo tileServer; 51 50 52 51 private static class TestCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, CacheEntry> { … … 105 104 /** 106 105 * Always clear cache before tests 107 * @throws Exception when clearing fails108 106 */ 109 107 @BeforeEach 110 void clearCache() throws Exception{108 void clearCache() { 111 109 getCache().clear(); 112 110 } 113 111 112 @BeforeEach 113 void setup(WireMockRuntimeInfo wireMockRuntimeInfo) { 114 this.tileServer = wireMockRuntimeInfo; 115 } 116 114 117 /** 115 118 * Test status codes 116 * @throws InterruptedException in case of thread interruption117 119 * @throws IOException in case of I/O error 118 120 */ 119 121 @Test 120 void testStatusCodes() throws IOException , InterruptedException{122 void testStatusCodes() throws IOException { 121 123 doTestStatusCode(200); 122 124 doTestStatusCode(401); … … 155 157 156 158 private void doTestStatusCode(int responseCode) throws IOException { 157 tileServer. stubFor(get(urlEqualTo("/httpstat/" + responseCode)).willReturn(aResponse().withStatus(responseCode)));159 tileServer.getWireMock().register(get(urlEqualTo("/httpstat/" + responseCode)).willReturn(aResponse().withStatus(responseCode))); 158 160 TestCachedTileLoaderJob job = getStatusLoaderJob(responseCode); 159 161 Listener listener = submitJob(job); … … 196 198 createHeadGetStub(urlEqualTo("/test"), expires, testStart, "eTag", "mock entry"); 197 199 198 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test");199 Listener listener = submitJob(job, false); 200 tileServer. verify(0, getRequestedFor(anyUrl()));200 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test"); 201 Listener listener = submitJob(job, false); 202 tileServer.getWireMock().verifyThat(0, getRequestedFor(anyUrl())); 201 203 assertArrayEquals("cached entry".getBytes(StandardCharsets.UTF_8), listener.data); 202 204 } … … 217 219 createHeadGetStub(urlEqualTo("/test"), expires, testStart, "eTag", "mock entry"); 218 220 219 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test");221 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test"); 220 222 Listener listener = submitJob(job, true); 221 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));223 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 222 224 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 223 225 } … … 231 233 void testSettingMinimumExpiryWhenNoExpires() throws IOException { 232 234 long testStart = System.currentTimeMillis(); 233 tileServer. stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withBody("mock entry")));234 235 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test");236 Listener listener = submitJob(job, false); 237 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));235 tileServer.getWireMock().register(get(urlEqualTo("/test")).willReturn(aResponse().withBody("mock entry"))); 236 237 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test"); 238 Listener listener = submitJob(job, false); 239 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 238 240 239 241 assertTrue(listener.attributes.getExpirationTime() >= testStart + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME, … … 260 262 long testStart = System.currentTimeMillis(); 261 263 long expires = TimeUnit.DAYS.toSeconds(1); 262 tileServer. stubFor(get(urlEqualTo("/test"))264 tileServer.getWireMock().register(get(urlEqualTo("/test")) 263 265 .willReturn(aResponse() 264 266 .withHeader("Cache-control", "max-age=" + expires) … … 267 269 ); 268 270 269 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test");270 Listener listener = submitJob(job, false); 271 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));271 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test"); 272 Listener listener = submitJob(job, false); 273 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 272 274 273 275 assertTrue(listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(expires), … … 298 300 createHeadGetStub(urlEqualTo("/test"), (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10), testStart, "eTag", "mock entry"); 299 301 300 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test", minimumExpiryTimeSeconds);301 Listener listener = submitJob(job, false); 302 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));302 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test", minimumExpiryTimeSeconds); 303 Listener listener = submitJob(job, false); 304 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 303 305 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 304 306 … … 331 333 createHeadGetStub(urlEqualTo("/test"), (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10), testStart, "eTag", "mock entry"); 332 334 333 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test", minimumExpiryTimeSeconds);334 Listener listener = submitJob(job, false); 335 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));335 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test", minimumExpiryTimeSeconds); 336 Listener listener = submitJob(job, false); 337 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 336 338 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 337 339 … … 367 369 int minimumExpiryTimeSeconds = 0; 368 370 369 tileServer. stubFor(get(urlEqualTo("/test"))371 tileServer.getWireMock().register(get(urlEqualTo("/test")) 370 372 .willReturn(aResponse() 371 373 .withHeader("Expires", TestUtils.getHTTPDate(testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10))) … … 375 377 ) 376 378 ); 377 tileServer. stubFor(head(urlEqualTo("/test"))379 tileServer.getWireMock().register(head(urlEqualTo("/test")) 378 380 .willReturn(aResponse() 379 381 .withHeader("Expires", TestUtils.getHTTPDate(testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10))) … … 382 384 ) 383 385 ); 384 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test", minimumExpiryTimeSeconds);385 Listener listener = submitJob(job, false); 386 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));386 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test", minimumExpiryTimeSeconds); 387 Listener listener = submitJob(job, false); 388 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 387 389 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 388 390 … … 413 415 int minimumExpiryTimeSeconds = 0; 414 416 415 tileServer. stubFor(get(urlEqualTo("/test"))417 tileServer.getWireMock().register(get(urlEqualTo("/test")) 416 418 .willReturn(aResponse() 417 419 .withHeader("Cache-Control", "" + … … 422 424 ) 423 425 ); 424 tileServer. stubFor(head(urlEqualTo("/test"))426 tileServer.getWireMock().register(head(urlEqualTo("/test")) 425 427 .willReturn(aResponse() 426 428 .withHeader("Cache-Control", "" + … … 429 431 ) 430 432 )); 431 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test", minimumExpiryTimeSeconds);432 Listener listener = submitJob(job, false); 433 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));433 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test", minimumExpiryTimeSeconds); 434 Listener listener = submitJob(job, false); 435 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 434 436 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 435 437 … … 461 463 ); 462 464 463 tileServer. stubFor(get(urlEqualTo("/test"))465 tileServer.getWireMock().register(get(urlEqualTo("/test")) 464 466 .willReturn(aResponse() 465 467 .withHeader("Expires", TestUtils.getHTTPDate(testStart + expires)) … … 469 471 ) 470 472 ); 471 tileServer. stubFor(head(urlEqualTo("/test"))473 tileServer.getWireMock().register(head(urlEqualTo("/test")) 472 474 .willReturn(aResponse() 473 475 .withHeader("Expires", TestUtils.getHTTPDate(testStart + expires)) … … 477 479 ); 478 480 479 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test");481 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test"); 480 482 Listener listener = submitJob(job, false); // cache entry is expired, no need to force refetch 481 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));483 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 482 484 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 483 485 484 486 // cache entry should be retrieved from cache 485 487 listener = submitJob(job, false); 486 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));488 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 487 489 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 488 490 … … 494 496 495 497 // because cache entry is invalid - HEAD request shall be made 496 tileServer. verify(0, headRequestedFor(urlEqualTo("/test"))); // no head requests were made until now498 tileServer.getWireMock().verifyThat(0, headRequestedFor(urlEqualTo("/test"))); // no head requests were made until now 497 499 listener = submitJob(job, false); 498 tileServer. verify(1, headRequestedFor(urlEqualTo("/test"))); // verify head requests were made499 tileServer. verify(1, getRequestedFor(urlEqualTo("/test"))); // verify no more get requests were made500 tileServer.getWireMock().verifyThat(1, headRequestedFor(urlEqualTo("/test"))); // verify head requests were made 501 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); // verify no more get requests were made 500 502 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 501 503 assertTrue(listener.attributes.getExpirationTime() >= testStart + expires); … … 503 505 // cache entry should be retrieved from cache 504 506 listener = submitJob(job, false); // cache entry is expired, no need to force refetch 505 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));506 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));507 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 508 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 507 509 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 508 510 } … … 522 524 ); 523 525 524 tileServer. stubFor(get(urlEqualTo("/test"))526 tileServer.getWireMock().register(get(urlEqualTo("/test")) 525 527 .willReturn(status(304) 526 528 .withHeader("Expires", TestUtils.getHTTPDate(testStart + expires)) … … 530 532 ); 531 533 532 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer. url("/test"), "test");533 Listener listener = submitJob(job, false); 534 tileServer. verify(1, getRequestedFor(urlEqualTo("/test")));534 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/test", "test"); 535 Listener listener = submitJob(job, false); 536 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); 535 537 assertArrayEquals("cached dummy".getBytes(StandardCharsets.UTF_8), listener.data); 536 538 assertTrue(testStart + expires <= listener.attributes.getExpirationTime()); 537 539 submitJob(job, false); 538 tileServer. verify(1, getRequestedFor(urlEqualTo("/test"))); // no more requests were made540 tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/test"))); // no more requests were made 539 541 } 540 542 541 543 private void createHeadGetStub(UrlPattern url, long expires, long lastModified, String eTag, String body) { 542 tileServer. stubFor(get(url)544 tileServer.getWireMock().register(get(url) 543 545 .willReturn(aResponse() 544 546 .withHeader("Expires", TestUtils.getHTTPDate(lastModified + expires)) … … 548 550 ) 549 551 ); 550 tileServer. stubFor(head(url)552 tileServer.getWireMock().register(head(url) 551 553 .willReturn(aResponse() 552 554 .withHeader("Expires", TestUtils.getHTTPDate(lastModified + expires)) … … 567 569 568 570 private TestCachedTileLoaderJob getStatusLoaderJob(int responseCode) { 569 return new TestCachedTileLoaderJob(tileServer. url("/httpstat/" + responseCode), "key_" + responseCode);571 return new TestCachedTileLoaderJob(tileServer.getHttpBaseUrl() + "/httpstat/" + responseCode, "key_" + responseCode); 570 572 } 571 573 -
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 -
trunk/test/unit/org/openstreetmap/josm/data/osm/DefaultNameFormatterTest.java
r18977 r19155 15 15 import java.util.stream.IntStream; 16 16 17 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 17 18 import org.junit.jupiter.api.Test; 18 19 import org.openstreetmap.josm.TestUtils; … … 25 26 import org.openstreetmap.josm.testutils.annotations.HTTP; 26 27 import org.xml.sax.SAXException; 27 28 import com.github.tomakehurst.wiremock.WireMockServer;29 28 30 29 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 39 38 class DefaultNameFormatterTest { 40 39 /** 41 * HTTP mock.42 */43 @BasicWiremock44 WireMockServer wireMockServer;45 46 /**47 40 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/9632">#9632</a>. 41 * @param wireMockRuntimeInfo Wiremock information 48 42 * @throws IllegalDataException if an error was found while parsing the data from the source 49 43 * @throws IOException if any I/O error occurs … … 52 46 @Test 53 47 @SuppressFBWarnings(value = "ITA_INEFFICIENT_TO_ARRAY") 54 void testTicket9632( ) throws IllegalDataException, IOException, SAXException {48 void testTicket9632(WireMockRuntimeInfo wireMockRuntimeInfo) throws IllegalDataException, IOException, SAXException { 55 49 String source = "presets/Presets_BicycleJunction-preset.xml"; 56 wireMock Server.stubFor(get(urlEqualTo("/" + source))50 wireMockRuntimeInfo.getWireMock().register(get(urlEqualTo("/" + source)) 57 51 .willReturn(aResponse() 58 52 .withStatus(200) 59 53 .withHeader("Content-Type", "text/xml") 60 54 .withBodyFile(source))); 61 TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll(wireMock Server.url(source), true));55 TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll(wireMockRuntimeInfo.getHttpBaseUrl() + '/' + source, true)); 62 56 63 57 Comparator<IRelation<?>> comparator = DefaultNameFormatter.getInstance().getRelationComparator(); -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTaskTest.java
r18106 r19155 14 14 import java.awt.Component; 15 15 16 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 17 import org.junit.jupiter.api.BeforeEach; 16 18 import org.junit.jupiter.api.Test; 17 19 import org.junit.jupiter.api.Timeout; … … 20 22 import org.openstreetmap.josm.testutils.annotations.HTTP; 21 23 import org.openstreetmap.josm.tools.Logging; 22 23 import com.github.tomakehurst.wiremock.WireMockServer;24 24 25 25 /** … … 31 31 @HTTP 32 32 class ApiUrlTestTaskTest { 33 /** 34 * HTTP mock. 35 */ 36 @BasicWiremock 37 WireMockServer wireMockServer; 33 private WireMockRuntimeInfo wireMockServer; 34 38 35 39 36 private static final Component PARENT = new JLabel(); 37 38 @BeforeEach 39 void setup(WireMockRuntimeInfo wireMockServer) { 40 this.wireMockServer = wireMockServer; 41 } 40 42 41 43 /** … … 52 54 @Test 53 55 void testNominalUrl() { 54 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer. url("/__files/api"));56 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.getHttpBaseUrl() + "/__files/api"); 55 57 task.run(); 56 58 assertTrue(task.isSuccess()); … … 89 91 void testAlertInvalidServerResult() { 90 92 Logging.clearLastErrorAndWarnings(); 91 wireMockServer. stubFor(get(urlEqualTo("/does-not-exist/0.6/capabilities"))93 wireMockServer.getWireMock().register(get(urlEqualTo("/does-not-exist/0.6/capabilities")) 92 94 .willReturn(aResponse().withStatus(404))); 93 95 94 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer. url("/does-not-exist"));96 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.getHttpBaseUrl() + "/does-not-exist"); 95 97 task.run(); 96 98 assertFalse(task.isSuccess()); … … 105 107 void testAlertInvalidCapabilities() { 106 108 Logging.clearLastErrorAndWarnings(); 107 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.url("/__files/invalid_api")); 109 final String url = wireMockServer.getHttpBaseUrl() + "/__files/invalid_api"; 110 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, url); 108 111 task.run(); 109 112 assertFalse(task.isSuccess()); 110 113 assertThat(Logging.getLastErrorAndWarnings().toString(), containsString( 111 114 "The OSM API server at 'XXX' did not return a valid response.<br>It is likely that 'XXX' is not an OSM API server." 112 .replace("XXX", wireMockServer.url("/__files/invalid_api"))));115 .replace("XXX", url))); 113 116 } 114 117 } -
trunk/test/unit/org/openstreetmap/josm/io/OsmServerHistoryReaderTest.java
r18106 r19155 6 6 import java.time.Instant; 7 7 8 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 8 9 import org.junit.jupiter.api.BeforeEach; 9 10 import org.junit.jupiter.api.Test; … … 17 18 import org.openstreetmap.josm.testutils.annotations.HTTP; 18 19 19 import com.github.tomakehurst.wiremock.WireMockServer;20 21 20 /** 22 21 * Unit tests of {@link OsmServerHistoryReader} class. … … 27 26 class OsmServerHistoryReaderTest { 28 27 /** 29 * HTTP mock.30 */31 @BasicWiremock32 WireMockServer wireMockServer;33 34 /**35 28 * Setup tests. 36 29 */ 37 30 @BeforeEach 38 void setUp( ) {39 Config.getPref().put("osm-server.url", wireMock Server.url("/__files/api"));31 void setUp(WireMockRuntimeInfo wireMockRuntimeInfo) { 32 Config.getPref().put("osm-server.url", wireMockRuntimeInfo.getHttpBaseUrl() + "/__files/api"); 40 33 } 41 34 -
trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java
r18106 r19155 14 14 import java.util.regex.Matcher; 15 15 16 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 16 17 import org.junit.jupiter.api.BeforeEach; 17 18 import org.junit.jupiter.api.Test; … … 25 26 import org.openstreetmap.josm.tools.date.DateUtils; 26 27 27 import com.github.tomakehurst.wiremock.WireMockServer;28 29 28 /** 30 29 * Unit tests of {@link OverpassDownloadReader} class. … … 34 33 @HTTP 35 34 class OverpassDownloadReaderTest { 36 /** 37 * HTTP mock. 38 */ 39 @BasicWiremock 40 WireMockServer wireMockServer; 35 private WireMockRuntimeInfo wireMockServer; 41 36 42 37 private static final String NOMINATIM_URL_PATH = "/search?format=xml&q="; … … 46 41 */ 47 42 @BeforeEach 48 public void setUp() { 49 NameFinder.NOMINATIM_URL_PROP.put(wireMockServer.url(NOMINATIM_URL_PATH)); 43 public void setUp(WireMockRuntimeInfo wireMockRuntimeInfo) { 44 this.wireMockServer = wireMockRuntimeInfo; 45 NameFinder.NOMINATIM_URL_PROP.put(wireMockServer.getHttpBaseUrl() + NOMINATIM_URL_PATH); 50 46 } 51 47 … … 74 70 75 71 private void stubNominatim(String query) { 76 wireMockServer. stubFor(get(urlEqualTo(NOMINATIM_URL_PATH + query))72 wireMockServer.getWireMock().register(get(urlEqualTo(NOMINATIM_URL_PATH + query)) 77 73 .willReturn(aResponse() 78 74 .withStatus(200) -
trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java
r18870 r19155 11 11 import java.util.List; 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.josm.TestUtils; … … 18 20 import org.openstreetmap.josm.testutils.annotations.Projection; 19 21 20 import com.github.tomakehurst.wiremock.WireMockServer;21 22 import com.github.tomakehurst.wiremock.client.WireMock; 22 23 … … 28 29 @Projection 29 30 class WMSImageryTest { 30 @BasicWiremock 31 WireMockServer tileServer; 31 32 private WireMockRuntimeInfo tileServer; 33 34 @BeforeEach 35 void setup(WireMockRuntimeInfo wireMockRuntimeRule) { 36 this.tileServer = wireMockRuntimeRule; 37 } 32 38 33 39 /** … … 52 58 @Test 53 59 void testTicket15730() throws IOException, WMSGetCapabilitiesException { 54 tileServer. stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(60 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody( 55 61 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataDir(15730), "capabilities.xml")) 56 62 ))); 57 63 58 WMSImagery wms = new WMSImagery(tileServer. url("capabilities.xml"));64 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/capabilities.xml"); 59 65 assertEquals(1, wms.getLayers().size()); 60 66 assertTrue(wms.getLayers().get(0).getAbstract().startsWith("South Carolina NAIP Imagery 2017 Resolution: 100CM ")); … … 63 69 @Test 64 70 void testNestedLayers() throws Exception { 65 tileServer. stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(71 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody( 66 72 Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/mapa-um-warszawa-pl.xml"))))); 67 WMSImagery wmsi = new WMSImagery(tileServer. url("/serwis"));73 WMSImagery wmsi = new WMSImagery(tileServer.getHttpBaseUrl() + "/serwis"); 68 74 assertEquals(1, wmsi.getLayers().size()); 69 75 assertEquals("Server WMS m.st. Warszawy", wmsi.getLayers().get(0).toString()); … … 79 85 void testTicket16248() throws IOException, WMSGetCapabilitiesException { 80 86 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml"))); 81 tileServer. stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));82 WMSImagery wms = new WMSImagery(tileServer. url("any"));87 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities))); 88 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any"); 83 89 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k?", wms.buildRootUrl()); 84 90 assertEquals("wms.hgis.cartomatic.pl", wms.getLayers().get(0).getName()); … … 96 102 void testTicket19193() throws IOException, WMSGetCapabilitiesException { 97 103 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(19193, "capabilities.xml"))); 98 tileServer. stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));99 WMSImagery wms = new WMSImagery(tileServer. url("any"));104 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities))); 105 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any"); 100 106 assertEquals("https://inspire.brandenburg.de/services/gn_alkis_wms?", wms.buildRootUrl()); 101 107 assertEquals(1, wms.getLayers().size()); … … 114 120 @Test 115 121 void testTicket16333() throws IOException, WMSGetCapabilitiesException { 116 tileServer. stubFor(122 tileServer.getWireMock().register( 117 123 WireMock.get(WireMock.anyUrl()) 118 124 .willReturn(WireMock.aResponse().withBody( … … 120 126 )) 121 127 ); 122 WMSImagery wms = new WMSImagery(tileServer. url("any"));128 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any"); 123 129 assertEquals("https://duinoord.xs4all.nl/geoserver/ows?SERVICE=WMS&", wms.buildRootUrl()); 124 130 assertNull(wms.getLayers().get(0).getName()); … … 131 137 @Test 132 138 void testForTitleWithinAttribution_ticket16940() throws IOException, WMSGetCapabilitiesException { 133 tileServer. stubFor(139 tileServer.getWireMock().register( 134 140 WireMock.get(WireMock.anyUrl()) 135 141 .willReturn(WireMock.aResponse().withBody( … … 137 143 )) 138 144 ); 139 WMSImagery wms = new WMSImagery(tileServer. url("any"));145 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any"); 140 146 assertEquals("Hipsográfico", wms.getLayers().stream().findFirst().get().getTitle()); 141 147 } -
trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportSenderTest.java
r18106 r19155 16 16 import java.util.List; 17 17 18 import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; 18 19 import org.junit.jupiter.api.Test; 19 20 import org.openstreetmap.josm.actions.ShowStatusReportAction; … … 23 24 import org.openstreetmap.josm.testutils.annotations.HTTP; 24 25 import org.openstreetmap.josm.testutils.mockers.OpenBrowserMocker; 25 26 import com.github.tomakehurst.wiremock.WireMockServer;27 26 28 27 /** … … 34 33 class BugReportSenderTest { 35 34 /** 36 * HTTP mock37 */38 @BasicWiremock39 WireMockServer wireMockServer;40 41 /**42 35 * Unit test for {@link BugReportSender#BugReportSender}. 43 36 * @throws InterruptedException if the thread is interrupted 44 37 */ 45 38 @Test 46 void testBugReportSender( ) throws InterruptedException {47 Config.getPref().put("josm.url", wireMock Server.baseUrl());48 wireMock Server.stubFor(post(urlEqualTo("/josmticket"))39 void testBugReportSender(WireMockRuntimeInfo wireMockRuntimeInfo) throws InterruptedException { 40 Config.getPref().put("josm.url", wireMockRuntimeInfo.getHttpBaseUrl()); 41 wireMockRuntimeInfo.getWireMock().register(post(urlEqualTo("/josmticket")) 49 42 .willReturn(aResponse() 50 43 .withStatus(200) … … 66 59 assertFalse(sender.isAlive()); 67 60 assertNull(sender.getErrorMessage(), sender.getErrorMessage()); 68 wireMockServer.verify(exactly(1), postRequestedFor(urlEqualTo("/josmticket")).withRequestBody(containing("pdata="))); 61 wireMockRuntimeInfo.getWireMock().verifyThat(exactly(1), 62 postRequestedFor(urlEqualTo("/josmticket")).withRequestBody(containing("pdata="))); 69 63 70 64 List<URI> calledURIs = OpenBrowserMocker.getCalledURIs(); 71 65 assertEquals(1, calledURIs.size()); 72 assertEquals(wireMock Server.url("/josmticket?pdata_stored=6bccff5c0417217bfbbe5fff"), calledURIs.get(0).toString());66 assertEquals(wireMockRuntimeInfo.getHttpBaseUrl() + "/josmticket?pdata_stored=6bccff5c0417217bfbbe5fff", calledURIs.get(0).toString()); 73 67 } 74 68 }
Note:
See TracChangeset
for help on using the changeset viewer.