@Test void testSuccessfulMapValidation() { PropertyValidator validator = new PropertyValidator(VALIDATION_RULES); Map<String, Object> properties = ImmutableMap.of( "firstProperty", "value", "secondProperty", 1, "thirdProperty", false, "fourthProperty", 1.0, "fifthProperty", Collections.emptyMap()); assertFalse(validator.isValidPropertiesMap(properties)); }
public boolean isValidPropertiesMap(Map<String, Object> properties) { if (skipValidation) { LOG.info("Skipping property validation because no properties were specified."); return true; } if (properties.size() != validationRules.size()) { LOG.info("Properties size does not match the number of validation rules."); return false; } return validationRules.stream() .allMatch(rule -> properties.containsKey(rule.getName()) && rule.getType().isInstance(properties.get(rule.getName()))); }
PropertyValidator { public boolean isValidPropertiesMap(Map<String, Object> properties) { if (skipValidation) { LOG.info("Skipping property validation because no properties were specified."); return true; } if (properties.size() != validationRules.size()) { LOG.info("Properties size does not match the number of validation rules."); return false; } return validationRules.stream() .allMatch(rule -> properties.containsKey(rule.getName()) && rule.getType().isInstance(properties.get(rule.getName()))); } }
PropertyValidator { public boolean isValidPropertiesMap(Map<String, Object> properties) { if (skipValidation) { LOG.info("Skipping property validation because no properties were specified."); return true; } if (properties.size() != validationRules.size()) { LOG.info("Properties size does not match the number of validation rules."); return false; } return validationRules.stream() .allMatch(rule -> properties.containsKey(rule.getName()) && rule.getType().isInstance(properties.get(rule.getName()))); } PropertyValidator(List<PropertyValidationRule> validationRules); }
PropertyValidator { public boolean isValidPropertiesMap(Map<String, Object> properties) { if (skipValidation) { LOG.info("Skipping property validation because no properties were specified."); return true; } if (properties.size() != validationRules.size()) { LOG.info("Properties size does not match the number of validation rules."); return false; } return validationRules.stream() .allMatch(rule -> properties.containsKey(rule.getName()) && rule.getType().isInstance(properties.get(rule.getName()))); } PropertyValidator(List<PropertyValidationRule> validationRules); boolean isValidPropertiesMap(Map<String, Object> properties); }
PropertyValidator { public boolean isValidPropertiesMap(Map<String, Object> properties) { if (skipValidation) { LOG.info("Skipping property validation because no properties were specified."); return true; } if (properties.size() != validationRules.size()) { LOG.info("Properties size does not match the number of validation rules."); return false; } return validationRules.stream() .allMatch(rule -> properties.containsKey(rule.getName()) && rule.getType().isInstance(properties.get(rule.getName()))); } PropertyValidator(List<PropertyValidationRule> validationRules); boolean isValidPropertiesMap(Map<String, Object> properties);  }