Changeset 14535 in josm for trunk/test/unit/org
- Timestamp:
- 2018-12-09T20:06:53+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java
r14533 r14535 4 4 import static org.junit.Assert.assertTrue; 5 5 6 import java.io.ByteArrayInputStream; 6 7 import java.io.IOException; 7 8 import java.net.URL; 9 import java.nio.charset.StandardCharsets; 8 10 import java.util.ArrayList; 9 11 import java.util.Collections; … … 15 17 import java.util.concurrent.TimeUnit; 16 18 19 import javax.imageio.ImageIO; 20 21 import org.apache.commons.jcs.access.CacheAccess; 17 22 import org.junit.Before; 18 23 import org.junit.Rule; … … 34 39 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 35 40 import org.openstreetmap.josm.data.imagery.Shape; 41 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoaderJob; 36 42 import org.openstreetmap.josm.data.imagery.TemplatedWMSTileSource; 43 import org.openstreetmap.josm.data.imagery.TileJobOptions; 37 44 import org.openstreetmap.josm.data.imagery.WMSEndpointTileSource; 38 45 import org.openstreetmap.josm.data.imagery.WMTSTileSource; … … 64 71 private final Set<String> workingURLs = Collections.synchronizedSet(new HashSet<>()); 65 72 73 private TMSCachedTileLoaderJob helper; 66 74 private List<String> ignoredErrors; 67 75 … … 72 80 @Before 73 81 public void before() throws IOException { 82 helper = new TMSCachedTileLoaderJob(null, null, new CacheAccess<>(null), new TileJobOptions(0, 0, null, 0), null); 74 83 ignoredErrors = TestUtils.getIgnoredErrorMessages(ImageryPreferenceTestIT.class); 75 84 } … … 82 91 } 83 92 84 private voidcheckUrl(ImageryInfo info, String url) {93 private byte[] checkUrl(ImageryInfo info, String url) { 85 94 if (url != null && !url.isEmpty() && !workingURLs.contains(url)) { 86 95 try { … … 97 106 workingURLs.add(url); 98 107 } 99 response.disconnect(); 108 try { 109 return Utils.readBytesFromStream(response.getContent()); 110 } finally { 111 response.disconnect(); 112 } 100 113 } catch (IOException e) { 101 114 addError(info, url + " -> " + e); 102 115 } 116 } 117 return new byte[0]; 118 } 119 120 private void checkLinkUrl(ImageryInfo info, String url) { 121 if (url != null && checkUrl(info, url).length == 0) { 122 addError(info, url + " -> returned empty contents"); 103 123 } 104 124 } … … 109 129 for (int i = 0; i < 3; i++) { 110 130 try { 111 checkUrl(info, tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex())); 131 String url = tileSource.getTileUrl(zoom, xy.getXIndex(), xy.getYIndex()); 132 byte[] data = checkUrl(info, url); 133 try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) { 134 if (ImageIO.read(bais) == null) { 135 addImageError(info, url, data, "did not return an image"); 136 } 137 } catch (IOException e) { 138 addImageError(info, url, data, e.toString()); 139 Logging.trace(e); 140 } 112 141 return; 113 142 } catch (IOException e) { … … 125 154 } 126 155 } 156 } 157 158 private void addImageError(ImageryInfo info, String url, byte[] data, String defaultMessage) { 159 // Check if we have received an error message 160 String error = helper.detectErrorMessage(new String(data, StandardCharsets.UTF_8)); 161 addError(info, url + " -> " + (error != null ? error : defaultMessage)); 127 162 } 128 163 … … 184 219 } 185 220 186 check Url(info, info.getAttributionImageURL());187 check Url(info, info.getAttributionLinkURL());221 checkLinkUrl(info, info.getAttributionImageURL()); 222 checkLinkUrl(info, info.getAttributionLinkURL()); 188 223 String eula = info.getEulaAcceptanceRequired(); 189 224 if (eula != null) { 190 check Url(info, eula.replaceAll("\\{lang\\}", ""));191 } 192 check Url(info, info.getPermissionReferenceURL());193 check Url(info, info.getTermsOfUseURL());225 checkLinkUrl(info, eula.replaceAll("\\{lang\\}", "")); 226 } 227 checkLinkUrl(info, info.getPermissionReferenceURL()); 228 checkLinkUrl(info, info.getTermsOfUseURL()); 194 229 195 230 try {
Note:
See TracChangeset
for help on using the changeset viewer.