@Test public final void test_isValidName_create() throws Exception { Long id = null; String name = "existing-service"; when(_serviceDef.getName()).thenReturn(name); when(_store.getServiceDefByName(name)).thenReturn(null); assertTrue(_validator.isValidServiceDefName(name, id, Action.CREATE, _failures)); assertTrue(_failures.isEmpty()); RangerServiceDef existingServiceDef = mock(RangerServiceDef.class); when(_store.getServiceDefByName(name)).thenReturn(existingServiceDef); _failures.clear(); assertFalse(_validator.isValidServiceDefName(name, id, Action.CREATE, _failures)); _utils.checkFailureForSemanticError(_failures, "name"); }
boolean isValidServiceDefName(String name, Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s)", name, id, action, failures)); } boolean valid = true; if (StringUtils.isBlank(name)) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_NAME; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else { RangerServiceDef otherServiceDef = getServiceDef(name); if (otherServiceDef != null && action == Action.CREATE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_SERVICE_DEF_NAME_CONFICT; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else if (otherServiceDef != null && !Objects.equals(id, otherServiceDef.getId())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ID_NAME_CONFLICT; failures.add(new ValidationFailureDetailsBuilder() .field("id/name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name, otherServiceDef.getId())) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s): %s", name, id, action, failures, valid)); } return valid; }
RangerServiceDefValidator extends RangerValidator { boolean isValidServiceDefName(String name, Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s)", name, id, action, failures)); } boolean valid = true; if (StringUtils.isBlank(name)) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_NAME; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else { RangerServiceDef otherServiceDef = getServiceDef(name); if (otherServiceDef != null && action == Action.CREATE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_SERVICE_DEF_NAME_CONFICT; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else if (otherServiceDef != null && !Objects.equals(id, otherServiceDef.getId())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ID_NAME_CONFLICT; failures.add(new ValidationFailureDetailsBuilder() .field("id/name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name, otherServiceDef.getId())) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s): %s", name, id, action, failures, valid)); } return valid; } }
RangerServiceDefValidator extends RangerValidator { boolean isValidServiceDefName(String name, Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s)", name, id, action, failures)); } boolean valid = true; if (StringUtils.isBlank(name)) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_NAME; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else { RangerServiceDef otherServiceDef = getServiceDef(name); if (otherServiceDef != null && action == Action.CREATE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_SERVICE_DEF_NAME_CONFICT; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else if (otherServiceDef != null && !Objects.equals(id, otherServiceDef.getId())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ID_NAME_CONFLICT; failures.add(new ValidationFailureDetailsBuilder() .field("id/name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name, otherServiceDef.getId())) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s): %s", name, id, action, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); }
RangerServiceDefValidator extends RangerValidator { boolean isValidServiceDefName(String name, Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s)", name, id, action, failures)); } boolean valid = true; if (StringUtils.isBlank(name)) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_NAME; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else { RangerServiceDef otherServiceDef = getServiceDef(name); if (otherServiceDef != null && action == Action.CREATE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_SERVICE_DEF_NAME_CONFICT; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else if (otherServiceDef != null && !Objects.equals(id, otherServiceDef.getId())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ID_NAME_CONFLICT; failures.add(new ValidationFailureDetailsBuilder() .field("id/name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name, otherServiceDef.getId())) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s): %s", name, id, action, 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 isValidServiceDefName(String name, Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s)", name, id, action, failures)); } boolean valid = true; if (StringUtils.isBlank(name)) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_NAME; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else { RangerServiceDef otherServiceDef = getServiceDef(name); if (otherServiceDef != null && action == Action.CREATE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_SERVICE_DEF_NAME_CONFICT; failures.add(new ValidationFailureDetailsBuilder() .field("name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name)) .build()); valid = false; } else if (otherServiceDef != null && !Objects.equals(id, otherServiceDef.getId())) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_ID_NAME_CONFLICT; failures.add(new ValidationFailureDetailsBuilder() .field("id/name") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(name, otherServiceDef.getId())) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefName(%s, %s, %s, %s): %s", name, id, action, 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);  }