Changeset 18106 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2021-08-01T21:21:38+02:00 (3 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 2 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java
r17195 r18106 5 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 8 import static org.junit.Assert.assertEquals; 9 import static org.junit.Assert.assertTrue; 7 import static org.junit.jupiter.api.Assertions.assertEquals; 8 import static org.junit.jupiter.api.Assertions.assertTrue; 10 9 11 10 import java.util.List; 12 11 13 import org.junit.Rule; 14 import org.junit.Test; 15 import org.openstreetmap.josm.TestUtils; 12 import org.junit.jupiter.api.Test; 13 import org.junit.jupiter.api.extension.RegisterExtension; 16 14 import org.openstreetmap.josm.data.imagery.ImageryInfo; 17 15 import org.openstreetmap.josm.gui.MainApplication; … … 19 17 import org.openstreetmap.josm.gui.layer.WMSLayer; 20 18 import org.openstreetmap.josm.testutils.JOSMTestRules; 19 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 20 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 21 21 22 import com.github.tomakehurst.wiremock. junit.WireMockRule;22 import com.github.tomakehurst.wiremock.WireMockServer; 23 23 24 24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 27 27 * Unit tests for class {@link AddImageryLayerAction}. 28 28 */ 29 public final class AddImageryLayerActionTest { 29 @BasicWiremock 30 @BasicPreferences 31 final class AddImageryLayerActionTest { 30 32 /** 31 33 * We need prefs for this. We need platform for actions and the OSM API for checking blacklist. 32 34 */ 33 @R ule35 @RegisterExtension 34 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 35 public JOSMTestRules test = new JOSMTestRules(). preferences().fakeAPI();37 public JOSMTestRules test = new JOSMTestRules().fakeAPI(); 36 38 37 39 /** 38 40 * HTTP mock. 39 41 */ 40 @ Rule41 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));42 @BasicWiremock 43 WireMockServer wireMockServer; 42 44 43 45 /** … … 45 47 */ 46 48 @Test 47 publicvoid testEnabledState() {49 void testEnabledState() { 48 50 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo")).isEnabled()); 49 51 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled()); … … 57 59 */ 58 60 @Test 59 publicvoid testActionPerformedEnabledTms() {61 void testActionPerformedEnabledTms() { 60 62 assertTrue(MainApplication.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty()); 61 63 new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null); … … 69 71 */ 70 72 @Test 71 publicvoid testActionPerformedEnabledWms() {72 wireMock Rule.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))73 void testActionPerformedEnabledWms() { 74 wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1")) 73 75 .willReturn(aResponse() 74 76 .withStatus(200) 75 77 .withHeader("Content-Type", "text/xml") 76 78 .withBodyFile("imagery/wms-capabilities.xml"))); 77 wireMock Rule.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities"))79 wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities")) 78 80 .willReturn(aResponse() 79 81 .withStatus(404))); 80 wireMock Rule.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))82 wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0")) 81 83 .willReturn(aResponse() 82 84 .withStatus(404))); 83 85 84 new AddImageryLayerAction(new ImageryInfo("localhost", wireMock Rule.url("/wms?"),86 new AddImageryLayerAction(new ImageryInfo("localhost", wireMockServer.url("/wms?"), 85 87 "wms_endpoint", null, null)).actionPerformed(null); 86 88 List<WMSLayer> wmsLayers = MainApplication.getLayerManager().getLayersOfType(WMSLayer.class); … … 94 96 */ 95 97 @Test 96 publicvoid testActionPerformedDisabled() {98 void testActionPerformedDisabled() { 97 99 assertTrue(MainApplication.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty()); 98 100 try { -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTaskTestParent.java
r17195 r18106 5 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;8 7 9 import org.junit.Rule; 10 import org.openstreetmap.josm.TestUtils; 8 import org.junit.jupiter.api.extension.RegisterExtension; 11 9 import org.openstreetmap.josm.testutils.JOSMTestRules; 10 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 12 11 13 import com.github.tomakehurst.wiremock. junit.WireMockRule;12 import com.github.tomakehurst.wiremock.WireMockServer; 14 13 15 14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 23 22 * Setup test. 24 23 */ 25 @R ule24 @RegisterExtension 26 25 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 27 publicJOSMTestRules test = new JOSMTestRules().https();26 JOSMTestRules test = new JOSMTestRules().https(); 28 27 29 28 /** 30 29 * HTTP mock. 31 30 */ 32 @ Rule33 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));31 @BasicWiremock 32 WireMockServer wireMockServer; 34 33 35 34 /** … … 53 52 */ 54 53 protected final String getRemoteFileUrl() { 55 return wireMock Rule.url(getRemoteFile());54 return wireMockServer.url(getRemoteFile()); 56 55 } 57 56 … … 60 59 */ 61 60 protected final void mockHttp() { 62 wireMock Rule.stubFor(get(urlEqualTo("/" + getRemoteFile()))61 wireMockServer.stubFor(get(urlEqualTo("/" + getRemoteFile())) 63 62 .willReturn(aResponse() 64 63 .withStatus(200) -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java
r13927 r18106 2 2 package org.openstreetmap.josm.actions.downloadtasks; 3 3 4 import static org.junit. Assert.assertFalse;5 import static org.junit. Assert.assertNotNull;6 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertFalse; 5 import static org.junit.jupiter.api.Assertions.assertNotNull; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 8 import java.util.concurrent.ExecutionException; 9 9 10 import org.junit. Test;10 import org.junit.jupiter.api.Test; 11 11 import org.openstreetmap.josm.data.gpx.GpxData; 12 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 12 13 13 14 /** 14 15 * Unit tests for class {@link DownloadGpsTask}. 15 16 */ 16 public class DownloadGpsTaskTest extends AbstractDownloadTaskTestParent { 17 @BasicWiremock 18 class DownloadGpsTaskTest extends AbstractDownloadTaskTestParent { 17 19 18 20 /** … … 20 22 */ 21 23 @Test 22 publicvoid testAcceptsURL() {24 void testAcceptsURL() { 23 25 DownloadGpsTask task = new DownloadGpsTask(); 24 26 assertFalse(task.acceptsUrl(null)); … … 42 44 */ 43 45 @Test 44 publicvoid testDownloadExternalFile() throws InterruptedException, ExecutionException {46 void testDownloadExternalFile() throws InterruptedException, ExecutionException { 45 47 mockHttp(); 46 48 DownloadGpsTask task = new DownloadGpsTask(); -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTaskTest.java
r13927 r18106 2 2 package org.openstreetmap.josm.actions.downloadtasks; 3 3 4 import static org.junit. Assert.assertFalse;5 import static org.junit. Assert.assertNotNull;6 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertFalse; 5 import static org.junit.jupiter.api.Assertions.assertNotNull; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 8 import java.util.concurrent.ExecutionException; 9 9 10 import org.junit. Test;10 import org.junit.jupiter.api.Test; 11 11 import org.openstreetmap.josm.data.osm.NoteData; 12 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 12 13 13 14 /** 14 15 * Unit tests for class {@link DownloadNotesTask}. 15 16 */ 16 public class DownloadNotesTaskTest extends AbstractDownloadTaskTestParent { 17 @BasicWiremock 18 class DownloadNotesTaskTest extends AbstractDownloadTaskTestParent { 17 19 18 20 /** … … 20 22 */ 21 23 @Test 22 publicvoid testAcceptsURL() {24 void testAcceptsURL() { 23 25 DownloadNotesTask task = new DownloadNotesTask(); 24 26 assertFalse(task.acceptsUrl(null)); … … 37 39 */ 38 40 @Test 39 publicvoid testDownloadExternalFile() throws InterruptedException, ExecutionException {41 void testDownloadExternalFile() throws InterruptedException, ExecutionException { 40 42 mockHttp(); 41 43 DownloadNotesTask task = new DownloadNotesTask(); -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskTest.java
r13927 r18106 2 2 package org.openstreetmap.josm.actions.downloadtasks; 3 3 4 import static org.junit. Assert.assertFalse;5 import static org.junit. Assert.assertNotNull;6 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertFalse; 5 import static org.junit.jupiter.api.Assertions.assertNotNull; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 8 import java.util.concurrent.ExecutionException; 9 9 10 import org.junit. Test;10 import org.junit.jupiter.api.Test; 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 12 13 13 14 /** 14 15 * Unit tests for class {@link DownloadOsmTask}. 15 16 */ 16 public class DownloadOsmTaskTest extends AbstractDownloadTaskTestParent { 17 @BasicWiremock 18 class DownloadOsmTaskTest extends AbstractDownloadTaskTestParent { 17 19 18 20 /** … … 20 22 */ 21 23 @Test 22 publicvoid testAcceptsURL() {24 void testAcceptsURL() { 23 25 DownloadOsmTask task = new DownloadOsmTask(); 24 26 assertFalse(task.acceptsUrl(null)); … … 39 41 */ 40 42 @Test 41 publicvoid testDownloadExternalFile() throws InterruptedException, ExecutionException {43 void testDownloadExternalFile() throws InterruptedException, ExecutionException { 42 44 mockHttp(); 43 45 DownloadOsmTask task = new DownloadOsmTask(); -
trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PluginDownloadTaskTest.java
r16162 r18106 2 2 package org.openstreetmap.josm.actions.downloadtasks; 3 3 4 import static org.junit. Assert.assertArrayEquals;5 import static org.junit. Assert.assertFalse;6 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertArrayEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 8 import java.io.File; … … 12 12 import java.util.Collections; 13 13 14 import org.junit. Rule;15 import org.junit. Test;14 import org.junit.jupiter.api.Test; 15 import org.junit.jupiter.api.extension.RegisterExtension; 16 16 import org.openstreetmap.josm.TestUtils; 17 17 import org.openstreetmap.josm.data.Preferences; … … 20 20 import org.openstreetmap.josm.plugins.PluginInformation; 21 21 import org.openstreetmap.josm.testutils.JOSMTestRules; 22 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 23 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 22 24 import org.openstreetmap.josm.tools.Utils; 23 25 … … 27 29 * Unit tests for class {@link PluginDownloadTask}. 28 30 */ 29 public class PluginDownloadTaskTest extends AbstractDownloadTaskTestParent { 31 @BasicWiremock 32 @BasicPreferences 33 class PluginDownloadTaskTest extends AbstractDownloadTaskTestParent { 30 34 protected String pluginPath; 31 35 … … 33 37 * Setup test. 34 38 */ 35 @R ule39 @RegisterExtension 36 40 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 41 public JOSMTestRules testRule = new JOSMTestRules().https().assumeRevision( 38 42 "Revision: 8000\n" 39 ) .preferences();43 ); 40 44 41 45 @Override … … 55 59 */ 56 60 @Test 57 publicvoid testUpdatePluginValid() throws Exception {61 void testUpdatePluginValid() throws Exception { 58 62 this.pluginPath = "plugin/dummy_plugin.v31772.jar"; 59 63 this.mockHttp(); … … 97 101 */ 98 102 @Test 99 publicvoid testUpdatePluginCorrupt() throws Exception {103 void testUpdatePluginCorrupt() throws Exception { 100 104 this.pluginPath = "plugin/corrupted_plugin.jar"; 101 105 this.mockHttp(); -
trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java
r17075 r18106 10 10 import static com.github.tomakehurst.wiremock.client.WireMock.status; 11 11 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 12 import static org.junit. Assert.assertArrayEquals;13 import static org.junit. Assert.assertEquals;14 import static org.junit. Assert.assertFalse;15 import static org.junit. Assert.assertTrue;12 import static org.junit.jupiter.api.Assertions.assertArrayEquals; 13 import static org.junit.jupiter.api.Assertions.assertEquals; 14 import static org.junit.jupiter.api.Assertions.assertFalse; 15 import static org.junit.jupiter.api.Assertions.assertTrue; 16 16 17 17 import java.io.IOException; … … 23 23 import org.apache.commons.jcs3.access.behavior.ICacheAccess; 24 24 import org.apache.commons.jcs3.engine.behavior.ICacheElement; 25 import org.junit. Before;26 import org.junit. Rule;27 import org.junit. Test;25 import org.junit.jupiter.api.BeforeEach; 26 import org.junit.jupiter.api.Test; 27 import org.junit.jupiter.api.Timeout; 28 28 import org.openstreetmap.josm.TestUtils; 29 29 import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult; 30 30 import org.openstreetmap.josm.data.imagery.TileJobOptions; 31 import org.openstreetmap.josm.testutils.JOSMTestRules; 31 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 32 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 32 33 import org.openstreetmap.josm.tools.Logging; 33 34 34 import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 35 import com.github.tomakehurst.wiremock.junit.WireMockRule; 35 import com.github.tomakehurst.wiremock.WireMockServer; 36 36 import com.github.tomakehurst.wiremock.matching.UrlPattern; 37 38 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;39 37 40 38 /** 41 39 * Unit tests for class {@link JCSCachedTileLoaderJob}. 42 40 */ 43 public class JCSCachedTileLoaderJobTest { 41 @BasicWiremock 42 @BasicPreferences 43 @Timeout(20) 44 class JCSCachedTileLoaderJobTest { 44 45 45 46 /** 46 47 * mocked tile server 47 48 */ 48 @Rule 49 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options() 50 .dynamicPort()); 49 @BasicWiremock 50 WireMockServer tileServer; 51 51 52 52 private static class TestCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, CacheEntry> { … … 104 104 105 105 /** 106 * Setup test.107 */108 @Rule109 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")110 public JOSMTestRules test = new JOSMTestRules().preferences().timeout(20_000);111 112 /**113 106 * Always clear cache before tests 114 107 * @throws Exception when clearing fails 115 108 */ 116 @Before 117 publicvoid clearCache() throws Exception {109 @BeforeEach 110 void clearCache() throws Exception { 118 111 getCache().clear(); 119 112 } … … 125 118 */ 126 119 @Test 127 publicvoid testStatusCodes() throws IOException, InterruptedException {120 void testStatusCodes() throws IOException, InterruptedException { 128 121 doTestStatusCode(200); 129 122 doTestStatusCode(401); … … 142 135 */ 143 136 @Test 144 publicvoid testUnknownHost() throws IOException {137 void testUnknownHost() throws IOException { 145 138 String key = "key_unknown_host"; 146 139 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key); … … 193 186 */ 194 187 @Test 195 publicvoid testNoRequestMadeWhenEntryInCache() throws IOException {188 void testNoRequestMadeWhenEntryInCache() throws IOException { 196 189 ICacheAccess<String, CacheEntry> cache = getCache(); 197 190 long expires = TimeUnit.DAYS.toMillis(1); … … 214 207 */ 215 208 @Test 216 publicvoid testRequestMadeWhenEntryInCacheAndForce() throws IOException {209 void testRequestMadeWhenEntryInCacheAndForce() throws IOException { 217 210 ICacheAccess<String, CacheEntry> cache = getCache(); 218 211 long expires = TimeUnit.DAYS.toMillis(1); … … 236 229 */ 237 230 @Test 238 publicvoid testSettingMinimumExpiryWhenNoExpires() throws IOException {231 void testSettingMinimumExpiryWhenNoExpires() throws IOException { 239 232 long testStart = System.currentTimeMillis(); 240 233 tileServer.stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withBody("mock entry"))); … … 244 237 tileServer.verify(1, getRequestedFor(urlEqualTo("/test"))); 245 238 246 assertTrue( "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " +247 JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)",248 listener.attributes.getExpirationTime() >= testStart + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME);249 250 assertTrue( "Cache entry expiration is " +251 (listener.attributes.getExpirationTime() - System.currentTimeMillis())+252 " which is not less than "+253 JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)",254 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME239 assertTrue(listener.attributes.getExpirationTime() >= testStart + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME, 240 "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 241 JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)"); 242 243 assertTrue(listener.attributes.getExpirationTime() <= System.currentTimeMillis() + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME, 244 "Cache entry expiration is " + 245 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 246 " which is not less than " + 247 JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)" 255 248 ); 256 249 … … 264 257 */ 265 258 @Test 266 publicvoid testSettingExpireByMaxAge() throws IOException {259 void testSettingExpireByMaxAge() throws IOException { 267 260 long testStart = System.currentTimeMillis(); 268 261 long expires = TimeUnit.DAYS.toSeconds(1); … … 278 271 tileServer.verify(1, getRequestedFor(urlEqualTo("/test"))); 279 272 280 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 281 TimeUnit.SECONDS.toMillis(expires) + " (max-age)", 282 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(expires)); 283 284 assertTrue("Cache entry expiration is " + 285 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 286 " which is not less than " + 287 TimeUnit.SECONDS.toMillis(expires) + " (max-age)", 288 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expires) 289 ); 273 assertTrue(listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(expires), 274 "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 275 TimeUnit.SECONDS.toMillis(expires) + " (max-age)"); 276 277 assertTrue( 278 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expires), 279 "Cache entry expiration is " + 280 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 281 " which is not less than " + 282 TimeUnit.SECONDS.toMillis(expires) + " (max-age)" 283 ); 290 284 291 285 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); … … 298 292 */ 299 293 @Test 300 publicvoid testSettingMinimumExpiryByMinimumExpiryTimeLessThanDefault() throws IOException {294 void testSettingMinimumExpiryByMinimumExpiryTimeLessThanDefault() throws IOException { 301 295 long testStart = System.currentTimeMillis(); 302 296 int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2); … … 310 304 311 305 312 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 313 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 314 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)); 315 316 assertTrue("Cache entry expiration is " + 317 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 318 " which is not less than " + 319 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 320 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) 321 ); 306 assertTrue( 307 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds), 308 "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 309 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)"); 310 311 assertTrue( 312 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds), 313 "Cache entry expiration is " + 314 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 315 " which is not less than " + 316 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)" 317 ); 322 318 } 323 319 … … 329 325 330 326 @Test 331 publicvoid testSettingMinimumExpiryByMinimumExpiryTimeGreaterThanDefault() throws IOException {327 void testSettingMinimumExpiryByMinimumExpiryTimeGreaterThanDefault() throws IOException { 332 328 long testStart = System.currentTimeMillis(); 333 329 int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME * 2); … … 341 337 342 338 343 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 344 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 345 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)); 346 347 assertTrue("Cache entry expiration is " + 348 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 349 " which is not less than " + 350 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 351 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) 352 ); 339 assertTrue( 340 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds), 341 "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 342 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)"); 343 344 assertTrue( 345 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds), 346 "Cache entry expiration is " + 347 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 348 " which is not less than " + 349 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)" 350 ); 353 351 } 354 352 … … 365 363 366 364 @Test 367 publicvoid testCacheControlVsExpires() throws IOException {365 void testCacheControlVsExpires() throws IOException { 368 366 long testStart = System.currentTimeMillis(); 369 367 int minimumExpiryTimeSeconds = 0; … … 390 388 391 389 392 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 393 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Expires header)", 394 listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10)); 395 396 assertTrue("Cache entry expiration is " + 397 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 398 " which is not less than " + 399 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: max-age=)", 400 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) 401 ); 390 assertTrue( 391 listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10), 392 "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 393 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Expires header)"); 394 395 assertTrue(listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2), 396 "Cache entry expiration is " + 397 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 398 " which is not less than " + 399 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: max-age=)" 400 ); 402 401 } 403 402 … … 410 409 */ 411 410 @Test 412 publicvoid testMaxAgeVsSMaxAge() throws IOException {411 void testMaxAgeVsSMaxAge() throws IOException { 413 412 long testStart = System.currentTimeMillis(); 414 413 int minimumExpiryTimeSeconds = 0; … … 435 434 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); 436 435 437 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 438 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Cache-Control: max-age)", 439 listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10)); 440 441 assertTrue("Cache entry expiration is " + 442 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 443 " which is not less than " + 444 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: s-max-age)", 445 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) 446 ); 436 assertTrue( 437 listener.attributes.getExpirationTime() >= testStart + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10), 438 "Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 439 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10) + " (Cache-Control: max-age)"); 440 441 assertTrue(listener.attributes.getExpirationTime() <= System.currentTimeMillis() + (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2), 442 "Cache entry expiration is " + 443 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 444 " which is not less than " + 445 (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2) + " (Cache-Control: s-max-age)" 446 ); 447 447 } 448 448 … … 452 452 */ 453 453 @Test 454 publicvoid testCheckUsingHead() throws IOException {454 void testCheckUsingHead() throws IOException { 455 455 ICacheAccess<String, CacheEntry> cache = getCache(); 456 456 long expires = TimeUnit.DAYS.toMillis(1); -
trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java
r16913 r18106 2 2 package org.openstreetmap.josm.data.imagery; 3 3 4 import static org.junit. Assert.assertArrayEquals;5 import static org.junit. Assert.assertEquals;6 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertArrayEquals; 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 8 import java.io.IOException; … … 17 17 18 18 import org.apache.commons.jcs3.access.behavior.ICacheAccess; 19 import org.junit.Before; 20 import org.junit.Rule; 21 import org.junit.Test; 19 import org.junit.jupiter.api.BeforeEach; 20 import org.junit.jupiter.api.Test; 22 21 import org.openstreetmap.gui.jmapviewer.Tile; 23 22 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener; … … 27 26 import org.openstreetmap.josm.data.cache.CacheEntryAttributes; 28 27 import org.openstreetmap.josm.data.cache.JCSCacheManager; 29 import org.openstreetmap.josm.testutils.JOSMTestRules; 28 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 29 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 30 30 import org.openstreetmap.josm.tools.Logging; 31 31 import org.openstreetmap.josm.tools.Utils; 32 32 33 import com.github.tomakehurst.wiremock.WireMockServer; 33 34 import com.github.tomakehurst.wiremock.client.WireMock; 34 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;35 import com.github.tomakehurst.wiremock.junit.WireMockRule;36 37 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;38 35 39 36 /** 40 37 * Unit tests for class {@link TMSCachedTileLoaderJob}. 41 38 */ 42 public class TMSCachedTileLoaderJobTest { 43 44 /** 45 * Setup tests 46 */ 47 @Rule 48 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 49 public JOSMTestRules test = new JOSMTestRules().preferences(); 50 39 @BasicWiremock 40 @BasicPreferences 41 class TMSCachedTileLoaderJobTest { 51 42 /** 52 43 * mocked tile server 53 44 */ 54 @Rule 55 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options() 56 .dynamicPort()); 57 58 @Before 59 public void clearCache() throws Exception { 45 @BasicWiremock 46 WireMockServer tileServer; 47 48 @BeforeEach 49 void clearCache() throws Exception { 60 50 getCache().clear(); 61 51 } … … 145 135 */ 146 136 @Test 147 publicvoid testServiceExceptionPattern() {137 void testServiceExceptionPattern() { 148 138 testServiceException("missing parameters ['version', 'format']", 149 139 "<?xml version=\"1.0\"?>\n" + … … 167 157 */ 168 158 @Test 169 publicvoid testCdataPattern() {159 void testCdataPattern() { 170 160 testCdata("received unsuitable wms request: no <grid> with suitable srs found for layer capitais", 171 161 "<![CDATA[\r\n" + … … 178 168 */ 179 169 @Test 180 publicvoid testJsonPattern() {170 void testJsonPattern() { 181 171 testJson("Tile does not exist", 182 172 "{\"message\":\"Tile does not exist\"}"); … … 197 187 private static void test(Pattern pattern, String expected, String text) { 198 188 Matcher m = pattern.matcher(text); 199 assertTrue( text, m.matches());189 assertTrue(m.matches(), text); 200 190 assertEquals(expected, Utils.strip(m.group(1))); 201 191 } … … 227 217 */ 228 218 @Test 229 publicvoid testNoCacheHeaders() throws IOException {219 void testNoCacheHeaders() throws IOException { 230 220 long testStart = System.currentTimeMillis(); 231 221 tileServer.stubFor( … … 250 240 */ 251 241 @Test 252 publicvoid testNoCacheHeadersMinimumExpires() throws IOException {242 void testNoCacheHeadersMinimumExpires() throws IOException { 253 243 noCacheHeadersMinimumExpires((int) TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get() * 2)); 254 244 } … … 261 251 262 252 @Test 263 publicvoid testNoCacheHeadersMinimumExpiresLargerThanMaximum() throws IOException {253 void testNoCacheHeadersMinimumExpiresLargerThanMaximum() throws IOException { 264 254 noCacheHeadersMinimumExpires((int) TimeUnit.MILLISECONDS.toSeconds(TMSCachedTileLoaderJob.MAXIMUM_EXPIRES.get() * 2)); 265 255 } … … 287 277 */ 288 278 @Test 289 publicvoid testShortExpire() throws IOException {279 void testShortExpire() throws IOException { 290 280 long testStart = System.currentTimeMillis(); 291 281 long expires = TMSCachedTileLoaderJob.MINIMUM_EXPIRES.get() / 2; … … 307 297 308 298 private void assertExpirationAtLeast(long duration, TestCachedTileLoaderJob job) { 309 assertTrue( 310 "Expiration time shorter by " + 311 -1 * (job.getAttributes().getExpirationTime() - duration) + 312 " than expected", 313 job.getAttributes().getExpirationTime() >= duration); 299 assertTrue(job.getAttributes().getExpirationTime() >= duration, "Expiration time shorter by " + 300 -1 * (job.getAttributes().getExpirationTime() - duration) + 301 " than expected"); 314 302 } 315 303 316 304 private void assertExpirationAtMost(long duration, TestCachedTileLoaderJob job) { 317 assertTrue( 318 "Expiration time longer by " + 319 (job.getAttributes().getExpirationTime() - duration) + 320 " than expected", 321 job.getAttributes().getExpirationTime() <= duration); 322 } 323 324 @Test 325 public void testLongExpire() throws IOException { 305 assertTrue(job.getAttributes().getExpirationTime() <= duration, "Expiration time longer by " + 306 (job.getAttributes().getExpirationTime() - duration) + 307 " than expected"); 308 } 309 310 @Test 311 void testLongExpire() throws IOException { 326 312 long testStart = System.currentTimeMillis(); 327 313 long expires = TMSCachedTileLoaderJob.MAXIMUM_EXPIRES.get() * 2; … … 343 329 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 344 330 } 345 346 331 } -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java
r16636 r18106 2 2 package org.openstreetmap.josm.data.imagery; 3 3 4 import static org.junit. Assert.assertEquals;5 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertTrue; 6 6 7 7 import java.nio.file.Files; … … 9 9 import java.util.Arrays; 10 10 11 import org.junit. Rule;12 import org.junit. Test;11 import org.junit.jupiter.api.Test; 12 import org.junit.jupiter.api.extension.RegisterExtension; 13 13 import org.openstreetmap.josm.TestUtils; 14 14 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; … … 17 17 import org.openstreetmap.josm.spi.preferences.Config; 18 18 import org.openstreetmap.josm.testutils.JOSMTestRules; 19 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 19 20 21 import com.github.tomakehurst.wiremock.WireMockServer; 20 22 import com.github.tomakehurst.wiremock.client.WireMock; 21 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;22 import com.github.tomakehurst.wiremock.junit.WireMockRule;23 23 24 24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 25 25 26 public class WMSEndpointTileSourceTest { 26 @BasicWiremock 27 class WMSEndpointTileSourceTest { 27 28 /** 28 29 * Setup test 29 30 */ 30 @R ule31 @RegisterExtension 31 32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 32 33 public JOSMTestRules test = new JOSMTestRules().projection(); 33 34 34 @Rule 35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 36 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort()); 35 @BasicWiremock 36 WireMockServer tileServer; 37 37 38 38 @Test 39 publicvoid testDefaultLayerSetInMaps() throws Exception {39 void testDefaultLayerSetInMaps() throws Exception { 40 40 41 41 tileServer.stubFor( … … 87 87 88 88 @Test 89 publicvoid testCustomHeaders() throws Exception {89 void testCustomHeaders() throws Exception { 90 90 tileServer.stubFor( 91 91 WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities")) -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
r17549 r18106 2 2 package org.openstreetmap.josm.data.imagery; 3 3 4 import static org.junit. Assert.assertEquals;5 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertTrue; 6 6 7 7 import java.io.File; … … 15 15 import java.util.concurrent.TimeUnit; 16 16 17 import org.junit.ClassRule; 18 import org.junit.Ignore; 19 import org.junit.Rule; 20 import org.junit.Test; 17 import org.junit.jupiter.api.Disabled; 18 import org.junit.jupiter.api.Test; 19 import org.junit.jupiter.api.extension.RegisterExtension; 21 20 import org.openstreetmap.gui.jmapviewer.TileXY; 22 21 import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource; … … 30 29 import org.openstreetmap.josm.spi.preferences.Config; 31 30 import org.openstreetmap.josm.testutils.JOSMTestRules; 32 31 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 32 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 33 34 import com.github.tomakehurst.wiremock.WireMockServer; 33 35 import com.github.tomakehurst.wiremock.client.WireMock; 34 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;35 import com.github.tomakehurst.wiremock.junit.WireMockRule;36 36 37 37 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 40 40 * Unit tests for class {@link WMTSTileSource}. 41 41 */ 42 public class WMTSTileSourceTest { 42 @BasicWiremock 43 @BasicPreferences 44 class WMTSTileSourceTest { 43 45 44 46 /** 45 47 * Setup test. 46 48 */ 47 @ ClassRule49 @RegisterExtension 48 50 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 49 public static JOSMTestRules test = new JOSMTestRules().preferences().projection().timeout((int) TimeUnit.MINUTES.toMillis(5)); 50 51 @Rule 52 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 53 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort()); 51 public static JOSMTestRules test = new JOSMTestRules().projection().timeout((int) TimeUnit.MINUTES.toMillis(5)); 52 53 @BasicWiremock 54 WireMockServer tileServer; 54 55 55 56 private final ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null); … … 86 87 87 88 @Test 88 publicvoid testPseudoMercator() throws IOException, WMTSGetCapabilitiesException {89 void testPseudoMercator() throws IOException, WMTSGetCapabilitiesException { 89 90 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 90 91 WMTSTileSource testSource = new WMTSTileSource(testImageryPSEUDO_MERCATOR); … … 107 108 verifyMercatorTile(testSource, 2 << 9 - 1, 2 << 8 - 1, 10); 108 109 109 assertEquals( "TileXMax", 1, testSource.getTileXMax(0));110 assertEquals( "TileYMax", 1, testSource.getTileYMax(0));111 assertEquals( "TileXMax", 2, testSource.getTileXMax(1));112 assertEquals( "TileYMax", 2, testSource.getTileYMax(1));113 assertEquals( "TileXMax", 4, testSource.getTileXMax(2));114 assertEquals( "TileYMax", 4, testSource.getTileYMax(2));115 } 116 117 @Test 118 publicvoid testWALLONIE() throws IOException, WMTSGetCapabilitiesException {110 assertEquals(1, testSource.getTileXMax(0), "TileXMax"); 111 assertEquals(1, testSource.getTileYMax(0), "TileYMax"); 112 assertEquals(2, testSource.getTileXMax(1), "TileXMax"); 113 assertEquals(2, testSource.getTileYMax(1), "TileYMax"); 114 assertEquals(4, testSource.getTileXMax(2), "TileXMax"); 115 assertEquals(4, testSource.getTileYMax(2), "TileYMax"); 116 } 117 118 @Test 119 void testWALLONIE() throws IOException, WMTSGetCapabilitiesException { 119 120 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:31370")); 120 121 WMTSTileSource testSource = new WMTSTileSource(testImageryWALLONIE); … … 135 136 136 137 @Test 137 @ Ignore("disable this test, needs further working") // XXX138 publicvoid testWALLONIENoMatrixDimension() throws IOException, WMTSGetCapabilitiesException {138 @Disabled("disable this test, needs further working") // XXX 139 void testWALLONIENoMatrixDimension() throws IOException, WMTSGetCapabilitiesException { 139 140 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:31370")); 140 141 WMTSTileSource testSource = new WMTSTileSource(getImagery("test/data/wmts/WMTSCapabilities-Wallonie-nomatrixdimension.xml")); … … 152 153 private void verifyBounds(Bounds bounds, WMTSTileSource testSource, int z, int x, int y) { 153 154 LatLon ret = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z)); 154 assertTrue( ret.toDisplayString() + " doesn't lie within: " + bounds.toString(), bounds.contains(ret));155 assertTrue(bounds.contains(ret), ret.toDisplayString() + " doesn't lie within: " + bounds); 155 156 int tileXmax = testSource.getTileXMax(z); 156 157 int tileYmax = testSource.getTileYMax(z); 157 assertTrue( "tile x: " + x + " is greater than allowed max: " + tileXmax, tileXmax >=x);158 assertTrue( "tile y: " + y + " is greater than allowed max: " + tileYmax, tileYmax >= y);159 } 160 161 @Test 162 publicvoid testWIEN() throws IOException, WMTSGetCapabilitiesException {158 assertTrue(tileXmax >= x, "tile x: " + x + " is greater than allowed max: " + tileXmax); 159 assertTrue(tileYmax >= y, "tile y: " + y + " is greater than allowed max: " + tileYmax); 160 } 161 162 @Test 163 void testWIEN() throws IOException, WMTSGetCapabilitiesException { 163 164 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 164 165 WMTSTileSource testSource = new WMTSTileSource(testImageryWIEN); … … 195 196 int result = testSource.getTileXMax(zoom); 196 197 int expected = verifier.getTileXMax(zoom + zoomOffset); 197 assertTrue( "TileXMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);198 assertTrue(Math.abs(result - expected) < 5, "TileXMax expected: " + expected + " got: " + result); 198 199 result = testSource.getTileYMax(zoom); 199 200 expected = verifier.getTileYMax(zoom + zoomOffset); 200 assertTrue( "TileYMax expected: " + expected + " got: " + result, Math.abs(result - expected) < 5);201 } 202 203 @Test 204 publicvoid testGeoportalTOPOPL() throws IOException, WMTSGetCapabilitiesException {201 assertTrue(Math.abs(result - expected) < 5, "TileYMax expected: " + expected + " got: " + result); 202 } 203 204 @Test 205 void testGeoportalTOPOPL() throws IOException, WMTSGetCapabilitiesException { 205 206 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:4326")); 206 207 WMTSTileSource testSource = new WMTSTileSource(testImageryTOPO_PL); … … 210 211 verifyTile(new LatLon(51.13231917844218, 16.867680821557823), testSource, 1, 1, 1); 211 212 212 assertEquals( "TileXMax", 2, testSource.getTileXMax(0));213 assertEquals( "TileYMax", 1, testSource.getTileYMax(0));214 assertEquals( "TileXMax", 3, testSource.getTileXMax(1));215 assertEquals( "TileYMax", 2, testSource.getTileYMax(1));216 assertEquals( "TileXMax", 6, testSource.getTileXMax(2));217 assertEquals( "TileYMax", 4, testSource.getTileYMax(2));213 assertEquals(2, testSource.getTileXMax(0), "TileXMax"); 214 assertEquals(1, testSource.getTileYMax(0), "TileYMax"); 215 assertEquals(3, testSource.getTileXMax(1), "TileXMax"); 216 assertEquals(2, testSource.getTileYMax(1), "TileYMax"); 217 assertEquals(6, testSource.getTileXMax(2), "TileXMax"); 218 assertEquals(4, testSource.getTileYMax(2), "TileYMax"); 218 219 assertEquals( 219 220 "http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/TOPO?SERVICE=WMTS&REQUEST=GetTile&" … … 224 225 225 226 @Test 226 publicvoid testGeoportalORTOPL4326() throws IOException, WMTSGetCapabilitiesException {227 void testGeoportalORTOPL4326() throws IOException, WMTSGetCapabilitiesException { 227 228 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:4326")); 228 229 WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL); … … 233 234 234 235 @Test 235 publicvoid testGeoportalORTOPL2180() throws IOException, WMTSGetCapabilitiesException {236 void testGeoportalORTOPL2180() throws IOException, WMTSGetCapabilitiesException { 236 237 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:2180")); 237 238 WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL); … … 243 244 244 245 @Test 245 publicvoid testTicket12168() throws IOException, WMTSGetCapabilitiesException {246 void testTicket12168() throws IOException, WMTSGetCapabilitiesException { 246 247 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 247 248 WMTSTileSource testSource = new WMTSTileSource(testImagery12168); … … 253 254 254 255 @Test 255 publicvoid testProjectionWithENUAxis() throws IOException, WMTSGetCapabilitiesException {256 void testProjectionWithENUAxis() throws IOException, WMTSGetCapabilitiesException { 256 257 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3346")); 257 258 WMTSTileSource testSource = new WMTSTileSource(testImageryORT2LT); … … 267 268 268 269 @Test 269 publicvoid testTwoTileSetsForOneProjection() throws Exception {270 void testTwoTileSetsForOneProjection() throws Exception { 270 271 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 271 272 ImageryInfo ontario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml"); … … 284 285 285 286 @Test 286 publicvoid testTwoTileSetsForOneProjectionSecondLayer() throws Exception {287 void testTwoTileSetsForOneProjectionSecondLayer() throws Exception { 287 288 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 288 289 ImageryInfo ontario = getImagery(TestUtils.getTestDataRoot() + "wmts/WMTSCapabilities-Ontario.xml"); … … 301 302 302 303 @Test 303 publicvoid testManyLayersScrollbars() throws Exception {304 void testManyLayersScrollbars() throws Exception { 304 305 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 305 306 WMTSTileSource testSource = new WMTSTileSource(testLotsOfLayers); … … 308 309 309 310 @Test 310 publicvoid testParserForDuplicateTags() throws Exception {311 void testParserForDuplicateTags() throws Exception { 311 312 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 312 313 WMTSTileSource testSource = new WMTSTileSource(testDuplicateTags); … … 320 321 321 322 @Test 322 publicvoid testParserForMissingStyleIdentifier() throws Exception {323 void testParserForMissingStyleIdentifier() throws Exception { 323 324 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 324 325 WMTSTileSource testSource = new WMTSTileSource(testMissingStyleIdentifier); … … 327 328 328 329 @Test 329 publicvoid testForMultipleTileMatricesForOneLayerProjection() throws Exception {330 void testForMultipleTileMatricesForOneLayerProjection() throws Exception { 330 331 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:3857")); 331 332 ImageryInfo copy = new ImageryInfo(testMultipleTileMatrixForLayer); … … 348 349 */ 349 350 @Test 350 publicvoid testDimension() throws IOException, WMTSGetCapabilitiesException {351 void testDimension() throws IOException, WMTSGetCapabilitiesException { 351 352 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:21781")); 352 353 ImageryInfo info = new ImageryInfo(testImageryGeoAdminCh); … … 363 364 364 365 @Test 365 publicvoid testDefaultLayer() throws Exception {366 void testDefaultLayer() throws Exception { 366 367 // https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/1.0.0/WMTSCapabilities.xml 367 368 // do not use withFileBody as it needs different directory layout :( … … 412 413 private void verifyTile(LatLon expected, WMTSTileSource source, int x, int y, int z) { 413 414 LatLon ll = CoordinateConversion.coorToLL(source.tileXYToLatLon(x, y, z)); 414 assertEquals( "Latitude", expected.lat(), ll.lat(), 1e-05);415 assertEquals( "Longitude", expected.lon(), ll.lon(), 1e-05);415 assertEquals(expected.lat(), ll.lat(), 1e-05, "Latitude"); 416 assertEquals(expected.lon(), ll.lon(), 1e-05, "Longitude"); 416 417 } 417 418 … … 424 425 LatLon result = CoordinateConversion.coorToLL(testSource.tileXYToLatLon(x, y, z)); 425 426 LatLon expected = CoordinateConversion.coorToLL(verifier.tileXYToLatLon(x, y, z + zoomOffset)); 426 assertEquals( "Longitude", LatLon.normalizeLon(expected.lon() - result.lon()), 0.0, 1e-04);427 assertEquals( "Latitude", expected.lat(), result.lat(), 1e-04);428 } 429 430 @Test 431 publicvoid testGisKtnGvAt() throws IOException, WMTSGetCapabilitiesException {427 assertEquals(0.0, LatLon.normalizeLon(expected.lon() - result.lon()), 1e-04, "Longitude"); 428 assertEquals(expected.lat(), result.lat(), 1e-04, "Latitude"); 429 } 430 431 @Test 432 void testGisKtnGvAt() throws IOException, WMTSGetCapabilitiesException { 432 433 ProjectionRegistry.setProjection(Projections.getProjectionByCode("EPSG:31258")); 433 434 final WMTSTileSource source = new WMTSTileSource(testImageryGisKtnGvAt); -
trunk/test/unit/org/openstreetmap/josm/data/osm/DefaultNameFormatterTest.java
r17673 r18106 5 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 8 import static org.junit.Assert.assertEquals; 7 import static org.junit.jupiter.api.Assertions.assertEquals; 9 8 10 9 import java.io.IOException; … … 16 15 import java.util.stream.IntStream; 17 16 18 import org.junit.Rule; 19 import org.junit.Test; 17 import org.junit.jupiter.api.Test; 20 18 import org.openstreetmap.josm.TestUtils; 21 19 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader; … … 23 21 import org.openstreetmap.josm.io.IllegalDataException; 24 22 import org.openstreetmap.josm.io.OsmReader; 25 import org.openstreetmap.josm.testutils.JOSMTestRules; 23 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 24 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 25 import org.openstreetmap.josm.testutils.annotations.HTTP; 26 26 import org.xml.sax.SAXException; 27 27 28 import com.github.tomakehurst.wiremock. junit.WireMockRule;28 import com.github.tomakehurst.wiremock.WireMockServer; 29 29 30 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 33 33 * Unit tests of {@link DefaultNameFormatter} class. 34 34 */ 35 public class DefaultNameFormatterTest { 36 37 /** 38 * Setup test. 39 */ 40 @Rule 41 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 42 public JOSMTestRules test = new JOSMTestRules(); 43 35 // Preferences are needed for OSM primitives 36 @BasicPreferences 37 @BasicWiremock 38 @HTTP 39 class DefaultNameFormatterTest { 44 40 /** 45 41 * HTTP mock. 46 42 */ 47 @ Rule48 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));43 @BasicWiremock 44 WireMockServer wireMockServer; 49 45 50 46 /** … … 56 52 @Test 57 53 @SuppressFBWarnings(value = "ITA_INEFFICIENT_TO_ARRAY") 58 publicvoid testTicket9632() throws IllegalDataException, IOException, SAXException {54 void testTicket9632() throws IllegalDataException, IOException, SAXException { 59 55 String source = "presets/Presets_BicycleJunction-preset.xml"; 60 wireMock Rule.stubFor(get(urlEqualTo("/" + source))56 wireMockServer.stubFor(get(urlEqualTo("/" + source)) 61 57 .willReturn(aResponse() 62 58 .withStatus(200) 63 59 .withHeader("Content-Type", "text/xml") 64 60 .withBodyFile(source))); 65 TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll(wireMock Rule.url(source), true));61 TaggingPresets.addTaggingPresets(TaggingPresetReader.readAll(wireMockServer.url(source), true)); 66 62 67 63 Comparator<IRelation<?>> comparator = DefaultNameFormatter.getInstance().getRelationComparator(); … … 102 98 */ 103 99 @Test 104 publicvoid testRelationName() {100 void testRelationName() { 105 101 assertEquals("relation (0, 0 members)", 106 102 getFormattedRelationName("X=Y")); … … 123 119 */ 124 120 @Test 125 publicvoid testWayName() {121 void testWayName() { 126 122 assertEquals("\u200Ebuilding\u200E (0 nodes)\u200C", getFormattedWayName("building=yes")); 127 123 assertEquals("\u200EHouse number 123\u200E (0 nodes)\u200C", … … 145 141 */ 146 142 @Test 147 publicvoid testFormatAsHtmlUnorderedList() {143 void testFormatAsHtmlUnorderedList() { 148 144 assertEquals("<ul><li>incomplete</li></ul>", 149 145 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(new Node(1))); … … 159 155 */ 160 156 @Test 161 publicvoid testBuildDefaultToolTip() {157 void testBuildDefaultToolTip() { 162 158 assertEquals("<html><strong>id</strong>=0<br>"+ 163 159 "<strong>name:en</strong>=foo<br>"+ … … 173 169 */ 174 170 @Test 175 publicvoid testRemoveBiDiCharacters() {171 void testRemoveBiDiCharacters() { 176 172 assertEquals("building (0 nodes)", DefaultNameFormatter.removeBiDiCharacters("\u200Ebuilding\u200E (0 nodes)\u200C")); 177 173 } -
trunk/test/unit/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClientTest.java
r17196 r18106 5 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 8 import static org.junit.Assert.assertEquals; 9 import static org.junit.Assert.assertNotNull; 10 import static org.junit.Assert.assertNull; 7 import static org.junit.jupiter.api.Assertions.assertEquals; 8 import static org.junit.jupiter.api.Assertions.assertNotNull; 9 import static org.junit.jupiter.api.Assertions.assertNull; 11 10 12 11 import java.net.CookieHandler; … … 15 14 import java.util.Collections; 16 15 17 import org.junit. Rule;18 import org.junit. Test;16 import org.junit.jupiter.api.Test; 17 import org.junit.jupiter.api.Timeout; 19 18 import org.openstreetmap.josm.data.oauth.OAuthParameters; 20 19 import org.openstreetmap.josm.data.oauth.OAuthToken; 21 20 import org.openstreetmap.josm.io.OsmTransferCanceledException; 22 import org.openstreetmap.josm.testutils.JOSMTestRules; 21 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 22 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 23 import org.openstreetmap.josm.testutils.annotations.HTTP; 23 24 24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 25 26 import com.github.tomakehurst.wiremock.junit.WireMockRule; 25 import com.github.tomakehurst.wiremock.WireMockServer; 27 26 28 27 /** 29 28 * Unit tests of {@link OsmOAuthAuthorizationClient} class. 30 29 */ 31 public class OsmOAuthAuthorizationClientTest { 32 33 /** 34 * Setup tests 35 */ 36 @Rule 37 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 public JOSMTestRules test = new JOSMTestRules().timeout(20000); 39 30 @Timeout(20) 31 @BasicWiremock 32 // Needed for OAuthParameters 33 @BasicPreferences 34 @HTTP 35 class OsmOAuthAuthorizationClientTest { 40 36 /** 41 37 * HTTP mock. 42 38 */ 43 @ Rule44 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());39 @BasicWiremock 40 WireMockServer wireMockServer; 45 41 46 42 /** … … 50 46 */ 51 47 @Test 52 publicvoid testOsmOAuthAuthorizationClient() throws OsmTransferCanceledException, OsmOAuthAuthorizationException {48 void testOsmOAuthAuthorizationClient() throws OsmTransferCanceledException, OsmOAuthAuthorizationException { 53 49 // request token 54 wireMock Rule.stubFor(get(urlEqualTo("/oauth/request_token"))50 wireMockServer.stubFor(get(urlEqualTo("/oauth/request_token")) 55 51 .willReturn(aResponse().withStatus(200).withBody(String.join("&", 56 52 "oauth_token=entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR", 57 53 "oauth_token_secret=nsBD2Hr5lLGDUeNoh3SnLaGsUV1TiPYM4qUr7tPB")))); 58 OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(OAuthParameters.createDefault(wireMockRule.url("/api"))); 54 OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(OAuthParameters.createDefault( 55 wireMockServer.url("/api"))); 59 56 60 57 OAuthToken requestToken = client.getRequestToken(null); 61 assertEquals(" requestToken.key", "entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR", requestToken.getKey());62 assertEquals(" requestToken.secret", "nsBD2Hr5lLGDUeNoh3SnLaGsUV1TiPYM4qUr7tPB", requestToken.getSecret());58 assertEquals("entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR", requestToken.getKey(), "requestToken.key"); 59 assertEquals("nsBD2Hr5lLGDUeNoh3SnLaGsUV1TiPYM4qUr7tPB", requestToken.getSecret(), "requestToken.secret"); 63 60 String url = client.getAuthoriseUrl(requestToken); 64 assertEquals( "url", wireMockRule.url("/oauth/authorize?oauth_token=entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR"), url);61 assertEquals(wireMockServer.url("/oauth/authorize?oauth_token=entxUGuwRKV6KyVDF0OWScdGhbqXGMGmosXuiChR"), url, "url"); 65 62 66 63 // access token 67 wireMock Rule.stubFor(get(urlEqualTo("/oauth/access_token"))64 wireMockServer.stubFor(get(urlEqualTo("/oauth/access_token")) 68 65 .willReturn(aResponse().withStatus(200).withBody(String.join("&", 69 66 "oauth_token=eGMGmosXuiChRntxUGuwRKV6KyVDF0OWScdGhbqX", … … 71 68 72 69 OAuthToken accessToken = client.getAccessToken(null); 73 assertEquals(" accessToken.key", "eGMGmosXuiChRntxUGuwRKV6KyVDF0OWScdGhbqX", accessToken.getKey());74 assertEquals(" accessToken.secret", "nsBUeNor7tPh3SHr5lLaGsGDUD2PYMV1TinL4qUB", accessToken.getSecret());70 assertEquals("eGMGmosXuiChRntxUGuwRKV6KyVDF0OWScdGhbqX", accessToken.getKey(), "accessToken.key"); 71 assertEquals("nsBUeNor7tPh3SHr5lLaGsGDUD2PYMV1TinL4qUB", accessToken.getSecret(), "accessToken.secret"); 75 72 } 76 73 … … 82 79 */ 83 80 @Test 84 publicvoid testCookieHandlingMock() throws Exception {85 wireMock Rule.stubFor(get(urlEqualTo("/login?cookie_test=true"))81 void testCookieHandlingMock() throws Exception { 82 wireMockServer.stubFor(get(urlEqualTo("/login?cookie_test=true")) 86 83 .willReturn(aResponse() 87 84 .withStatus(200) … … 90 87 "name=\"authenticity_token\" " + 91 88 "value=\"fzp6CWJhp6Vns09re3s2Tw==\" />"))); 92 final OAuthParameters parameters = OAuthParameters.createDefault(wireMock Rule.url("/api"));89 final OAuthParameters parameters = OAuthParameters.createDefault(wireMockServer.url("/api")); 93 90 final OsmOAuthAuthorizationClient client = new OsmOAuthAuthorizationClient(parameters); 94 91 final OsmOAuthAuthorizationClient.SessionId sessionId = client.fetchOsmWebsiteSessionId(); 95 92 assertNotNull(sessionId); 96 assertEquals(" sessionId.id", "7fe8e2ea36c6b803cb902301b28e0a", sessionId.id);97 assertEquals(" sessionId.token", "fzp6CWJhp6Vns09re3s2Tw==", sessionId.token);98 assertNull( "sessionId.userName", sessionId.userName);93 assertEquals("7fe8e2ea36c6b803cb902301b28e0a", sessionId.id, "sessionId.id"); 94 assertEquals("fzp6CWJhp6Vns09re3s2Tw==", sessionId.token, "sessionId.token"); 95 assertNull(sessionId.userName, "sessionId.userName"); 99 96 } 100 97 … … 106 103 */ 107 104 @Test 108 publicvoid testCookieHandlingCookieManager() throws Exception {105 void testCookieHandlingCookieManager() throws Exception { 109 106 // emulate Java Web Start behaviour 110 107 // see https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/accessingCookies.html -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTaskTest.java
r17194 r18106 5 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;8 7 import static org.hamcrest.CoreMatchers.containsString; 9 8 import static org.hamcrest.MatcherAssert.assertThat; 10 import static org.junit.Assert.assertFalse; 11 import static org.junit.Assert.assertTrue; 9 import static org.junit.jupiter.api.Assertions.assertFalse; 10 import static org.junit.jupiter.api.Assertions.assertThrows; 11 import static org.junit.jupiter.api.Assertions.assertTrue; 12 12 13 import javax.swing.JLabel; 13 14 import java.awt.Component; 14 15 15 import javax.swing.JLabel; 16 17 import org.junit.Rule; 18 import org.junit.Test; 19 import org.openstreetmap.josm.TestUtils; 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 16 import org.junit.jupiter.api.Test; 17 import org.junit.jupiter.api.Timeout; 18 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 19 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 20 import org.openstreetmap.josm.testutils.annotations.HTTP; 21 21 import org.openstreetmap.josm.tools.Logging; 22 22 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 24 25 import com.github.tomakehurst.wiremock.junit.WireMockRule; 23 import com.github.tomakehurst.wiremock.WireMockServer; 26 24 27 25 /** 28 26 * Unit tests of {@link ApiUrlTestTask} class. 29 27 */ 30 public class ApiUrlTestTaskTest { 31 32 /** 33 * Setup tests 34 */ 35 @Rule 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 public JOSMTestRules test = new JOSMTestRules().preferences().timeout(30000); 38 28 @Timeout(30) 29 @BasicPreferences 30 @BasicWiremock 31 @HTTP 32 class ApiUrlTestTaskTest { 39 33 /** 40 34 * HTTP mock. 41 35 */ 42 @ Rule43 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));36 @BasicWiremock 37 WireMockServer wireMockServer; 44 38 45 39 private static final Component PARENT = new JLabel(); … … 48 42 * Unit test of {@link ApiUrlTestTask#ApiUrlTestTask} - null url. 49 43 */ 50 @Test (expected = IllegalArgumentException.class)51 publicvoid testNullApiUrl() {52 new ApiUrlTestTask(PARENT, null);44 @Test 45 void testNullApiUrl() { 46 assertThrows(IllegalArgumentException.class, () -> new ApiUrlTestTask(PARENT, null)); 53 47 } 54 48 … … 57 51 */ 58 52 @Test 59 publicvoid testNominalUrl() {60 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMock Rule.url("/__files/api"));53 void testNominalUrl() { 54 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.url("/__files/api")); 61 55 task.run(); 62 56 assertTrue(task.isSuccess()); … … 67 61 */ 68 62 @Test 69 publicvoid testAlertInvalidUrl() {63 void testAlertInvalidUrl() { 70 64 Logging.clearLastErrorAndWarnings(); 71 65 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "malformed url"); … … 80 74 */ 81 75 @Test 82 publicvoid testUnknownHost() {76 void testUnknownHost() { 83 77 Logging.clearLastErrorAndWarnings(); 84 78 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "http://unknown"); … … 93 87 */ 94 88 @Test 95 publicvoid testAlertInvalidServerResult() {89 void testAlertInvalidServerResult() { 96 90 Logging.clearLastErrorAndWarnings(); 97 wireMock Rule.stubFor(get(urlEqualTo("/does-not-exist/0.6/capabilities"))91 wireMockServer.stubFor(get(urlEqualTo("/does-not-exist/0.6/capabilities")) 98 92 .willReturn(aResponse().withStatus(404))); 99 93 100 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMock Rule.url("/does-not-exist"));94 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.url("/does-not-exist")); 101 95 task.run(); 102 96 assertFalse(task.isSuccess()); … … 109 103 */ 110 104 @Test 111 publicvoid testAlertInvalidCapabilities() {105 void testAlertInvalidCapabilities() { 112 106 Logging.clearLastErrorAndWarnings(); 113 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMock Rule.url("/__files/invalid_api"));107 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockServer.url("/__files/invalid_api")); 114 108 task.run(); 115 109 assertFalse(task.isSuccess()); 116 110 assertThat(Logging.getLastErrorAndWarnings().toString(), containsString( 117 111 "The OSM API server at 'XXX' did not return a valid response.<br>It is likely that 'XXX' is not an OSM API server." 118 .replace("XXX", wireMock Rule.url("/__files/invalid_api"))));112 .replace("XXX", wireMockServer.url("/__files/invalid_api")))); 119 113 } 120 114 } -
trunk/test/unit/org/openstreetmap/josm/io/OsmServerHistoryReaderTest.java
r17903 r18106 2 2 package org.openstreetmap.josm.io; 3 3 4 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 5 import static org.junit.Assert.assertEquals; 4 import static org.junit.jupiter.api.Assertions.assertEquals; 6 5 7 import org.junit.Before; 8 import org.junit.Rule; 9 import org.junit.Test; 10 import org.openstreetmap.josm.JOSMFixture; 11 import org.openstreetmap.josm.TestUtils; 6 import java.time.Instant; 7 8 import org.junit.jupiter.api.BeforeEach; 9 import org.junit.jupiter.api.Test; 12 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 13 11 import org.openstreetmap.josm.data.osm.history.History; … … 15 13 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 16 14 import org.openstreetmap.josm.spi.preferences.Config; 15 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 16 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 17 import org.openstreetmap.josm.testutils.annotations.HTTP; 17 18 18 import com.github.tomakehurst.wiremock.junit.WireMockRule; 19 20 import java.time.Instant; 19 import com.github.tomakehurst.wiremock.WireMockServer; 21 20 22 21 /** 23 22 * Unit tests of {@link OsmServerHistoryReader} class. 24 23 */ 25 public class OsmServerHistoryReaderTest { 26 24 @BasicPreferences 25 @BasicWiremock 26 @HTTP 27 class OsmServerHistoryReaderTest { 27 28 /** 28 29 * HTTP mock. 29 30 */ 30 @ Rule31 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));31 @BasicWiremock 32 WireMockServer wireMockServer; 32 33 33 34 /** 34 35 * Setup tests. 35 36 */ 36 @Before 37 public void setUp() { 38 JOSMFixture.createUnitTestFixture().init(); 39 Config.getPref().put("osm-server.url", wireMockRule.url("/__files/api")); 37 @BeforeEach 38 void setUp() { 39 Config.getPref().put("osm-server.url", wireMockServer.url("/__files/api")); 40 40 } 41 41 … … 45 45 */ 46 46 @Test 47 publicvoid testNode() throws OsmTransferException {47 void testNode() throws OsmTransferException { 48 48 OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.NODE, 266187); 49 49 HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE); … … 60 60 */ 61 61 @Test 62 publicvoid testWay() throws OsmTransferException {62 void testWay() throws OsmTransferException { 63 63 OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.WAY, 3058844); 64 64 HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE); … … 80 80 */ 81 81 @Test 82 publicvoid testRelation() throws OsmTransferException {82 void testRelation() throws OsmTransferException { 83 83 OsmServerHistoryReader reader = new OsmServerHistoryReader(OsmPrimitiveType.RELATION, 49); 84 84 HistoryDataSet ds = reader.parseHistory(NullProgressMonitor.INSTANCE); -
trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java
r17988 r18106 5 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 8 import static org.junit.Assert.assertEquals; 9 import static org.junit.Assert.assertNotNull; 10 import static org.junit.Assert.assertNull; 11 import static org.junit.Assert.assertTrue; 7 import static org.junit.jupiter.api.Assertions.assertEquals; 8 import static org.junit.jupiter.api.Assertions.assertNotNull; 9 import static org.junit.jupiter.api.Assertions.assertNull; 10 import static org.junit.jupiter.api.Assertions.assertTrue; 12 11 13 12 import java.io.StringReader; … … 15 14 import java.util.regex.Matcher; 16 15 17 import org.junit.Before; 18 import org.junit.Rule; 19 import org.junit.Test; 20 import org.openstreetmap.josm.TestUtils; 16 import org.junit.jupiter.api.BeforeEach; 17 import org.junit.jupiter.api.Test; 21 18 import org.openstreetmap.josm.data.Bounds; 22 19 import org.openstreetmap.josm.io.OverpassDownloadReader.OverpassOutputFormat; 23 import org.openstreetmap.josm.testutils.JOSMTestRules; 20 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 21 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 22 import org.openstreetmap.josm.testutils.annotations.HTTP; 24 23 import org.openstreetmap.josm.tools.SearchCompilerQueryWizard; 25 24 import org.openstreetmap.josm.tools.Utils; 26 25 import org.openstreetmap.josm.tools.date.DateUtils; 27 26 28 import com.github.tomakehurst.wiremock.junit.WireMockRule; 29 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 27 import com.github.tomakehurst.wiremock.WireMockServer; 31 28 32 29 /** 33 30 * Unit tests of {@link OverpassDownloadReader} class. 34 31 */ 35 public class OverpassDownloadReaderTest { 36 37 /** 38 * Base test environment is enough 39 */ 40 @Rule 41 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 42 public JOSMTestRules test = new JOSMTestRules().preferences(); 43 32 @BasicWiremock 33 @BasicPreferences 34 @HTTP 35 class OverpassDownloadReaderTest { 44 36 /** 45 37 * HTTP mock. 46 38 */ 47 @ Rule48 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot()));39 @BasicWiremock 40 WireMockServer wireMockServer; 49 41 50 42 private static final String NOMINATIM_URL_PATH = "/search?format=xml&q="; … … 53 45 * Setup test. 54 46 */ 55 @Before 47 @BeforeEach 56 48 public void setUp() { 57 NameFinder.NOMINATIM_URL_PROP.put(wireMock Rule.url(NOMINATIM_URL_PATH));49 NameFinder.NOMINATIM_URL_PROP.put(wireMockServer.url(NOMINATIM_URL_PATH)); 58 50 } 59 51 … … 70 62 */ 71 63 @Test 72 publicvoid testBbox() {64 void testBbox() { 73 65 final String query = getExpandedQuery("amenity=drinking_water"); 74 66 assertEquals("" + … … 82 74 83 75 private void stubNominatim(String query) { 84 wireMock Rule.stubFor(get(urlEqualTo(NOMINATIM_URL_PATH + query))76 wireMockServer.stubFor(get(urlEqualTo(NOMINATIM_URL_PATH + query)) 85 77 .willReturn(aResponse() 86 78 .withStatus(200) … … 93 85 */ 94 86 @Test 95 publicvoid testDate() {87 void testDate() { 96 88 LocalDateTime from = LocalDateTime.of(2017, 7, 14, 2, 40); 97 89 assertEquals("2016-07-14T02:40:00Z", OverpassDownloadReader.date("1 year", from)); … … 119 111 */ 120 112 @Test 121 publicvoid testDateNewer() {113 void testDateNewer() { 122 114 String query = getExpandedQuery("type:node and newer:3minutes"); 123 115 String statement = query.substring(query.indexOf("node(newer:\"") + 12, query.lastIndexOf("\");")); … … 133 125 */ 134 126 @Test 135 publicvoid testGeocodeArea() {127 void testGeocodeArea() { 136 128 stubNominatim("London"); 137 129 final String query = getExpandedQuery("amenity=drinking_water in London"); … … 150 142 */ 151 143 @Test 152 publicvoid testGeocodeUnknownArea() {144 void testGeocodeUnknownArea() { 153 145 stubNominatim("foo-bar-baz-does-not-exist"); 154 146 final String query = OverpassDownloadReader.expandExtendedQueries("{{geocodeArea:foo-bar-baz-does-not-exist}}"); … … 160 152 */ 161 153 @Test 162 publicvoid testOutputFormatStatement() {154 void testOutputFormatStatement() { 163 155 for (OverpassOutputFormat oof : OverpassOutputFormat.values()) { 164 156 Matcher m = OverpassDownloadReader.OUTPUT_FORMAT_STATEMENT.matcher("[out:"+oof.getDirective()+"]"); … … 182 174 */ 183 175 @Test 184 publicvoid testFixQuery() {176 void testFixQuery() { 185 177 assertNull(OverpassDownloadReader.fixQuery(null)); 186 178 … … 224 216 */ 225 217 @Test 226 publicvoid testSearchName() throws Exception {218 void testSearchName() throws Exception { 227 219 try (StringReader reader = new StringReader(NameFinderTest.SAMPLE)) { 228 220 assertEquals(1942586L, -
trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java
r16412 r18106 2 2 package org.openstreetmap.josm.io.imagery; 3 3 4 import static org.junit. Assert.assertEquals;5 import static org.junit. Assert.assertNull;6 import static org.junit. Assert.assertTrue;4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertNull; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 8 import java.io.IOException; … … 11 11 import java.util.List; 12 12 13 import org.junit. Rule;14 import org.junit. Test;13 import org.junit.jupiter.api.Test; 14 import org.junit.jupiter.api.extension.RegisterExtension; 15 15 import org.openstreetmap.josm.TestUtils; 16 16 import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException; 17 17 import org.openstreetmap.josm.testutils.JOSMTestRules; 18 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 18 19 20 import com.github.tomakehurst.wiremock.WireMockServer; 19 21 import com.github.tomakehurst.wiremock.client.WireMock; 20 import com.github.tomakehurst.wiremock.core.WireMockConfiguration;21 import com.github.tomakehurst.wiremock.junit.WireMockRule;22 22 23 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 26 26 * Unit tests of {@link WMSImagery} class. 27 27 */ 28 public class WMSImageryTest { 28 @BasicWiremock 29 class WMSImageryTest { 29 30 30 31 /** 31 32 * Setup test 32 33 */ 33 @R ule34 @RegisterExtension 34 35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 35 publicJOSMTestRules test = new JOSMTestRules().projection();36 JOSMTestRules test = new JOSMTestRules().projection(); 36 37 37 @ Rule38 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options()39 .dynamicPort()); 38 @BasicWiremock 39 WireMockServer tileServer; 40 40 41 /** 41 42 * Unit test of {@code WMSImagery.WMSGetCapabilitiesException} class 42 43 */ 43 44 @Test 44 publicvoid testWMSGetCapabilitiesException() {45 void testWMSGetCapabilitiesException() { 45 46 Exception cause = new Exception("test"); 46 47 WMSGetCapabilitiesException exc = new WMSGetCapabilitiesException(cause, "bar"); … … 58 59 */ 59 60 @Test 60 publicvoid testTicket15730() throws IOException, WMSGetCapabilitiesException {61 void testTicket15730() throws IOException, WMSGetCapabilitiesException { 61 62 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody( 62 63 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataDir(15730), "capabilities.xml")) … … 69 70 70 71 @Test 71 publicvoid testNestedLayers() throws Exception {72 void testNestedLayers() throws Exception { 72 73 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody( 73 74 Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/mapa-um-warszawa-pl.xml"))))); … … 84 85 */ 85 86 @Test 86 publicvoid testTicket16248() throws IOException, WMSGetCapabilitiesException {87 void testTicket16248() throws IOException, WMSGetCapabilitiesException { 87 88 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml"))); 88 89 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities))); … … 101 102 */ 102 103 @Test 103 publicvoid testTicket19193() throws IOException, WMSGetCapabilitiesException {104 void testTicket19193() throws IOException, WMSGetCapabilitiesException { 104 105 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(19193, "capabilities.xml"))); 105 106 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities))); … … 120 121 */ 121 122 @Test 122 publicvoid testTicket16333() throws IOException, WMSGetCapabilitiesException {123 void testTicket16333() throws IOException, WMSGetCapabilitiesException { 123 124 tileServer.stubFor( 124 125 WireMock.get(WireMock.anyUrl()) … … 129 130 WMSImagery wms = new WMSImagery(tileServer.url("any")); 130 131 assertEquals("https://duinoord.xs4all.nl/geoserver/ows?SERVICE=WMS&", wms.buildRootUrl()); 131 assert Equals(null,wms.getLayers().get(0).getName());132 assertNull(wms.getLayers().get(0).getName()); 132 133 assertEquals("", wms.getLayers().get(0).getTitle()); 133 134 … … 137 138 138 139 @Test 139 publicvoid testForTitleWithinAttribution_ticket16940() throws IOException, WMSGetCapabilitiesException {140 void testForTitleWithinAttribution_ticket16940() throws IOException, WMSGetCapabilitiesException { 140 141 tileServer.stubFor( 141 142 WireMock.get(WireMock.anyUrl()) … … 148 149 } 149 150 } 150 -
trunk/test/unit/org/openstreetmap/josm/testutils/annotations/AnnotationUtils.java
r18051 r18106 17 17 * @since 18037 18 18 */ 19 final class AnnotationUtils {19 public final class AnnotationUtils { 20 20 private AnnotationUtils() { 21 21 // Utils class -
trunk/test/unit/org/openstreetmap/josm/tools/bugreport/BugReportSenderTest.java
r17195 r18106 8 8 import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; 9 9 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 10 import static com.github.tomakehurst.wiremock.client.WireMock.verify; 11 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 12 import static org.junit.Assert.assertEquals; 13 import static org.junit.Assert.assertFalse; 14 import static org.junit.Assert.assertNotNull; 15 import static org.junit.Assert.assertNull; 10 import static org.junit.jupiter.api.Assertions.assertEquals; 11 import static org.junit.jupiter.api.Assertions.assertFalse; 12 import static org.junit.jupiter.api.Assertions.assertNotNull; 13 import static org.junit.jupiter.api.Assertions.assertNull; 16 14 17 15 import java.net.URI; 18 16 import java.util.List; 19 17 20 import org.junit.Before; 21 import org.junit.Rule; 22 import org.junit.Test; 23 import org.openstreetmap.josm.JOSMFixture; 18 import org.junit.jupiter.api.Test; 24 19 import org.openstreetmap.josm.actions.ShowStatusReportAction; 25 20 import org.openstreetmap.josm.spi.preferences.Config; 21 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 22 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 23 import org.openstreetmap.josm.testutils.annotations.HTTP; 26 24 import org.openstreetmap.josm.testutils.mockers.OpenBrowserMocker; 27 25 28 import com.github.tomakehurst.wiremock. junit.WireMockRule;26 import com.github.tomakehurst.wiremock.WireMockServer; 29 27 30 28 /** 31 29 * Unit tests of {@link BugReportSender} class. 32 30 */ 33 public class BugReportSenderTest { 34 31 @BasicPreferences 32 @BasicWiremock 33 @HTTP 34 class BugReportSenderTest { 35 35 /** 36 * Setup tests.36 * HTTP mock 37 37 */ 38 @Before 39 public void setUp() { 40 JOSMFixture.createUnitTestFixture().init(); 41 } 42 43 /** 44 * HTTP mock. 45 */ 46 @Rule 47 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); 38 @BasicWiremock 39 WireMockServer wireMockServer; 48 40 49 41 /** … … 52 44 */ 53 45 @Test 54 publicvoid testBugReportSender() throws InterruptedException {55 Config.getPref().put("josm.url", wireMock Rule.baseUrl());56 wireMock Rule.stubFor(post(urlEqualTo("/josmticket"))46 void testBugReportSender() throws InterruptedException { 47 Config.getPref().put("josm.url", wireMockServer.baseUrl()); 48 wireMockServer.stubFor(post(urlEqualTo("/josmticket")) 57 49 .willReturn(aResponse() 58 50 .withStatus(200) … … 74 66 assertFalse(sender.isAlive()); 75 67 assertNull(sender.getErrorMessage(), sender.getErrorMessage()); 76 verify(exactly(1), postRequestedFor(urlEqualTo("/josmticket")).withRequestBody(containing("pdata=")));68 wireMockServer.verify(exactly(1), postRequestedFor(urlEqualTo("/josmticket")).withRequestBody(containing("pdata="))); 77 69 78 70 List<URI> calledURIs = OpenBrowserMocker.getCalledURIs(); 79 71 assertEquals(1, calledURIs.size()); 80 assertEquals(wireMock Rule.url("/josmticket?pdata_stored=6bccff5c0417217bfbbe5fff"), calledURIs.get(0).toString());72 assertEquals(wireMockServer.url("/josmticket?pdata_stored=6bccff5c0417217bfbbe5fff"), calledURIs.get(0).toString()); 81 73 } 82 74 }
Note:
See TracChangeset
for help on using the changeset viewer.