Changeset 15742 in josm for trunk/test


Ignore:
Timestamp:
2020-01-20T23:18:42+01:00 (5 years ago)
Author:
simon04
Message:

HttpClient: add support for Content-Encoding: deflate

File:
1 edited

Legend:

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

    r15741 r15742  
    316316    public void testTakesTooLong() throws IOException {
    317317        HttpClient.create(new URL("https://httpbin.org/delay/1")).setReadTimeout(500).connect(progress);
     318    }
     319
     320    /**
     321     * Test reading Deflate-encoded data.
     322     * @throws IOException if any I/O error occurs
     323     */
     324    @Test
     325    public void testDeflate() throws IOException {
     326        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/deflate")).connect(progress);
     327        assertThat(response.getResponseCode(), is(200));
     328        try (InputStream in = response.getContent();
     329             JsonReader json = JsonProvider.provider().createReader(in)) {
     330            assertThat(json.readObject().getBoolean("deflated"), is(true));
     331        }
     332    }
     333
     334    /**
     335     * Test reading Gzip-encoded data.
     336     * @throws IOException if any I/O error occurs
     337     */
     338    @Test
     339    public void testGzip() throws IOException {
     340        final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/gzip")).connect(progress);
     341        assertThat(response.getResponseCode(), is(200));
     342        try (InputStream in = response.getContent();
     343             JsonReader json = JsonProvider.provider().createReader(in)) {
     344            assertThat(json.readObject().getBoolean("gzipped"), is(true));
     345        }
    318346    }
    319347
Note: See TracChangeset for help on using the changeset viewer.