Changeset 9488 in josm for trunk/test/unit/org/openstreetmap


Ignore:
Timestamp:
2016-01-16T15:53:14+01:00 (8 years ago)
Author:
Don-vip
Message:

fix unit test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java

    r9479 r9488  
    77import java.net.HttpURLConnection;
    88import java.net.SocketException;
     9import java.net.URL;
    910import java.net.UnknownHostException;
    1011
     
    1617import org.openstreetmap.josm.io.MissingOAuthAccessTokenException;
    1718import org.openstreetmap.josm.io.OfflineAccessException;
     19import org.openstreetmap.josm.io.OsmApi;
    1820import org.openstreetmap.josm.io.OsmApiException;
    1921import org.openstreetmap.josm.io.OsmApiInitializationException;
     
    2628public class ExceptionUtilTest {
    2729
    28     private static String url;
     30    private static String baseUrl;
     31    private static String serverUrl;
    2932    private static String host;
    3033    private static String user;
     
    3235    /**
    3336     * Setup test.
     37     * @throws Exception in case of error
    3438     */
    3539    @BeforeClass
    36     public static void setUp() {
     40    public static void setUp() throws Exception {
    3741        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();
    4047        user = CredentialsManager.getInstance().getUsername();
    4148    }
     
    4653    @Test
    4754    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>",
    4956                ExceptionUtil.explainBadRequest(new OsmApiException("")));
    5057
    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>"+
    5259                "Error message(untranslated): header</html>",
    5360                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "")));
    5461
    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>"+
    5663                "Error message(untranslated): header</html>",
    5764                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", "invalid_url")));
     
    5966        assertEquals("<html>The OSM server '"+host+"' reported a bad request.<br><br>"+
    6067                "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>"+
    6471                "The area you tried to download is too big or your request was too large.<br>"+
    6572                "Either request a smaller area or use an export file provided by the OSM community.</html>",
    6673                ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "The maximum bbox", "")));
    6774
    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>"+
    6976                "The area you tried to download is too big or your request was too large.<br>"+
    7077                "Either request a smaller area or use an export file provided by the OSM community.</html>",
     
    7784    @Test
    7885    public void testExplainBandwidthLimitExceeded() {
    79         assertEquals("<html>Communication with the OSM server '"+url+"'failed. "+
     86        assertEquals("<html>Communication with the OSM server '"+baseUrl+"'failed. "+
    8087                "The server replied<br>the following error code and the following error message:<br>"+
    8188                "<strong>Error code:<strong> 0<br><strong>Error message (untranslated)</strong>: no error message available</html>",
     
    100107    @Test
    101108    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>",
    103110                ExceptionUtil.explainClientTimeout(new OsmApiException("")));
    104111    }
     
    160167                ExceptionUtil.explainFailedOAuthAuthorisation(new OsmApiException("")));
    161168        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>"+
    163170                "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)));
    165172    }
    166173
     
    190197    @Test
    191198    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>"+
    193200                "the following error code and the following error message:<br><strong>Error code:<strong> 0<br>"+
    194201                "<strong>Error message (untranslated)</strong>: no error message available</html>",
    195202                ExceptionUtil.explainGenericOsmApiException(new OsmApiException("")));
    196203
    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>"+
    198205                "the following error code and the following error message:<br><strong>Error code:<strong> 500<br>"+
    199206                "<strong>Error message (untranslated)</strong>: header</html>",
    200207                ExceptionUtil.explainGenericOsmApiException(new OsmApiException(HttpURLConnection.HTTP_INTERNAL_ERROR, "header", null)));
    201208
    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>"+
    203210                "the following error code and the following error message:<br><strong>Error code:<strong> 500<br>"+
    204211                "<strong>Error message (untranslated)</strong>: body</html>",
     
    223230    @Test
    224231    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>"+
    226233                "This is most likely a temporary problem. Please try again later.</html>",
    227234                ExceptionUtil.explainInternalServerError(new OsmApiException("")));
     
    258265    @Test
    259266    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>"+
    261268                "due to a problem with transferring data.<br>Details (untranslated): null</html>",
    262269                ExceptionUtil.explainNestedIOException(new OsmApiException("")));
    263270
    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>"+
    265272                "due to a problem with transferring data.<br>Details (untranslated): test</html>",
    266273                ExceptionUtil.explainNestedIOException(new OsmApiException(new IOException("test"))));
     
    272279    @Test
    273280    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>"+
    275282                "Please check your internet connection.</html>",
    276283                ExceptionUtil.explainNestedSocketException(new OsmApiException("")));
     
    282289    @Test
    283290    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>"+
    285292                "Host name '"+host+"' could not be resolved. <br>"+
    286293                "Please check the API URL in your preferences and your internet connection.</html>",
     
    293300    @Test
    294301    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>"+
    296303                "you tried to read, update, or delete. Either the respective object<br>"+
    297304                "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>",
    299306                ExceptionUtil.explainNotFound(new OsmApiException("")));
    300307    }
     
    316323    @Test
    317324    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>"+
    319326                "Check the server URL in your preferences and your internet connection.</html>",
    320327                ExceptionUtil.explainOsmApiInitializationException(new OsmApiInitializationException("")));
     
    326333    @Test
    327334    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>"+
    329336                "for security reasons. This is most likely because you are running<br>"+
    330337                "in an applet and because you did not load your applet from '"+host+"'.</html>",
    331338                ExceptionUtil.explainOsmTransferException(new OsmApiException(new SecurityException("test"))));
    332339
    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>"+
    334341                "Please check your internet connection.</html>",
    335342                ExceptionUtil.explainOsmTransferException(new OsmApiException(new SocketException("test"))));
    336343
    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>"+
    338345                "Host name '"+host+"' could not be resolved. <br>"+
    339346                "Please check the API URL in your preferences and your internet connection.</html>",
    340347                ExceptionUtil.explainOsmTransferException(new OsmApiException(new UnknownHostException("test"))));
    341348
    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>"+
    343350                "due to a problem with transferring data.<br>Details (untranslated): test</html>",
    344351                ExceptionUtil.explainOsmTransferException(new OsmApiException(new IOException("test"))));
    345352
    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>"+
    347354                "Check the server URL in your preferences and your internet connection.</html>",
    348355                ExceptionUtil.explainOsmTransferException(new OsmApiInitializationException("")));
     
    361368                ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_GONE, "", "")));
    362369
    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>"+
    364371                "This is most likely a temporary problem. Please try again later.</html>",
    365372                ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_INTERNAL_ERROR, "", "")));
    366373
    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>",
    368375                ExceptionUtil.explainOsmTransferException(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "", "")));
    369376
    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>"+
    371378                "the following error code and the following error message:<br><strong>Error code:<strong> 509<br>"+
    372379                "<strong>Error message (untranslated)</strong>: </html>",
Note: See TracChangeset for help on using the changeset viewer.