GzipBinaryBase64MessageValidator extends BinaryBase64MessageValidator { @Override public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context, ValidationContext validationContext) throws ValidationException { if (receivedMessage.getPayload() instanceof byte[]) { try (GZIPInputStream gzipInputStream = new GZIPInputStream(receivedMessage.getPayload(InputStream.class)); ByteArrayOutputStream unzipped = new ByteArrayOutputStream()) { StreamUtils.copy(gzipInputStream, unzipped); receivedMessage.setPayload(unzipped.toByteArray()); } catch (IOException e) { throw new CitrusRuntimeException("Failed to validate gzipped message", e); } } super.validateMessage(receivedMessage, controlMessage, context, validationContext); }  @Override void validateMessage(Message receivedMessage, Message controlMessage,
                                TestContext context, ValidationContext validationContext); @Override boolean supportsMessageType(String messageType, Message message);  }
@Test public void testGzipBinaryBase64Validation() throws IOException { Message receivedMessage = new DefaultMessage(getZippedContent("Hello World!")); Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello World!".getBytes())); validator.validateMessage(receivedMessage, controlMessage, context, validationContext); }
@Test public void testGzipBinaryBase64ValidationNoBinaryData() throws IOException { Message receivedMessage = new DefaultMessage("SGVsbG8gV29ybGQh"); Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello World!".getBytes())); validator.validateMessage(receivedMessage, controlMessage, context, validationContext); }
@Test public void testGzipBinaryBase64ValidationError() throws IOException { Message receivedMessage = new DefaultMessage(getZippedContent("Hello World!")); Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello Citrus!".getBytes())); try { validator.validateMessage(receivedMessage, controlMessage, context, validationContext); } catch (ValidationException e) { Assert.assertTrue(e.getMessage().contains("expected 'SGVsbG8gQ2l0cnVzIQ=='")); Assert.assertTrue(e.getMessage().contains("but was 'SGVsbG8gV29ybGQh'")); return; } Assert.fail("Missing validation exception due to wrong number of JSON entries"); }