Changeset 13742 in josm for trunk/test/unit
- Timestamp:
- 2018-05-13T09:15:34+02:00 (7 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r13733 r13742 411 411 ); 412 412 } 413 413 414 /** 414 415 * Renders Temporal to RFC 1123 Date Time 415 * @param time 416 * @param time to convert 416 417 * @return string representation according to RFC1123 of time 417 418 */ … … 422 423 /** 423 424 * Renders java time stamp to RFC 1123 Date Time 424 * @param time 425 * @param time java timestamp (milliseconds from Epoch) 425 426 * @return string representation according to RFC1123 of time 426 427 */ … … 428 429 return getHTTPDate(Instant.ofEpochMilli(time)); 429 430 } 430 431 432 431 } -
trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java
r13733 r13742 47 47 private String key; 48 48 49 TestCachedTileLoaderJob(String url, String key) 49 TestCachedTileLoaderJob(String url, String key) { 50 50 this(url, key, (int) TimeUnit.DAYS.toSeconds(1)); 51 51 } 52 52 53 TestCachedTileLoaderJob(String url, String key, int minimumExpiry) 53 TestCachedTileLoaderJob(String url, String key, int minimumExpiry) { 54 54 super(getCache(), new TileJobOptions(30000, 30000, null, minimumExpiry)); 55 55 … … 57 57 this.key = key; 58 58 } 59 60 59 61 60 @Override … … 183 182 184 183 /** 185 * That no requ st is made when entry is in cache and force == false186 * @throws IOException 184 * That no request is made when entry is in cache and force == false 185 * @throws IOException exception 187 186 */ 188 187 @Test … … 205 204 /** 206 205 * that request is made, when object is in cache, but force mode is used 207 * @throws IOException 206 * @throws IOException exception 208 207 */ 209 208 @Test 210 209 public void testRequestMadeWhenEntryInCacheAndForce() throws IOException { 211 210 ICacheAccess<String, CacheEntry> cache = getCache(); 212 long expires = 211 long expires = TimeUnit.DAYS.toMillis(1); 213 212 long testStart = System.currentTimeMillis(); 214 213 cache.put("test", … … 227 226 * Mock returns no cache-control / expires headers 228 227 * Expire time should be set to DEFAULT_EXPIRE_TIME 229 * @throws IOException 228 * @throws IOException exception 230 229 */ 231 230 @Test … … 247 246 listener.attributes.getExpirationTime() >= testStart + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME); 248 247 249 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + " which is not less than " + 248 assertTrue("Cache entry expiration is " + 249 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 250 " which is not less than " + 250 251 JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME + " (DEFAULT_EXPIRE_TIME)", 251 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME); 252 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME 253 ); 252 254 253 255 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); … … 257 259 * Mock returns expires headers, but Cache-Control 258 260 * Expire time should be set to max-age 259 * @throws IOException 261 * @throws IOException exception 260 262 */ 261 263 @Test 262 264 public void testSettingExpireByMaxAge() throws IOException { 263 265 long testStart = System.currentTimeMillis(); 264 long expires = 266 long expires = TimeUnit.DAYS.toSeconds(1); 265 267 tileServer.stubFor( 266 268 WireMock.get(WireMock.urlEqualTo("/test")) … … 279 281 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(expires)); 280 282 281 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + " which is not less than " + 283 assertTrue("Cache entry expiration is " + 284 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 285 " which is not less than " + 282 286 TimeUnit.SECONDS.toMillis(expires) + " (max-age)", 283 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expires)); 287 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(expires) 288 ); 284 289 285 290 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), listener.data); … … 289 294 * mock returns expiration: JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10 290 295 * minimum expire time: JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2 291 * @throws IOException 296 * @throws IOException exception 292 297 */ 293 298 @Test 294 299 public void testSettingMinimumExpiryByMinimumExpiryTimeLessThanDefault() throws IOException { 295 300 long testStart = System.currentTimeMillis(); 296 int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2);301 int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 2); 297 302 298 303 createHeadGetStub(WireMock.urlEqualTo("/test"), (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10), testStart, "eTag", "mock entry"); … … 306 311 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 307 312 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 308 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) ); 309 310 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + " which is not less than " + 313 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)); 314 315 assertTrue("Cache entry expiration is " + 316 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 317 " which is not less than " + 311 318 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 312 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)); 319 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) 320 ); 313 321 } 314 322 … … 316 324 * mock returns expiration: JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10 317 325 * minimum expire time: JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME * 2 318 * @throws IOException 326 * @throws IOException exception 319 327 */ 320 328 … … 322 330 public void testSettingMinimumExpiryByMinimumExpiryTimeGreaterThanDefault() throws IOException { 323 331 long testStart = System.currentTimeMillis(); 324 int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME * 2);332 int minimumExpiryTimeSeconds = (int) (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME * 2); 325 333 326 334 createHeadGetStub(WireMock.urlEqualTo("/test"), (JCSCachedTileLoaderJob.DEFAULT_EXPIRE_TIME / 10), testStart, "eTag", "mock entry"); … … 334 342 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - testStart) + " which is not larger than " + 335 343 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 336 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) ); 337 338 assertTrue("Cache entry expiration is " + (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + " which is not less than " + 344 listener.attributes.getExpirationTime() >= testStart + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)); 345 346 assertTrue("Cache entry expiration is " + 347 (listener.attributes.getExpirationTime() - System.currentTimeMillis()) + 348 " which is not less than " + 339 349 TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) + " (minimumExpireTime)", 340 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds)); 350 listener.attributes.getExpirationTime() <= System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(minimumExpiryTimeSeconds) 351 ); 341 352 } 342 353 343 354 /** 344 355 * Check if verifying cache entries using HEAD requests work properly 345 * @throws IOException 356 * @throws IOException exception 346 357 */ 347 358 @Test … … 385 396 // invalidate entry in cache 386 397 ICacheElement<String, CacheEntry> cacheEntry = cache.getCacheElement("test"); 387 CacheEntryAttributes attributes = (CacheEntryAttributes) cacheEntry.getElementAttributes();398 CacheEntryAttributes attributes = (CacheEntryAttributes) cacheEntry.getElementAttributes(); 388 399 attributes.setExpirationTime(testStart - TimeUnit.DAYS.toMillis(1)); 389 400 cache.put("test", cacheEntry.getVal(), attributes); … … 406 417 /** 407 418 * Check if server returns 304 - it will update cache attributes and not ask again for it 408 * @throws IOException 419 * @throws IOException exception 409 420 */ 410 421 @Test … … 470 481 } 471 482 472 private static TestCachedTileLoaderJob getStatusLoaderJob(int responseCode) 483 private static TestCachedTileLoaderJob getStatusLoaderJob(int responseCode) { 473 484 return new TestCachedTileLoaderJob("http://httpstat.us/" + responseCode, "key_" + responseCode); 474 485 } -
trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java
r13733 r13742 68 68 private String key; 69 69 70 TestCachedTileLoaderJob(TileLoaderListener listener, Tile tile, String key) throws IOException 71 this(listener, tile, key, 72 } 73 74 TestCachedTileLoaderJob(TileLoaderListener listener, Tile tile, String key, int minimumExpiry) throws IOException 70 TestCachedTileLoaderJob(TileLoaderListener listener, Tile tile, String key) throws IOException { 71 this(listener, tile, key, (int) TimeUnit.DAYS.toSeconds(1)); 72 } 73 74 TestCachedTileLoaderJob(TileLoaderListener listener, Tile tile, String key, int minimumExpiry) throws IOException { 75 75 super(listener, tile, getCache(), new TileJobOptions(30000, 30000, null, minimumExpiry), 76 76 (ThreadPoolExecutor) Executors.newFixedThreadPool(1)); … … 104 104 return false; 105 105 } 106 return cacheData.getContent().length > 0; } 106 return cacheData.getContent().length > 0; 107 } 107 108 } 108 109 … … 112 113 private byte[] data; 113 114 114 115 115 @Override 116 116 public synchronized void tileLoadingFinished(Tile tile, boolean success) { … … 129 129 private final String url; 130 130 131 publicMockTileSource(String url) {131 MockTileSource(String url) { 132 132 super(new ImageryInfo("mock")); 133 133 this.url = url; … … 191 191 /** 192 192 * When tile server doesn't return any Expires/Cache-Control headers, expire should be at least MINIMUM_EXPIRES 193 * @throws IOException 193 * @throws IOException exception 194 194 */ 195 195 @Test … … 214 214 /** 215 215 * When tile server doesn't return any Expires/Cache-Control headers, expire should be at least minimumExpires parameter 216 * @throws IOException 216 * @throws IOException exception 217 217 */ 218 218 @Test … … 224 224 * When tile server doesn't return any Expires/Cache-Control headers, expire should be at least minimumExpires parameter, 225 225 * which is larger than MAXIMUM_EXPIRES 226 * @throws IOException 226 * @throws IOException exception 227 227 */ 228 228 … … 251 251 /** 252 252 * When tile server returns Expires header shorter than MINIMUM_EXPIRES, we should cache if for at least MINIMUM_EXPIRES 253 * @throws IOException 253 * @throws IOException exception 254 254 */ 255 255 @Test … … 288 288 job.getAttributes().getExpirationTime() <= duration); 289 289 } 290 291 290 292 291 @Test -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java
r13735 r13742 53 53 "<type>wms_endpoint</type>\n" + 54 54 "<url><![CDATA[" + tileServer.url("/capabilities") + "]]></url>\n" + 55 "<icon>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsSAAALEgHS3X78AAAB5UlEQVQ4y4WTwWsTURDGfy8W1yYmXZOqtGJJFyGw6KF7CEigwYuS0kthrYUi4i0iORS9BU9hQdA/ILcixVBrwENKLz1FUBB0wWOwYFAqxUNYTZq6BfM8yC5d05iBObz3vfnmm3kz4sqDh/zP7szdlG5I+Of1zQ1xFA8xxI4GH2cjg4Cl+UUJcC4SJq6c7FPkKRlIoPQk0+NnuDwxHrhvuYd83+8OVuBlHouE/eDXzW8+/qO9DyHB0vyiVHoy2INSNiPdeg23XuPs3icmIoofPKXGmFJjjEUjgf4EFNi2TT6fJ5FI0Gg0ePrkMRfnbvn41QsJgEAJAQUdbYZyuQxAcvoSpmnydesFAF+cn8f2KUCw/fGt6GgzWJbF706bVCoFwGxyktnk5N8kB79QepL1zQ3xbOulCJWyGbkQHZWlbEZ6JIZhBDI1nQ5Np8P2zi4t9zAwGyNe3QALti11XSedTvsPYrEY73f3Bk+irusAnI6qrNy7z43sNUbFCQC6LYdCoYBbr/k1/2sh690HUalUaH7eIRxXA+6RFItF3HqN6+dP9REIb5lK2Yy0bdsHDMMgl8vRbTkAhOMqlmVhmibLq2ui7xsf1d+IV+0D3zVNw7KsPiXVapXnd2/Lodu4vLomTNMcSvIHY6bDkqJtEqIAAAAASUVORK5CYII=</icon>\n" + 55 "<icon>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsSAAALEgHS3X78AAAB5UlEQVQ4y4WTwWsTURDG" + 56 "fy8W1yYmXZOqtGJJFyGw6KF7CEigwYuS0kthrYUi4i0iORS9BU9hQdA/ILcixVBrwENKLz1FUBB0wWOwYFAqxUNYTZq6BfM8yC5d05iBObz3vfnmm3kz4sqDh/zP" + 57 "7szdlG5I+Of1zQ1xFA8xxI4GH2cjg4Cl+UUJcC4SJq6c7FPkKRlIoPQk0+NnuDwxHrhvuYd83+8OVuBlHouE/eDXzW8+/qO9DyHB0vyiVHoy2INSNiPdeg23XuPs" + 58 "3icmIoofPKXGmFJjjEUjgf4EFNi2TT6fJ5FI0Gg0ePrkMRfnbvn41QsJgEAJAQUdbYZyuQxAcvoSpmnydesFAF+cn8f2KUCw/fGt6GgzWJbF706bVCoFwGxyktnk" + 59 "5N8kB79QepL1zQ3xbOulCJWyGbkQHZWlbEZ6JIZhBDI1nQ5Np8P2zi4t9zAwGyNe3QALti11XSedTvsPYrEY73f3Bk+irusAnI6qrNy7z43sNUbFCQC6LYdCoYBb" + 60 "r/k1/2sh690HUalUaH7eIRxXA+6RFItF3HqN6+dP9REIb5lK2Yy0bdsHDMMgl8vRbTkAhOMqlmVhmibLq2ui7xsf1d+IV+0D3zVNw7KsPiXVapXnd2/Lodu4vLom" + 61 "TNMcSvIHY6bDkqJtEqIAAAAASUVORK5CYII=</icon>\n" + 56 62 "<attribution-text mandatory=\"true\">© Geofabrik GmbH, OpenStreetMap contributors, CC-BY-SA</attribution-text>\n" + 57 63 "<attribution-url>http://tools.geofabrik.de/osmi/</attribution-url>\n" + … … 72 78 WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, Main.getProjection()); 73 79 tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857")); 74 assertEquals("https://tools.geofabrik.de/osmi/views/geometry/wxs?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS& REQUEST=GetMap&"75 + " LAYERS=single_node_in_way&STYLES=default&"80 assertEquals("https://tools.geofabrik.de/osmi/views/geometry/wxs?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&" 81 + "REQUEST=GetMap&LAYERS=single_node_in_way&STYLES=default&" 76 82 + "SRS=EPSG:3857&WIDTH=512&HEIGHT=512&" 77 83 + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108", tileSource.getTileUrl(1, 1, 1)); -
trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
r13735 r13742 46 46 @ClassRule 47 47 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 48 public static JOSMTestRules test = new JOSMTestRules().preferences().platform().projection().timeout((int) TimeUnit.MINUTES.toMillis(5));48 public static JOSMTestRules test = new JOSMTestRules().preferences().platform().projection().timeout((int) TimeUnit.MINUTES.toMillis(5)); 49 49 50 50 @Rule … … 67 67 "wmts/bug13975-multiple-tile-matrices-for-one-layer-projection.xml"); 68 68 69 70 69 private static ImageryInfo getImagery(String path) { 71 70 try { … … 259 258 testSource.initProjection(Main.getProjection()); 260 259 assertEquals( 261 "http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/Basemap_Imagery_2014/default/default028mm/4/2932/2371.jpg", 260 "http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/Basemap_Imagery_2014/default/" 261 + "default028mm/4/2932/2371.jpg", 262 262 testSource.getTileUrl(4, 2371, 2932)); 263 263 verifyTile(new LatLon(45.4601306, -75.7617187), testSource, 2372, 2932, 4); … … 275 275 testSource.initProjection(Main.getProjection()); 276 276 assertEquals( 277 "http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/Basemap_Imagery_2014/default/GoogleMapsCompatible/4/2932/2371.jpg", 277 "http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/Basemap_Imagery_2014/default/" 278 + "GoogleMapsCompatible/4/2932/2371.jpg", 278 279 testSource.getTileUrl(4, 2371, 2932)); 279 280 verifyMercatorTile(testSource, 74, 91, 8); … … 326 327 * Test WMTS dimension. 327 328 * @throws IOException if any I/O error occurs 328 * @throws WMTSGetCapabilitiesException 329 * @throws WMTSGetCapabilitiesException if any error occurs 329 330 */ 330 331 @Test -
trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java
r13735 r13742 86 86 tileServer.stubFor( 87 87 WireMock.get(WireMock.anyUrl()) 88 .willReturn(WireMock.aResponse().withBody(Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml")))))); 88 .willReturn(WireMock.aResponse().withBody( 89 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml"))) 90 )) 91 ); 89 92 WMSImagery wms = new WMSImagery(tileServer.url("any")); 90 93 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k", wms.buildRootUrl()); … … 92 95 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25kFORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&" 93 96 + "LAYERS=wms.hgis.cartomatic.pl&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}", 94 wms.buildGetMapUrl(wms.getLayers(), (List<String>) null, true));97 wms.buildGetMapUrl(wms.getLayers(), (List<String>) null, true)); 95 98 } 96 99 }
Note:
See TracChangeset
for help on using the changeset viewer.