HttpQueryParamHeaderValidator extends DefaultHeaderValidator { @Override public void validateHeader(String name, Object received, Object control, TestContext context, HeaderValidationContext validationContext) { if (ValidationMatcherUtils.isValidationMatcherExpression(Optional.ofNullable(control) .map(Object::toString) .orElse(""))) { super.validateHeader(HttpMessageHeaders.HTTP_QUERY_PARAMS, received, control, context, validationContext); return; } Map<String, String> receiveParams = convertToMap(received); Map<String, String> controlParams = convertToMap(control); for (Map.Entry<String, String> param : controlParams.entrySet()) { if (!receiveParams.containsKey(param.getKey())) { throw new ValidationException("Validation failed: Query param '" + param.getKey() + "' is missing"); } super.validateHeader(HttpMessageHeaders.HTTP_QUERY_PARAMS + "(" + param.getKey() + ")", receiveParams.get(param.getKey()), param.getValue(), context, validationContext); } }  @Override void validateHeader(String name, Object received, Object control, TestContext context, HeaderValidationContext validationContext); @Override boolean supports(String headerName, Class<?> type);  }
@Test(dataProvider = "successData") public void testValidateHeader(Object receivedValue, Object controlValue) { validator.validateHeader(HttpMessageHeaders.HTTP_QUERY_PARAMS, receivedValue, controlValue, context, validationContext); }
@Test public void testValidateHeaderVariableSupport() { context.setVariable("control", "barValue"); validator.validateHeader(HttpMessageHeaders.HTTP_QUERY_PARAMS, "foo=fooValue,bar=barValue", "foo=fooValue,bar=${control}", context, validationContext); }
@Test public void testValidateHeaderValidationMatcherSupport() { validator.validateHeader(HttpMessageHeaders.HTTP_QUERY_PARAMS, "foo=fooValue,bar=barValue", "foo=fooValue,bar=@ignore@", context, validationContext); validator.validateHeader(HttpMessageHeaders.HTTP_QUERY_PARAMS, "foo=fooValue,bar=barValue", "foo=fooValue,bar=@hasLength(8)@", context, validationContext); }
@Test(dataProvider = "errorData", expectedExceptions = ValidationException.class) public void testValidateHeaderError(Object receivedValue, Object controlValue) { validator.validateHeader(HttpMessageHeaders.HTTP_QUERY_PARAMS, receivedValue, controlValue, context, validationContext); }