@Test public void testCreateFromDecodedStringBody() throws Exception { String str = "Gaap is awesome"; byte[] content = str.getBytes(); byte[] compressedContent = new GzipCompressor().compress(content); RecordedStringHttpBody recordedStringHttpBody = new RecordedStringHttpBody(str); RecordedEncodedHttpBody recordedEncodedHttpBody = new RecordedEncodedHttpBody(recordedStringHttpBody, "gzip"); Assert.assertEquals(recordedEncodedHttpBody.getContent("UTF-8"), compressedContent); }
@Test public void testCreateFromEncodedBytes() throws Exception { String str = "Gaap is awesome"; byte[] content = str.getBytes(); byte[] compressedContent = new GzipCompressor().compress(content); RecordedEncodedHttpBody recordedEncodedHttpBody = new RecordedEncodedHttpBody(compressedContent, "gzip", "UTF-8", "text/html"); Assert.assertEquals(recordedEncodedHttpBody.getContent("UTF-8"), compressedContent); Assert.assertEquals(recordedEncodedHttpBody.getEncodingName(), "gzip"); RecordedHttpBody decodedBody = recordedEncodedHttpBody.getDecodedBody(); Assert.assertTrue(decodedBody instanceof RecordedStringHttpBody); Assert.assertEquals(((RecordedStringHttpBody) decodedBody).getContent(), str); } }
@Test public void testCreateDeflateEncodedStringHttpBody() throws IOException { String str = "Hello world. This is some extra text to make the string longer so that deflate makes it smaller"; byte[] content = str.getBytes(); byte[] compressedContent = new DeflateCompressor().compress(content); InputStream is = new ByteArrayInputStream(compressedContent); RecordedHttpBody recordedHttpBody = RecordedHttpBodyFactory.create("text/html", "deflate", is, "UTF-8"); Assert.assertTrue(recordedHttpBody instanceof RecordedEncodedHttpBody); RecordedEncodedHttpBody encodedBody = (RecordedEncodedHttpBody) recordedHttpBody; Assert.assertEquals(encodedBody.getEncodingName(), "deflate"); Assert.assertTrue(encodedBody.getDecodedBody() instanceof RecordedStringHttpBody); Assert.assertEquals(encodedBody.getDecodedBody().getContent("UTF-8"), content); Assert.assertEquals(encodedBody.getContent("UTF-8"), compressedContent); } }
@Test public void testCreateGZipEncodedStringHttpBody() throws IOException { String str = "Hello world. This is some extra text to make the string longer so that gzip makes it smaller"; byte[] content = str.getBytes(); byte[] compressedContent = new GzipCompressor().compress(content); InputStream is = new ByteArrayInputStream(compressedContent); RecordedHttpBody recordedHttpBody = RecordedHttpBodyFactory.create("text/html", "gzip", is, "UTF-8"); Assert.assertTrue(recordedHttpBody instanceof RecordedEncodedHttpBody); RecordedEncodedHttpBody encodedBody = (RecordedEncodedHttpBody) recordedHttpBody; Assert.assertEquals(encodedBody.getEncodingName(), "gzip"); Assert.assertTrue(encodedBody.getDecodedBody() instanceof RecordedStringHttpBody); Assert.assertEquals(encodedBody.getDecodedBody().getContent("UTF-8"), content); Assert.assertEquals(encodedBody.getContent("UTF-8"), compressedContent); }