BinaryBase64MessageValidator extends PlainTextMessageValidator { @Override public void validateMessage(Message receivedMessage, Message controlMessage, TestContext context, ValidationContext validationContext) throws ValidationException { if (receivedMessage.getPayload() instanceof byte[]) { receivedMessage.setPayload(Base64.encodeBase64String(receivedMessage.getPayload(byte[].class))); } 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 testBinaryBase64Validation() { Message receivedMessage = new DefaultMessage("Hello World!".getBytes()); Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello World!".getBytes())); validator.validateMessage(receivedMessage, controlMessage, context, validationContext); }
@Test public void testBinaryBase64ValidationNoBinaryData() { Message receivedMessage = new DefaultMessage("SGVsbG8gV29ybGQh"); Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello World!".getBytes())); validator.validateMessage(receivedMessage, controlMessage, context, validationContext); }
@Test public void testBinaryBase64ValidationError() { Message receivedMessage = new DefaultMessage("Hello World!".getBytes()); 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"); }