@Test public final void testIsValid_long() throws Exception { Assert.assertFalse(_validator.isValid(3L, Action.CREATE, _failures)); _utils.checkFailureForInternalError(_failures); _failures.clear(); _failures.clear(); Assert.assertFalse(_validator.isValid((Long)null, Action.DELETE, _failures)); _utils.checkFailureForMissingValue(_failures, "id"); when(_store.getPolicy(1L)).thenReturn(null); when(_store.getPolicy(2L)).thenThrow(new Exception()); RangerPolicy existingPolicy = mock(RangerPolicy.class); when(_store.getPolicy(3L)).thenReturn(existingPolicy); _failures.clear(); Assert.assertTrue(_validator.isValid(1L, Action.DELETE, _failures)); Assert.assertTrue(_failures.isEmpty()); _failures.clear(); Assert.assertTrue(_validator.isValid(2L, Action.DELETE, _failures)); Assert.assertTrue(_failures.isEmpty()); _failures.clear(); Assert.assertTrue(_validator.isValid(3L, Action.DELETE, _failures)); Assert.assertTrue(_failures.isEmpty()); }
@Override boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .becauseOf("policy id was null/missing") .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage("id")) .build()); valid = false; } else if (policyExists(id)) { if (LOG.isDebugEnabled()) { LOG.debug("No policy found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", id, action, failures, valid)); } return valid; }
RangerPolicyValidator extends RangerValidator { @Override boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .becauseOf("policy id was null/missing") .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage("id")) .build()); valid = false; } else if (policyExists(id)) { if (LOG.isDebugEnabled()) { LOG.debug("No policy found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", id, action, failures, valid)); } return valid; } }
RangerPolicyValidator extends RangerValidator { @Override boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .becauseOf("policy id was null/missing") .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage("id")) .build()); valid = false; } else if (policyExists(id)) { if (LOG.isDebugEnabled()) { LOG.debug("No policy found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", id, action, failures, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); }
RangerPolicyValidator extends RangerValidator { @Override boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .becauseOf("policy id was null/missing") .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage("id")) .build()); valid = false; } else if (policyExists(id)) { if (LOG.isDebugEnabled()) { LOG.debug("No policy found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", id, action, failures, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); void validate(RangerPolicy policy, Action action, boolean isAdmin); }
RangerPolicyValidator extends RangerValidator { @Override boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug(String.format("==> RangerPolicyValidator.isValid(%s, %s, %s)", id, action, failures)); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .becauseOf(error.getMessage()) .errorCode(error.getErrorCode()) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.POLICY_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .becauseOf("policy id was null/missing") .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage("id")) .build()); valid = false; } else if (policyExists(id)) { if (LOG.isDebugEnabled()) { LOG.debug("No policy found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug(String.format("<== RangerPolicyValidator.isValid(%s, %s, %s): %s", id, action, failures, valid)); } return valid; } RangerPolicyValidator(ServiceStore store); void validate(RangerPolicy policy, Action action, boolean isAdmin);  }