Changeset 17152 in josm


Ignore:
Timestamp:
2020-10-10T23:24:23+02:00 (4 years ago)
Author:
simon04
Message:

Revert "HttpClientTest: migrate to httpbingo.org"

This reverts commit r16837. httpbin.org is up and running again. Fixes broken HttpClientTest tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    r16837 r17152  
    3636
    3737/**
    38  * Tests the {@link HttpClient} using the webservice <a href="https://httpbingo.org/">https://httpbingo.org/</a>.
     38 * Tests the {@link HttpClient} using the webservice <a href="https://httpbin.org/">https://httpbin.org/</a>.
    3939 */
    4040public class HttpClientTest {
     
    8383    @Test
    8484    public void testConstructorGetterSetter() throws IOException {
    85         final HttpClient client = HttpClient.create(new URL("https://httpbingo.org/"));
    86         assertThat(client.getURL(), is(new URL("https://httpbingo.org/")));
     85        final HttpClient client = HttpClient.create(new URL("https://httpbin.org/"));
     86        assertThat(client.getURL(), is(new URL("https://httpbin.org/")));
    8787        assertThat(client.getRequestMethod(), is("GET"));
    8888        assertThat(client.getRequestHeader("Accept"), is("*/*"));
     
    104104    @Test
    105105    public void testGet() throws IOException {
    106         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/get?foo=bar")).connect(progress);
     106        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/get?foo=bar")).connect(progress);
    107107        assertThat(response.getRequestMethod(), is("GET"));
    108108        assertThat(response.getResponseCode(), is(200));
    109109        assertThat(response.getResponseMessage(), equalToIgnoringCase("OK"));
    110         assertThat(response.getContentType(), is("application/json; encoding=utf-8"));
    111         assertThat(response.getHeaderField("Content-Type"), is("application/json; encoding=utf-8"));
    112         assertThat(response.getHeaderField("Content-TYPE"), is("application/json; encoding=utf-8"));
    113         assertThat(response.getHeaderFields().get("Content-Type"), is(Collections.singletonList("application/json; encoding=utf-8")));
    114         assertThat(response.getHeaderFields().get("Content-TYPE"), is(Collections.singletonList("application/json; encoding=utf-8")));
     110        assertThat(response.getContentType(), is("application/json"));
     111        assertThat(response.getHeaderField("Content-Type"), is("application/json"));
     112        assertThat(response.getHeaderField("Content-TYPE"), is("application/json"));
     113        assertThat(response.getHeaderFields().get("Content-Type"), is(Collections.singletonList("application/json")));
     114        assertThat(response.getHeaderFields().get("Content-TYPE"), is(Collections.singletonList("application/json")));
    115115        try (InputStream in = response.getContent();
    116116             JsonReader json = JsonProvider.provider().createReader(in)) {
    117117            final JsonObject root = json.readObject();
    118             assertThat(root.getJsonObject("args").getJsonArray("foo").getString(0), is("bar"));
    119             assertThat(root.getString("url"), is("https://httpbingo.org/get?foo=bar"));
     118            assertThat(root.getJsonObject("args").getString("foo"), is("bar"));
     119            assertThat(root.getString("url"), is("https://httpbin.org/get?foo=bar"));
    120120            assertThat(root.getJsonObject("headers").get("Cache-Control"), nullValue());
    121121            assertThat(root.getJsonObject("headers").get("Pragma"), nullValue());
     
    129129    @Test
    130130    public void testHeaders() throws IOException {
    131         try (InputStream in = HttpClient.create(new URL("https://httpbingo.org/headers")).connect(progress).getContent();
     131        try (InputStream in = HttpClient.create(new URL("https://httpbin.org/headers")).connect(progress).getContent();
    132132             JsonReader json = JsonProvider.provider().createReader(in)) {
    133133            final JsonObject headers = json.readObject().getJsonObject("headers");
    134             assertThat(headers.getJsonArray("Accept").getString(0), is("*/*"));
    135             assertThat(headers.getJsonArray("Accept-Encoding").getString(0), is("gzip, deflate"));
    136             assertThat(headers.getJsonArray("User-Agent").getString(0), is(Version.getInstance().getFullAgentString()));
     134            assertThat(headers.getString("Accept"), is("*/*"));
     135            assertThat(headers.getString("Accept-Encoding"), is("gzip, deflate"));
     136            assertThat(headers.getString("User-Agent"), is(Version.getInstance().getFullAgentString()));
    137137        }
    138138    }
     
    144144    @Test
    145145    public void testUserAgent() throws IOException {
    146         try (InputStream in = HttpClient.create(new URL("https://httpbingo.org/user-agent")).connect(progress).getContent();
     146        try (InputStream in = HttpClient.create(new URL("https://httpbin.org/user-agent")).connect(progress).getContent();
    147147             JsonReader json = JsonProvider.provider().createReader(in)) {
    148148            assertThat(json.readObject().getString("user-agent"), is(Version.getInstance().getFullAgentString()));
     
    156156    @Test
    157157    public void testFetchUtf8Content() throws IOException {
    158         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/encoding/utf8")).connect(progress);
     158        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/encoding/utf8")).connect(progress);
    159159        assertThat(response.getResponseCode(), is(200));
    160160        final String content = response.fetchContent();
     
    170170    public void testPost() throws IOException {
    171171        final String text = "Hello World!\nGeetings from JOSM, the Java OpenStreetMap Editor";
    172         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/post"), "POST")
     172        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST")
    173173                .setHeader("Content-Type", "text/plain")
    174174                .setRequestBody(text.getBytes(StandardCharsets.UTF_8))
     
    184184    @Test
    185185    public void testPostZero() throws IOException {
    186         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/post"), "POST")
     186        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST")
    187187                .setHeader("Content-Type", "text/plain")
    188188                .setRequestBody("".getBytes(StandardCharsets.UTF_8))
     
    196196    }
    197197
    198     @Test
     198    /*@Test
    199199    public void testRelativeRedirects() throws IOException {
    200         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/relative-redirect/3")).connect(progress);
     200        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/3")).connect(progress);
    201201        assertThat(response.getResponseCode(), is(200));
    202202        assertThat(response.getContentLength() > 100, is(true));
    203     }
    204 
    205     @Test
     203    }*/
     204
     205    /*@Test
    206206    public void testAbsoluteRedirects() throws IOException {
    207         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/absolute-redirect/3")).connect(progress);
     207        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/3")).connect(progress);
    208208        assertThat(response.getResponseCode(), is(200));
    209209        assertThat(response.getContentLength() > 100, is(true));
    210     }
     210    }*/
    211211
    212212    /**
     
    214214     * @throws IOException if an I/O error occurs
    215215     */
    216     @Test(expected = IOException.class)
     216    /*@Test(expected = IOException.class)
    217217    public void testTooMuchRedirects() throws IOException {
    218         HttpClient.create(new URL("https://httpbingo.org/redirect/3")).setMaxRedirects(2).connect(progress);
    219     }
     218        HttpClient.create(new URL("https://httpbin.org/redirect/3")).setMaxRedirects(2).connect(progress);
     219    }*/
    220220
    221221    /**
     
    226226    public void testHttp418() throws IOException {
    227227        // https://tools.ietf.org/html/rfc2324
    228         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/418")).connect(progress);
     228        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/418")).connect(progress);
    229229        assertThat(response.getResponseCode(), is(418));
    230         assertThat(response.getHeaderField("X-More-Info"), is("http://tools.ietf.org/html/rfc2324"));
    231         final String content = response.fetchContent();
    232         assertThat(content, containsString("I'm a teapot!"));
    233         assertThat(captured.getMessage(), containsString("I'm a teapot!"));
     230        final String content = response.fetchContent();
     231        assertThat(content, containsString("-=[ teapot ]=-"));
     232        assertThat(captured.getMessage(), containsString("-=[ teapot ]=-"));
    234233        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
    235234    }
     
    242241    public void testHttp401() throws IOException {
    243242        // https://tools.ietf.org/html/rfc2324
    244         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/401")).connect(progress);
     243        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/401")).connect(progress);
    245244        assertThat(response.getResponseCode(), is(401));
    246245        assertThat(response.getResponseMessage(), equalToIgnoringCase("UNAUTHORIZED"));
     
    258257    public void testHttp402() throws IOException {
    259258        // https://tools.ietf.org/html/rfc2324
    260         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/402")).connect(progress);
     259        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/402")).connect(progress);
    261260        assertThat(response.getResponseCode(), is(402));
    262261        assertThat(response.getResponseMessage(), equalToIgnoringCase("PAYMENT REQUIRED"));
     
    274273    public void testHttp403() throws IOException {
    275274        // https://tools.ietf.org/html/rfc2324
    276         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/403")).connect(progress);
     275        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/403")).connect(progress);
    277276        assertThat(response.getResponseCode(), is(403));
    278277        assertThat(response.getResponseMessage(), equalToIgnoringCase("FORBIDDEN"));
     
    290289    public void testHttp404() throws IOException {
    291290        // https://tools.ietf.org/html/rfc2324
    292         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/404")).connect(progress);
     291        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/404")).connect(progress);
    293292        assertThat(response.getResponseCode(), is(404));
    294293        assertThat(response.getResponseMessage(), equalToIgnoringCase("NOT FOUND"));
     
    306305    public void testHttp500() throws IOException {
    307306        // https://tools.ietf.org/html/rfc2324
    308         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/500")).connect(progress);
     307        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/500")).connect(progress);
    309308        assertThat(response.getResponseCode(), is(500));
    310309        assertThat(response.getResponseMessage(), equalToIgnoringCase("INTERNAL SERVER ERROR"));
     
    321320    @Test
    322321    public void testRequestInTime() throws IOException {
    323         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/delay/1")).setReadTimeout(2000).connect(progress);
     322        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/delay/1")).setReadTimeout(2000).connect(progress);
    324323        assertThat(response.getResponseCode(), is(200));
    325324    }
     
    331330    @Test(expected = IOException.class)
    332331    public void testTakesTooLong() throws IOException {
    333         HttpClient.create(new URL("https://httpbingo.org/delay/1")).setReadTimeout(500).connect(progress);
     332        HttpClient.create(new URL("https://httpbin.org/delay/1")).setReadTimeout(500).connect(progress);
    334333    }
    335334
     
    340339    @Test
    341340    public void testDeflate() throws IOException {
    342         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/deflate")).connect(progress);
     341        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/deflate")).connect(progress);
    343342        assertThat(response.getResponseCode(), is(200));
    344343        try (InputStream in = response.getContent();
     
    354353    @Test
    355354    public void testGzip() throws IOException {
    356         final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/gzip")).connect(progress);
     355        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/gzip")).connect(progress);
    357356        assertThat(response.getResponseCode(), is(200));
    358357        try (InputStream in = response.getContent();
Note: See TracChangeset for help on using the changeset viewer.