DefaultHeaderValidator implements HeaderValidator { @Override public void validateHeader(String headerName, Object receivedValue, Object controlValue, TestContext context, HeaderValidationContext validationContext) { Optional<HeaderValidator> validator = getHeaderValidator(headerName, controlValue, context); if (validator.isPresent()) { validator.get().validateHeader(headerName, receivedValue, controlValue, context, validationContext); return; } String expectedValue = Optional.ofNullable(controlValue) .map(value -> context.getTypeConverter().convertIfNecessary(value, String.class)) .map(context::replaceDynamicContentInString) .orElse(""); try { if (receivedValue != null) { String receivedValueString = context.getTypeConverter().convertIfNecessary(receivedValue, String.class); if (ValidationMatcherUtils.isValidationMatcherExpression(expectedValue)) { ValidationMatcherUtils.resolveValidationMatcher(headerName, receivedValueString, expectedValue, context); return; } Assert.isTrue(receivedValueString.equals(expectedValue), "Values not equal for header element '" + headerName + "', expected '" + expectedValue + "' but was '" + receivedValue + "'"); } else { Assert.isTrue(!StringUtils.hasText(expectedValue), "Values not equal for header element '" + headerName + "', expected '" + expectedValue + "' but was '" + null + "'"); } } catch (IllegalArgumentException e) { throw new ValidationException("Validation failed:", e); } if (log.isDebugEnabled()) { log.debug("Validating header element: " + headerName + "='" + expectedValue + "': OK."); } }  @Override void validateHeader(String headerName, Object receivedValue, Object controlValue, TestContext context, HeaderValidationContext validationContext); @Override boolean supports(String headerName, Class<?> type);  }
@Test(dataProvider = "successData") public void testValidateHeader(Object receivedValue, Object controlValue) { validator.validateHeader("foo", receivedValue, controlValue, context, validationContext); }
@Test public void testValidateHeaderVariableSupport() { context.setVariable("control", "bar"); validator.validateHeader("foo", "bar", "${control}", context, validationContext); }
@Test public void testValidateHeaderValidationMatcherSupport() { validator.validateHeader("foo", "bar", "@ignore@", context, validationContext); validator.validateHeader("foo", "bar", "@hasLength(3)@", context, validationContext); }
@Test(dataProvider = "errorData", expectedExceptions = ValidationException.class) public void testValidateHeaderError(Object receivedValue, Object controlValue) { validator.validateHeader("foo", receivedValue, controlValue, context, validationContext); }