Changeset 9488 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2016-01-16T15:53:14+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java
r9479 r9488 7 7 import java.net.HttpURLConnection; 8 8 import java.net.SocketException; 9 import java.net.URL; 9 10 import java.net.UnknownHostException; 10 11 … … 16 17 import org.openstreetmap.josm.io.MissingOAuthAccessTokenException; 17 18 import org.openstreetmap.josm.io.OfflineAccessException; 19 import org.openstreetmap.josm.io.OsmApi; 18 20 import org.openstreetmap.josm.io.OsmApiException; 19 21 import org.openstreetmap.josm.io.OsmApiInitializationException; … … 26 28 public class ExceptionUtilTest { 27 29 28 private static String url; 30 private static String baseUrl; 31 private static String serverUrl; 29 32 private static String host; 30 33 private static String user; … … 32 35 /** 33 36 * Setup test. 37 * @throws Exception in case of error 34 38 */ 35 39 @BeforeClass 36 public static void setUp() { 40 public static void setUp() throws Exception { 37 41 JOSMFixture.createUnitTestFixture().init(); 38 url = new OsmApiException("").getUrl(); 39 host = url.replace("http://", "").replace("/api/", "").replace("0.6/", ""); 42 OsmApi api = OsmApi.getOsmApi(); 43 api.initialize(null); 44 baseUrl = api.getBaseUrl(); 45 serverUrl = api.getServerUrl(); 46 host = new URL(serverUrl).getHost(); 40 47 user = CredentialsManager.getInstance().getUsername(); 41 48 } … … 46 53 @Test 47 54 public void testExplainBadRequest() { 48 assertEquals("<html>The OSM server '"+ url+"' reported a bad request.<br></html>",55 assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br></html>", 49 56 ExceptionUtil.explainBadRequest(new OsmApiException(""))); 50 57 51 assertEquals("<html>The OSM server '"+ url+"' reported a bad request.<br><br>"+58 assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+ 52 59 "Error message(untranslated): header</html>", 53 60 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", ""))); 54 61 55 assertEquals("<html>The OSM server '"+ url+"' reported a bad request.<br><br>"+62 assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+ 56 63 "Error message(untranslated): header</html>", 57 64 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", "invalid_url"))); … … 59 66 assertEquals("<html>The OSM server '"+host+"' reported a bad request.<br><br>"+ 60 67 "Error message(untranslated): header</html>", 61 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", url)));62 63 assertEquals("<html>The OSM server '"+ url+"' reported a bad request.<br><br>"+68 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", baseUrl))); 69 70 assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+ 64 71 "The area you tried to download is too big or your request was too large.<br>"+ 65 72 "Either request a smaller area or use an export file provided by the OSM community.</html>", 66 73 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "The maximum bbox", ""))); 67 74 68 assertEquals("<html>The OSM server '"+ url+"' reported a bad request.<br><br>"+75 assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+ 69 76 "The area you tried to download is too big or your request was too large.<br>"+ 70 77 "Either request a smaller area or use an export file provided by the OSM community.</html>", … … 77 84 @Test 78 85 public void testExplainBandwidthLimitExceeded() { 79 assertEquals("<html>Communication with the OSM server '"+ url+"'failed. "+86 assertEquals("<html>Communication with the OSM server '"+baseUrl+"'failed. "+ 80 87 "The server replied<br>the following error code and the following error message:<br>"+ 81 88 "<strong>Error code:<strong> 0<br><strong>Error message (untranslated)</strong>: no error message available</html>", … … 100 107 @Test 101 108 public void testExplainClientTimeout() { 102 assertEquals("<html>Communication with the OSM server '"+ url+"' timed out. Please retry later.</html>",109 assertEquals("<html>Communication with the OSM server '"+baseUrl+"' timed out. Please retry later.</html>", 103 110 ExceptionUtil.explainClientTimeout(new OsmApiException(""))); 104 111 } … … 160 167 ExceptionUtil.explainFailedOAuthAuthorisation(new OsmApiException(""))); 161 168 assertEquals("<html>Authorisation at the OSM server with the OAuth token 'null' failed.<br>"+ 162 "The token is not authorised to access the protected resource<br>'"+ url+"'.<br>"+169 "The token is not authorised to access the protected resource<br>'"+baseUrl+"'.<br>"+ 163 170 "Please launch the preferences dialog and retrieve another OAuth token.</html>", 164 ExceptionUtil.explainFailedOAuthAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, "", "", url)));171 ExceptionUtil.explainFailedOAuthAuthorisation(new OsmApiException(HttpURLConnection.HTTP_FORBIDDEN, "", "", baseUrl))); 165 172 } 166 173 … … 190 197 @Test 191 198 public void testExplainGenericOsmApiException() { 192 assertEquals("<html>Communication with the OSM server '"+ url+"'failed. The server replied<br>"+199 assertEquals("<html>Communication with the OSM server '"+baseUrl+"'failed. The server replied<br>"+ 193 200 "the following error code and the following error message:<br><strong>Error code:<strong> 0<br>"+ 194 201 "<strong>Error message (untranslated)</strong>: no error message available</html>", 195 202 ExceptionUtil.explainGenericOsmApiException(new OsmApiException(""))); 196 203 197 assertEquals("<html>Communication with the OSM server '"+ url+"'failed. The server replied<br>"+204 assertEquals("<html>Communication with the OSM server '"+baseUrl+"'failed. The server replied<br>"+ 198 205 "the following error code and the following error message:<br><strong>Error code:<strong> 500<br>"+ 199 206 "<strong>Error message (untranslated)</strong>: header</html>", 200 207 ExceptionUtil.explainGenericOsmApiException(new OsmApiException(HttpURLConnection.HTTP_INTERNAL_ERROR, "header", null))); 201 208 202 assertEquals("<html>Communication with the OSM server '"+ url+"'failed. The server replied<br>"+209 assertEquals("<html>Communication with the OSM server '"+baseUrl+"'failed. The server replied<br>"+ 203 210 "the following error code and the following error message:<br><strong>Error code:<strong> 500<br>"+ 204 211 "<strong>Error message (untranslated)</strong>: body</html>", … … 223 230 @Test 224 231 public void testExplainInternalServerError() { 225 assertEquals("<html>The OSM server<br>'"+ url+"'<br>reported an internal server error.<br>"+232 assertEquals("<html>The OSM server<br>'"+baseUrl+"'<br>reported an internal server error.<br>"+ 226 233 "This is most likely a temporary problem. Please try again later.</html>", 227 234 ExceptionUtil.explainInternalServerError(new OsmApiException(""))); … … 258 265 @Test 259 266 public void testExplainNestedIOException() { 260 assertEquals("<html>Failed to upload data to or download data from<br>'"+ url+"'<br>"+267 assertEquals("<html>Failed to upload data to or download data from<br>'"+baseUrl+"'<br>"+ 261 268 "due to a problem with transferring data.<br>Details (untranslated): null</html>", 262 269 ExceptionUtil.explainNestedIOException(new OsmApiException(""))); 263 270 264 assertEquals("<html>Failed to upload data to or download data from<br>'"+ url+"'<br>"+271 assertEquals("<html>Failed to upload data to or download data from<br>'"+baseUrl+"'<br>"+ 265 272 "due to a problem with transferring data.<br>Details (untranslated): test</html>", 266 273 ExceptionUtil.explainNestedIOException(new OsmApiException(new IOException("test")))); … … 272 279 @Test 273 280 public void testExplainNestedSocketException() { 274 assertEquals("<html>Failed to open a connection to the remote server<br>'"+ url+"'.<br>"+281 assertEquals("<html>Failed to open a connection to the remote server<br>'"+baseUrl+"'.<br>"+ 275 282 "Please check your internet connection.</html>", 276 283 ExceptionUtil.explainNestedSocketException(new OsmApiException(""))); … … 282 289 @Test 283 290 public void testExplainNestedUnknownHostException() { 284 assertEquals("<html>Failed to open a connection to the remote server<br>'"+ url+"'.<br>"+291 assertEquals("<html>Failed to open a connection to the remote server<br>'"+baseUrl+"'.<br>"+ 285 292 "Host name '"+host+"' could not be resolved. <br>"+ 286 293 "Please check the API URL in your preferences and your internet connection.</html>", … … 293 300 @Test 294 301 public void testExplainNotFound() { 295 assertEquals("<html>The OSM server '"+ url+"' does not know about an object<br>"+302 assertEquals("<html>The OSM server '"+baseUrl+"' does not know about an object<br>"+ 296 303 "you tried to read, update, or delete. Either the respective object<br>"+ 297 304 "does not exist on the server or you are using an invalid URL to access<br>"+ 298 "it. Please carefully check the server's address '"+ url+"' for typos.</html>",305 "it. Please carefully check the server's address '"+baseUrl+"' for typos.</html>", 299 306 ExceptionUtil.explainNotFound(new OsmApiException(""))); 300 307 } … … 316 323 @Test 317 324 public void testExplainOsmApiInitializationException() { 318 assertEquals("<html>Failed to initialize communication with the OSM server "+ url.substring(0, url.length()-1)+".<br>"+325 assertEquals("<html>Failed to initialize communication with the OSM server "+serverUrl+".<br>"+ 319 326 "Check the server URL in your preferences and your internet connection.</html>", 320 327 ExceptionUtil.explainOsmApiInitializationException(new OsmApiInitializationException(""))); … … 326 333 @Test 327 334 public void testExplainOsmTransferException() { 328 assertEquals("<html>Failed to open a connection to the remote server<br>'"+ url+"'<br>"+335 assertEquals("<html>Failed to open a connection to the remote server<br>'"+baseUrl+"'<br>"+ 329 336 "for security reasons. This is most likely because you are running<br>"+ 330 337 "in an applet and because you did not load your applet from '"+host+"'.</html>", 331 338 ExceptionUtil.explainOsmTransferException(new OsmApiException(new SecurityException("test")))); 332 339 333 assertEquals("<html>Failed to open a connection to the remote server<br>'"+ url+"'.<br>"+340 assertEquals("<html>Failed to open a connection to the remote server<br>'"+baseUrl+"'.<br>"+ 334 341 "Please check your internet connection.</html>", 335 342 ExceptionUtil.explainOsmTransferException(new OsmApiException(new SocketException("test")))); 336 343 337 assertEquals("<html>Failed to open a connection to the remote server<br>'"+ url+"'.<br>"+344 assertEquals("<html>Failed to open a connection to the remote server<br>'"+baseUrl+"'.<br>"+ 338 345 "Host name '"+host+"' could not be resolved. <br>"+ 339 346 "Please check the API URL in your preferences and your internet connection.</html>", 340 347 ExceptionUtil.explainOsmTransferException(new OsmApiException(new UnknownHostException("test")))); 341 348 342 assertEquals("<html>Failed to upload data to or download data from<br>'"+ url+"'<br>"+349 assertEquals("<html>Failed to upload data to or download data from<br>'"+baseUrl+"'<br>"+ 343 350 "due to a problem with transferring data.<br>Details (untranslated): test</html>", 344 351 ExceptionUtil.explainOsmTransferException(new OsmApiException(new IOException("test")))); 345 352 346 assertEquals("<html>Failed to initialize communication with the OSM server "+ url.substring(0, url.length()-1)+".<br>"+353 assertEquals("<html>Failed to initialize communication with the OSM server "+serverUrl+".<br>"+ 347 354 "Check the server URL in your preferences and your internet connection.</html>", 348 355 ExceptionUtil.explainOsmTransferException(new OsmApiInitializationException(""))); … … 361 368 ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_GONE, "", ""))); 362 369 363 assertEquals("<html>The OSM server<br>'"+ url+"'<br>reported an internal server error.<br>"+370 assertEquals("<html>The OSM server<br>'"+baseUrl+"'<br>reported an internal server error.<br>"+ 364 371 "This is most likely a temporary problem. Please try again later.</html>", 365 372 ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_INTERNAL_ERROR, "", ""))); 366 373 367 assertEquals("<html>The OSM server '"+ url+"' reported a bad request.<br><br>Error message(untranslated): </html>",374 assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>Error message(untranslated): </html>", 368 375 ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "", ""))); 369 376 370 assertEquals("<html>Communication with the OSM server '"+ url+"'failed. The server replied<br>"+377 assertEquals("<html>Communication with the OSM server '"+baseUrl+"'failed. The server replied<br>"+ 371 378 "the following error code and the following error message:<br><strong>Error code:<strong> 509<br>"+ 372 379 "<strong>Error message (untranslated)</strong>: </html>",
Note:
See TracChangeset
for help on using the changeset viewer.