Changeset 14551 in josm for trunk/test/unit
- Timestamp:
- 2018-12-11T00:24:50+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14550 r14551 2 2 package org.openstreetmap.josm.gui.preferences.imagery; 3 3 4 import static org.junit.Assert.assertFalse; 4 5 import static org.junit.Assert.assertTrue; 5 6 … … 63 64 public class ImageryPreferenceTestIT { 64 65 66 private static final LatLon GREENWICH = new LatLon(51.47810, -0.00170); 67 private static final int DEFAULT_ZOOM = 12; 68 65 69 /** 66 70 * Setup rule … … 133 137 } 134 138 135 private voidcheckTileUrl(ImageryInfo info, AbstractTileSource tileSource, ICoordinate center, int zoom)139 private boolean checkTileUrl(ImageryInfo info, AbstractTileSource tileSource, ICoordinate center, int zoom) 136 140 throws IOException { 137 141 TileXY xy = tileSource.latLonToTileXY(center, zoom); … … 142 146 try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) { 143 147 if (ImageIO.read(bais) == null) { 144 addImageError(info, url, data, "did not return an image");148 addImageError(info, url, data, zoom, "did not return an image"); 145 149 } 146 150 } catch (IOException e) { 147 addImageError(info, url, data, e.toString());151 addImageError(info, url, data, zoom, e.toString()); 148 152 Logging.trace(e); 149 153 } 150 154 }); 151 return; 155 // Determines if this is a success (no error message with current zoom marker) 156 return errors.getOrDefault(info.getCountryCode(), Collections.emptyMap()) 157 .getOrDefault(info, Collections.emptyList()) 158 .stream().noneMatch(e -> e.contains(zoomMarker(zoom))); 152 159 } catch (IOException e) { 153 160 // Try up to three times max to allow Bing source to initialize itself … … 164 171 } 165 172 } 166 } 167 168 private void addImageError(ImageryInfo info, String url, byte[] data, String defaultMessage) { 173 return false; 174 } 175 176 private static String zoomMarker(int zoom) { 177 return " -> zoom " + zoom + " -> "; 178 } 179 180 private void addImageError(ImageryInfo info, String url, byte[] data, int zoom, String defaultMessage) { 169 181 // Check if we have received an error message 170 182 String error = helper.detectErrorMessage(new String(data, StandardCharsets.UTF_8)); 171 addError(info, url + " -> "+ (error != null ? error.split("\\n")[0] : defaultMessage));183 addError(info, url + zoomMarker(zoom) + (error != null ? error.split("\\n")[0] : defaultMessage)); 172 184 } 173 185 … … 241 253 ImageryBounds bounds = info.getBounds(); 242 254 // Some imagery sources do not define tiles at (0,0). So pickup Greenwich Royal Observatory for global sources 243 ICoordinate center = CoordinateConversion.llToCoor(bounds != null ? getCenter(bounds) : new LatLon(51.47810, -0.00170));255 ICoordinate center = CoordinateConversion.llToCoor(bounds != null ? getCenter(bounds) : GREENWICH); 244 256 AbstractTileSource tileSource = getTileSource(info); 245 checkTileUrl(info, tileSource, center, info.getMinZoom()); 257 // test min zoom and try to detect the correct value in case of error 258 int maxZoom = info.getMaxZoom() > 0 ? Math.min(DEFAULT_ZOOM, info.getMaxZoom()) : DEFAULT_ZOOM; 259 for (int zoom = info.getMinZoom(); zoom < maxZoom; zoom++) { 260 if (checkTileUrl(info, tileSource, center, zoom)) { 261 break; 262 } 263 } 246 264 // checking max zoom for real is complex, see https://josm.openstreetmap.de/ticket/16073#comment:27 247 265 if (info.getMaxZoom() > 0 && info.getImageryType() != ImageryType.SCANEX) { 248 checkTileUrl(info, tileSource, center, Utils.clamp( 12, info.getMinZoom() + 1, info.getMaxZoom()));266 checkTileUrl(info, tileSource, center, Utils.clamp(DEFAULT_ZOOM, info.getMinZoom() + 1, info.getMaxZoom())); 249 267 } 250 268 } catch (IOException | RuntimeException | WMSGetCapabilitiesException | WMTSGetCapabilitiesException e) { … … 314 332 assertTrue(errors.toString().replaceAll("\\}, ", "\n\\}, ").replaceAll(", ImageryInfo\\{", "\n ,ImageryInfo\\{"), 315 333 errors.isEmpty()); 334 assertFalse(workingURLs.isEmpty()); 316 335 } 317 336 }
Note:
See TracChangeset
for help on using the changeset viewer.