Example #1
0
 @Test
 public void testCompressionDecompression() throws Exception {
   final StringEntity in = new StringEntity("some kind of text", ContentType.TEXT_PLAIN);
   final GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
   final ByteArrayOutputStream buf = new ByteArrayOutputStream();
   gzipe.writeTo(buf);
   final ByteArrayEntity out = new ByteArrayEntity(buf.toByteArray());
   final GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(out);
   Assert.assertEquals("some kind of text", EntityUtils.toString(gunzipe, Consts.ASCII));
 }
Example #2
0
 @Test
 public void testBasic() throws Exception {
   final String s = "some kind of text";
   final StringEntity e = new StringEntity(s, ContentType.TEXT_PLAIN);
   e.setChunked(false);
   final GzipCompressingEntity gzipe = new GzipCompressingEntity(e);
   Assert.assertTrue(gzipe.isChunked());
   Assert.assertEquals(-1, gzipe.getContentLength());
   Assert.assertNotNull(gzipe.getContentEncoding());
   Assert.assertEquals("gzip", gzipe.getContentEncoding().getValue());
 }
Example #3
0
 @Test
 public void testCompressionIOExceptionLeavesOutputStreamOpen() throws Exception {
   final HttpEntity in = Mockito.mock(HttpEntity.class);
   Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(Mockito.<OutputStream>any());
   final GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
   final OutputStream out = Mockito.mock(OutputStream.class);
   try {
     gzipe.writeTo(out);
   } catch (IOException ex) {
     Mockito.verify(out, Mockito.never()).close();
   }
 }