GzipDecompressorProcessor extends ProcessorBase { @Override public void process(final WilmaHttpEntity entity) throws ApplicationException { if (isContentGzipEncoded(entity)) { ByteArrayOutputStream baos = decompressor.decompress(entity.getInputStream()); ByteArrayInputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); entity.setInputStream(inputStream); entity.setBody(baos.toString()); } }  @Override void process(final WilmaHttpEntity entity);  }
@Test public void testProcessShouldCallDecompressor() throws ApplicationException { given(entity.getHeader(GZIP_ENCODING)).willReturn(GZIP); given(entity.getInputStream()).willReturn(inputStream); given(decompressor.decompress(inputStream)).willReturn(body); underTest.process(entity); verify(decompressor).decompress(inputStream); }
@Test public void testProcessShouldSetBodyWhenDecompressionNeeded() throws ApplicationException { given(entity.getHeader(GZIP_ENCODING)).willReturn(GZIP); given(entity.getInputStream()).willReturn(inputStream); given(decompressor.decompress(inputStream)).willReturn(body); underTest.process(entity); verify(entity).setBody(body.toString()); }
@Test public void testProcessShouldNotSetBodyWhenDecompressionNotNeeded() throws ApplicationException { given(entity.getHeader(GZIP_ENCODING)).willReturn("xml"); given(entity.getInputStream()).willReturn(inputStream); given(decompressor.decompress(inputStream)).willReturn(body); underTest.process(entity); verify(decompressor, never()).decompress(inputStream); }
@Test public void testProcessShouldNotSetBodyWhenHeaderIsNull() throws ApplicationException { given(entity.getHeader(GZIP_ENCODING)).willReturn(null); given(entity.getInputStream()).willReturn(inputStream); given(decompressor.compress(inputStream)).willReturn(body); underTest.process(entity); verify(decompressor, never()).decompress(inputStream); }