Base64DecoderProcessor extends ProcessorBase { @Override public void process(final WilmaHttpEntity entity) throws ApplicationException { if (isBinaryContent(entity)) { String responseBody = entity.getBody(); byte[] result = decompressor.decode(responseBody); entity.setInputStream(getInputStream(result)); } }  @Override void process(final WilmaHttpEntity entity);  }
@Test public void testProcessShouldCallDecoderWhenEntityHasBinaryContent() throws ApplicationException { given(entity.getHeader(CONTENT_TYPE)).willReturn(FAST_INFOSET); given(decoder.decode(BODY)).willReturn(result); underTest.process(entity); verify(decoder).decode(BODY); }
@Test public void testProcessShouldSetInputstreamWhenEntityHasBinaryContent() throws ApplicationException { given(entity.getHeader(CONTENT_TYPE)).willReturn(FAST_INFOSET); given(decoder.decode(BODY)).willReturn(result); underTest.process(entity); verify(entity).setInputStream(Mockito.any(ByteArrayInputStream.class)); }
@Test public void testProcessShouldNotDecompressBase64WhenEntityHasPlainContent() throws ApplicationException { given(entity.getHeader(CONTENT_TYPE)).willReturn(XML_CONTENT); underTest.process(entity); verify(entity, never()).setInputStream(Mockito.any(ByteArrayInputStream.class)); }
@Test public void testProcessShouldNotDecompressBase64WhenContentTypeIsNull() throws ApplicationException { given(entity.getHeader(CONTENT_TYPE)).willReturn(null); underTest.process(entity); verify(entity, never()).setInputStream(Mockito.any(ByteArrayInputStream.class)); }