Changeset 16837 in josm


Ignore:
Timestamp:
2020-08-03T20:52:27+02:00 (3 months ago)
Author:
simon04
Message:

HttpClientTest: migrate to httpbingo.org

Reason: httpbin.org seems to be unmaintained, https://github.com/postmanlabs/httpbin/issues/617

File:
1 edited

Legend:

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

    r16737 r16837  
    3636
    3737/**
    38  * Tests the {@link HttpClient} using the webservice <a href="https://httpbin.org/">https://httpbin.org/</a>.
     38 * Tests the {@link HttpClient} using the webservice <a href="https://httpbingo.org/">https://httpbingo.org/</a>.
    3939 */
    4040public class HttpClientTest {
     
    8383    @Test
    8484    public void testConstructorGetterSetter() throws IOException {
    85         final HttpClient client = HttpClient.create(new URL("https://httpbin.org/"));
    86         assertThat(client.getURL(), is(new URL("https://httpbin.org/")));
     85        final HttpClient client = HttpClient.create(new URL("https://httpbingo.org/"));
     86        assertThat(client.getURL(), is(new URL("https://httpbingo.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://httpbin.org/get?foo=bar")).connect(progress);
     106        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.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"));
    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")));
     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")));
    115115        try (InputStream in = response.getContent();
    116116             JsonReader json = JsonProvider.provider().createReader(in)) {
    117117            final JsonObject root = json.readObject();
    118             assertThat(root.getJsonObject("args").getString("foo"), is("bar"));
    119             assertThat(root.getString("url"), is("https://httpbin.org/get?foo=bar"));
     118            assertThat(root.getJsonObject("args").getJsonArray("foo").getString(0), is("bar"));
     119            assertThat(root.getString("url"), is("https://httpbingo.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://httpbin.org/headers")).connect(progress).getContent();
     131        try (InputStream in = HttpClient.create(new URL("https://httpbingo.org/headers")).connect(progress).getContent();
    132132             JsonReader json = JsonProvider.provider().createReader(in)) {
    133133            final JsonObject headers = json.readObject().getJsonObject("headers");
    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()));
     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()));
    137137        }
    138138    }
     
    144144    @Test
    145145    public void testUserAgent() throws IOException {
    146         try (InputStream in = HttpClient.create(new URL("https://httpbin.org/user-agent")).connect(progress).getContent();
     146        try (InputStream in = HttpClient.create(new URL("https://httpbingo.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://httpbin.org/encoding/utf8")).connect(progress);
     158        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.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://httpbin.org/post"), "POST")
     172        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.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://httpbin.org/post"), "POST")
     186        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.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://httpbin.org/relative-redirect/3")).connect(progress);
     200        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.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://httpbin.org/absolute-redirect/3")).connect(progress);
     207        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.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://httpbin.org/redirect/3")).setMaxRedirects(2).connect(progress);
    219     }*/
     218        HttpClient.create(new URL("https://httpbingo.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://httpbin.org/status/418")).connect(progress);
     228        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/418")).connect(progress);
    229229        assertThat(response.getResponseCode(), is(418));
    230         final String content = response.fetchContent();
    231         assertThat(content, containsString("-=[ teapot ]=-"));
    232         assertThat(captured.getMessage(), containsString("-=[ teapot ]=-"));
     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!"));
    233234        assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG));
    234235    }
     
    241242    public void testHttp401() throws IOException {
    242243        // https://tools.ietf.org/html/rfc2324
    243         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/401")).connect(progress);
     244        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/401")).connect(progress);
    244245        assertThat(response.getResponseCode(), is(401));
    245246        assertThat(response.getResponseMessage(), equalToIgnoringCase("UNAUTHORIZED"));
     
    257258    public void testHttp402() throws IOException {
    258259        // https://tools.ietf.org/html/rfc2324
    259         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/402")).connect(progress);
     260        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/402")).connect(progress);
    260261        assertThat(response.getResponseCode(), is(402));
    261262        assertThat(response.getResponseMessage(), equalToIgnoringCase("PAYMENT REQUIRED"));
     
    273274    public void testHttp403() throws IOException {
    274275        // https://tools.ietf.org/html/rfc2324
    275         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/403")).connect(progress);
     276        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/403")).connect(progress);
    276277        assertThat(response.getResponseCode(), is(403));
    277278        assertThat(response.getResponseMessage(), equalToIgnoringCase("FORBIDDEN"));
     
    289290    public void testHttp404() throws IOException {
    290291        // https://tools.ietf.org/html/rfc2324
    291         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/404")).connect(progress);
     292        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/404")).connect(progress);
    292293        assertThat(response.getResponseCode(), is(404));
    293294        assertThat(response.getResponseMessage(), equalToIgnoringCase("NOT FOUND"));
     
    305306    public void testHttp500() throws IOException {
    306307        // https://tools.ietf.org/html/rfc2324
    307         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/500")).connect(progress);
     308        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/500")).connect(progress);
    308309        assertThat(response.getResponseCode(), is(500));
    309310        assertThat(response.getResponseMessage(), equalToIgnoringCase("INTERNAL SERVER ERROR"));
     
    320321    @Test
    321322    public void testRequestInTime() throws IOException {
    322         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/delay/1")).setReadTimeout(2000).connect(progress);
     323        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/delay/1")).setReadTimeout(2000).connect(progress);
    323324        assertThat(response.getResponseCode(), is(200));
    324325    }
     
    330331    @Test(expected = IOException.class)
    331332    public void testTakesTooLong() throws IOException {
    332         HttpClient.create(new URL("https://httpbin.org/delay/1")).setReadTimeout(500).connect(progress);
     333        HttpClient.create(new URL("https://httpbingo.org/delay/1")).setReadTimeout(500).connect(progress);
    333334    }
    334335
     
    339340    @Test
    340341    public void testDeflate() throws IOException {
    341         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/deflate")).connect(progress);
     342        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/deflate")).connect(progress);
    342343        assertThat(response.getResponseCode(), is(200));
    343344        try (InputStream in = response.getContent();
     
    353354    @Test
    354355    public void testGzip() throws IOException {
    355         final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/gzip")).connect(progress);
     356        final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/gzip")).connect(progress);
    356357        assertThat(response.getResponseCode(), is(200));
    357358        try (InputStream in = response.getContent();
Note: See TracChangeset for help on using the changeset viewer.