@Test public final void test_isValidEnumElements_failures() { List<RangerEnumElementDef> input = _utils.createEnumElementDefs(new String[] { "simple", "kerberos" }); input.add(null); assertFalse(_validator.isValidEnumElements(input, _failures, "anEnum")); _utils.checkFailureForMissingValue(_failures, "enum element", "anEnum"); input = _utils.createEnumElementDefs(new String[] { "simple", "kerberos", null }); _failures.clear(); assertFalse(_validator.isValidEnumElements(input, _failures, "anEnum")); _utils.checkFailureForMissingValue(_failures, "enum element name", "anEnum"); input = _utils.createEnumElementDefs(new String[] { "simple", "kerberos", " " }); _failures.clear(); assertFalse(_validator.isValidEnumElements(input, _failures, "anEnum")); _utils.checkFailureForMissingValue(_failures, "enum element name", "anEnum"); input = _utils.createEnumElementDefs(new String[] { "simple", "kerberos", "kerberos" }); _failures.clear(); assertFalse(_validator.isValidEnumElements(input, _failures, "anEnum")); _utils.checkFailureForSemanticError(_failures, "enum element name", "kerberos"); input = _utils.createEnumElementDefs(new String[] { "simple", "kerberos", "kErbErOs" }); _failures.clear(); assertFalse(_validator.isValidEnumElements(input, _failures, "anEnum")); _utils.checkFailureForSemanticError(_failures, "enum element name", "kErbErOs"); }
boolean isValidEnumElements(List<RangerEnumElementDef> enumElementsDefs, List<ValidationFailureDetails> failures, String enumName) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnumElements(%s, %s)", enumElementsDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumElementsDefs)) { LOG.debug("Enum elements list passed in was null/empty!"); } else { Set<String> elementNames = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumElementDef elementDef : enumElementsDefs) { if (elementDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_ENUM_ELEMENT; failures.add(new ValidationFailureDetailsBuilder() .field("enum element") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isUnique(elementDef.getName(), enumName, elementNames, "enum element name", "enum elements", failures) && valid; valid = isUnique(elementDef.getItemId(), enumName, ids, "enum element itemId", "enum elements", failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnumElements(%s, %s): %s", enumElementsDefs, failures, valid)); } return valid; }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnumElements(List<RangerEnumElementDef> enumElementsDefs, List<ValidationFailureDetails> failures, String enumName) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnumElements(%s, %s)", enumElementsDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumElementsDefs)) { LOG.debug("Enum elements list passed in was null/empty!"); } else { Set<String> elementNames = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumElementDef elementDef : enumElementsDefs) { if (elementDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_ENUM_ELEMENT; failures.add(new ValidationFailureDetailsBuilder() .field("enum element") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isUnique(elementDef.getName(), enumName, elementNames, "enum element name", "enum elements", failures) && valid; valid = isUnique(elementDef.getItemId(), enumName, ids, "enum element itemId", "enum elements", failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnumElements(%s, %s): %s", enumElementsDefs, failures, valid)); } return valid; } }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnumElements(List<RangerEnumElementDef> enumElementsDefs, List<ValidationFailureDetails> failures, String enumName) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnumElements(%s, %s)", enumElementsDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumElementsDefs)) { LOG.debug("Enum elements list passed in was null/empty!"); } else { Set<String> elementNames = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumElementDef elementDef : enumElementsDefs) { if (elementDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_ENUM_ELEMENT; failures.add(new ValidationFailureDetailsBuilder() .field("enum element") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isUnique(elementDef.getName(), enumName, elementNames, "enum element name", "enum elements", failures) && valid; valid = isUnique(elementDef.getItemId(), enumName, ids, "enum element itemId", "enum elements", failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnumElements(%s, %s): %s", enumElementsDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnumElements(List<RangerEnumElementDef> enumElementsDefs, List<ValidationFailureDetails> failures, String enumName) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnumElements(%s, %s)", enumElementsDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumElementsDefs)) { LOG.debug("Enum elements list passed in was null/empty!"); } else { Set<String> elementNames = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumElementDef elementDef : enumElementsDefs) { if (elementDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_ENUM_ELEMENT; failures.add(new ValidationFailureDetailsBuilder() .field("enum element") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isUnique(elementDef.getName(), enumName, elementNames, "enum element name", "enum elements", failures) && valid; valid = isUnique(elementDef.getItemId(), enumName, ids, "enum element itemId", "enum elements", failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnumElements(%s, %s): %s", enumElementsDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action); boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures, final Action action); }
RangerServiceDefValidator extends RangerValidator { boolean isValidEnumElements(List<RangerEnumElementDef> enumElementsDefs, List<ValidationFailureDetails> failures, String enumName) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidEnumElements(%s, %s)", enumElementsDefs, failures)); } boolean valid = true; if (CollectionUtils.isEmpty(enumElementsDefs)) { LOG.debug("Enum elements list passed in was null/empty!"); } else { Set<String> elementNames = new HashSet<>(); Set<Long> ids = new HashSet<>(); for (RangerEnumElementDef elementDef : enumElementsDefs) { if (elementDef == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ENUM_DEF_NULL_ENUM_ELEMENT; failures.add(new ValidationFailureDetailsBuilder() .field("enum element") .subField(enumName) .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(enumName)) .build()); valid = false; } else { valid = isUnique(elementDef.getName(), enumName, elementNames, "enum element name", "enum elements", failures) && valid; valid = isUnique(elementDef.getItemId(), enumName, ids, "enum element itemId", "enum elements", failures) && valid; } } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidEnumElements(%s, %s): %s", enumElementsDefs, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); void validate(final RangerServiceDef serviceDef, final Action action); boolean isValidResources(RangerServiceDef serviceDef, List<ValidationFailureDetails> failures, final Action action);  }