@Test public final void test_isValidServiceDefId_happyPath() throws Exception { assertTrue(_validator.isValidServiceDefId(null, Action.CREATE, _failures)); assertTrue(_failures.isEmpty()); long id = 7; when(_serviceDef.getId()).thenReturn(id); RangerServiceDef serviceDefFromDb = mock(RangerServiceDef.class); when(serviceDefFromDb.getId()).thenReturn(id); when(_store.getServiceDef(id)).thenReturn(serviceDefFromDb); assertTrue(_validator.isValidServiceDefId(id, Action.UPDATE, _failures)); assertTrue(_failures.isEmpty()); }
boolean isValidServiceDefId(Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action == Action.UPDATE) { if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_EMPTY_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else if (getServiceDef(id) == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s): %s", id, action, failures, valid)); } return valid; }
RangerServiceDefValidator extends RangerValidator { boolean isValidServiceDefId(Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action == Action.UPDATE) { if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_EMPTY_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else if (getServiceDef(id) == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s): %s", id, action, failures, valid)); } return valid; } }
RangerServiceDefValidator extends RangerValidator { boolean isValidServiceDefId(Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action == Action.UPDATE) { if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_EMPTY_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else if (getServiceDef(id) == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s): %s", id, action, failures, valid)); } return valid; } RangerServiceDefValidator(ServiceStore store); }
RangerServiceDefValidator extends RangerValidator { boolean isValidServiceDefId(Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action == Action.UPDATE) { if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_EMPTY_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else if (getServiceDef(id) == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s): %s", 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 isValidServiceDefId(Long id, final Action action, final List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action == Action.UPDATE) { if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_EMPTY_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage()) .build()); valid = false; } else if (getServiceDef(id) == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_DEF_VALIDATION_ERR_INVALID_SERVICE_DEF_ID; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isSemanticallyIncorrect() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerServiceDefValidator.isValidServiceDefId(%s, %s, %s): %s", 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);  }