"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestGZip.java" between
httpcomponents-client-5.2-src.tar.gz and httpcomponents-client-5.2.1-src.tar.gz

About: Apache HttpComponents Client provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. Java sources.

TestGZip.java  (httpcomponents-client-5.2-src):TestGZip.java  (httpcomponents-client-5.2.1-src)
skipping to change at line 53 skipping to change at line 53
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers; import org.mockito.ArgumentMatchers;
import org.mockito.Mockito; import org.mockito.Mockito;
public class TestGZip { public class TestGZip {
@Test @Test
public void testBasic() throws Exception { public void testBasic() throws Exception {
final String s = "some kind of text"; final String s = "some kind of text";
final StringEntity e = new StringEntity(s, ContentType.TEXT_PLAIN, false ); final StringEntity e = new StringEntity(s, ContentType.TEXT_PLAIN, false );
final GzipCompressingEntity gzipe = new GzipCompressingEntity(e); try (final GzipCompressingEntity gzipe = new GzipCompressingEntity(e)) {
Assertions.assertTrue(gzipe.isChunked()); Assertions.assertTrue(gzipe.isChunked());
Assertions.assertEquals(-1, gzipe.getContentLength()); Assertions.assertEquals(-1, gzipe.getContentLength());
Assertions.assertNotNull(gzipe.getContentEncoding()); Assertions.assertNotNull(gzipe.getContentEncoding());
Assertions.assertEquals("gzip", gzipe.getContentEncoding()); Assertions.assertEquals("gzip", gzipe.getContentEncoding());
}
} }
@Test @Test
public void testCompressionDecompression() throws Exception { public void testCompressionDecompression() throws Exception {
final StringEntity in = new StringEntity("some kind of text", ContentTyp e.TEXT_PLAIN); final StringEntity in = new StringEntity("some kind of text", ContentTyp e.TEXT_PLAIN);
final GzipCompressingEntity gzipe = new GzipCompressingEntity(in); try (final GzipCompressingEntity gzipe = new GzipCompressingEntity(in))
final ByteArrayOutputStream buf = new ByteArrayOutputStream(); {
gzipe.writeTo(buf); final ByteArrayOutputStream buf = new ByteArrayOutputStream();
final ByteArrayEntity out = new ByteArrayEntity(buf.toByteArray(), Conte gzipe.writeTo(buf);
ntType.APPLICATION_OCTET_STREAM); final ByteArrayEntity out = new ByteArrayEntity(buf.toByteArray(), C
final GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(out) ontentType.APPLICATION_OCTET_STREAM);
; final GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(
Assertions.assertEquals("some kind of text", EntityUtils.toString(gunzip out);
e, StandardCharsets.US_ASCII)); Assertions.assertEquals("some kind of text", EntityUtils.toString(gu
nzipe, StandardCharsets.US_ASCII));
}
} }
@Test @Test
public void testCompressionIOExceptionLeavesOutputStreamOpen() throws Except ion { public void testCompressionIOExceptionLeavesOutputStreamOpen() throws Except ion {
final HttpEntity in = Mockito.mock(HttpEntity.class); final HttpEntity in = Mockito.mock(HttpEntity.class);
Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(ArgumentMat chers.any()); Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(ArgumentMat chers.any());
final GzipCompressingEntity gzipe = new GzipCompressingEntity(in); try (final GzipCompressingEntity gzipe = new GzipCompressingEntity(in))
final OutputStream out = Mockito.mock(OutputStream.class); {
try { final OutputStream out = Mockito.mock(OutputStream.class);
gzipe.writeTo(out); try {
} catch (final IOException ex) { gzipe.writeTo(out);
Mockito.verify(out, Mockito.never()).close(); } catch (final IOException ex) {
Mockito.verify(out, Mockito.never()).close();
}
} }
} }
@Test @Test
public void testDecompressionWithMultipleGZipStream() throws Exception { public void testDecompressionWithMultipleGZipStream() throws Exception {
final int[] data = new int[] { final int[] data = new int[] {
0x1f, 0x8b, 0x08, 0x08, 0x03, 0xf1, 0x55, 0x5a, 0x00, 0x03, 0x74 , 0x65, 0x73, 0x74, 0x31, 0x00, 0x1f, 0x8b, 0x08, 0x08, 0x03, 0xf1, 0x55, 0x5a, 0x00, 0x03, 0x74 , 0x65, 0x73, 0x74, 0x31, 0x00,
0x2b, 0x2e, 0x29, 0x4a, 0x4d, 0xcc, 0xd5, 0x35, 0xe4, 0x02, 0x00 , 0x03, 0x61, 0xf0, 0x5f, 0x09, 0x2b, 0x2e, 0x29, 0x4a, 0x4d, 0xcc, 0xd5, 0x35, 0xe4, 0x02, 0x00 , 0x03, 0x61, 0xf0, 0x5f, 0x09,
0x00, 0x00, 0x00, 0x1f, 0x8b, 0x08, 0x08, 0x08, 0xf1, 0x55, 0x5a , 0x00, 0x03, 0x74, 0x65, 0x73, 0x00, 0x00, 0x00, 0x1f, 0x8b, 0x08, 0x08, 0x08, 0xf1, 0x55, 0x5a , 0x00, 0x03, 0x74, 0x65, 0x73,
0x74, 0x32, 0x00, 0x2b, 0x2e, 0x29, 0x4a, 0x4d, 0xcc, 0xd5, 0x35 , 0xe2, 0x02, 0x00, 0xc0, 0x32, 0x74, 0x32, 0x00, 0x2b, 0x2e, 0x29, 0x4a, 0x4d, 0xcc, 0xd5, 0x35 , 0xe2, 0x02, 0x00, 0xc0, 0x32,
 End of changes. 3 change blocks. 
20 lines changed or deleted 25 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)