@Test public void decompressEmpty() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put("Content-Type", Collections.singletonList("application/json")); headers.put("Content-Encoding", Collections.singletonList("gzip")); HttpResponse res = new HttpResponse(200, headers); Assertions.assertEquals("", res.decompress().entityAsString()); Assertions.assertEquals(0, res.decompress().entity().length); } }
@Test public void decompress() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put("Content-Type", Collections.singletonList("application/json")); headers.put("Content-Encoding", Collections.singletonList("gzip")); byte[] entity = HttpUtils.gzip("foo bar baz foo bar baz".getBytes(StandardCharsets.UTF_8)); HttpResponse res = new HttpResponse(200, headers, entity); Assertions.assertEquals("foo bar baz foo bar baz", res.decompress().entityAsString()); Assertions.assertNull(res.decompress().header("content-encoding")); }
@Test public void decompressNoChange() throws IOException { Map<String, List<String>> headers = new HashMap<>(); headers.put("Content-Type", Collections.singletonList("application/json")); byte[] entity = HttpUtils.gzip("foo bar baz foo bar baz".getBytes(StandardCharsets.UTF_8)); HttpResponse res = new HttpResponse(200, headers, entity); Assertions.assertSame(res, res.decompress()); }
@Test public void okWithCompressedBody() throws IOException { HttpResponse res = HttpClient.DEFAULT .post(uri("/echo")) .acceptGzip() .addHeader("X-Status", "200") .withContent("text/plain", "foo") .compress() .send() .decompress(); Assertions.assertEquals(200, res.status()); Assertions.assertEquals("foo", res.entityAsString()); } }