@Test public void testIsValid_failures() throws Exception { RangerService service = mock(RangerService.class); Assert.assertFalse(_validator.isValid((RangerService)null, _action, _failures)); _utils.checkFailureForMissingValue(_failures, "service"); when(service.getId()).thenReturn(null); checkFailure_isValid(_validator, service, Action.UPDATE, _failures, "missing", "id"); when(service.getId()).thenReturn(7L); for (Action action : cu) { for (String name : new String[] { null, "", " " }) { when(service.getName()).thenReturn(name); checkFailure_isValid(_validator, service, action, _failures, "missing", "name"); } for (String type : new String[] { null, "", " " }) { when(service.getType()).thenReturn(type); checkFailure_isValid(_validator, service, action, _failures, "missing", "type"); } } when(service.getName()).thenReturn("aName"); when(_store.getServiceDefByName("null-type")).thenReturn(null); when(_store.getServiceDefByName("throwing-type")).thenThrow(new Exception()); for (Action action : cu) { for (String type : new String[] { "null-type", "throwing-type" }) { when(service.getType()).thenReturn(type); checkFailure_isValid(_validator, service, action, _failures, "semantic", "type"); } } when(service.getType()).thenReturn("aType"); RangerServiceDef serviceDef = mock(RangerServiceDef.class); when(_store.getServiceDefByName("aType")).thenReturn(serviceDef); RangerService anExistingService = mock(RangerService.class); when(_store.getServiceByName("aName")).thenReturn(anExistingService); checkFailure_isValid(_validator, service, Action.CREATE, _failures, "semantic", "name"); when(_store.getService(7L)).thenReturn(null); when(_store.getServiceByName("aName")).thenReturn(anExistingService); checkFailure_isValid(_validator, service, Action.UPDATE, _failures, "semantic", "id"); when(_store.getService(7L)).thenReturn(anExistingService); RangerService anotherExistingService = mock(RangerService.class); when(anotherExistingService.getId()).thenReturn(49L); when(_store.getServiceByName("aName")).thenReturn(anotherExistingService); checkFailure_isValid(_validator, service, Action.UPDATE, _failures, "semantic", "id/name"); }
boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceValidator.isValid(" + id + ")"); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(action)) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } else if (getService(id) == null) { if (LOG.isDebugEnabled()) { LOG.debug("No service found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceValidator.isValid(" + id + "): " + valid); } return valid; }
RangerServiceValidator extends RangerValidator { boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceValidator.isValid(" + id + ")"); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(action)) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } else if (getService(id) == null) { if (LOG.isDebugEnabled()) { LOG.debug("No service found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceValidator.isValid(" + id + "): " + valid); } return valid; } }
RangerServiceValidator extends RangerValidator { boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceValidator.isValid(" + id + ")"); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(action)) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } else if (getService(id) == null) { if (LOG.isDebugEnabled()) { LOG.debug("No service found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceValidator.isValid(" + id + "): " + valid); } return valid; } RangerServiceValidator(ServiceStore store); }
RangerServiceValidator extends RangerValidator { boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceValidator.isValid(" + id + ")"); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(action)) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } else if (getService(id) == null) { if (LOG.isDebugEnabled()) { LOG.debug("No service found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceValidator.isValid(" + id + "): " + valid); } return valid; } RangerServiceValidator(ServiceStore store); void validate(RangerService service, Action action); boolean isValidString(final Pattern pattern, final String name); }
RangerServiceValidator extends RangerValidator { boolean isValid(Long id, Action action, List<ValidationFailureDetails> failures) { if(LOG.isDebugEnabled()) { LOG.debug("==> RangerServiceValidator.isValid(" + id + ")"); } boolean valid = true; if (action != Action.DELETE) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_UNSUPPORTED_ACTION; failures.add(new ValidationFailureDetailsBuilder() .isAnInternalError() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(action)) .build()); valid = false; } else if (id == null) { ValidationErrorCode error = ValidationErrorCode.SERVICE_VALIDATION_ERR_MISSING_FIELD; failures.add(new ValidationFailureDetailsBuilder() .field("id") .isMissing() .errorCode(error.getErrorCode()) .becauseOf(error.getMessage(id)) .build()); valid = false; } else if (getService(id) == null) { if (LOG.isDebugEnabled()) { LOG.debug("No service found for id[" + id + "]! ok!"); } } if(LOG.isDebugEnabled()) { LOG.debug("<== RangerServiceValidator.isValid(" + id + "): " + valid); } return valid; } RangerServiceValidator(ServiceStore store); void validate(RangerService service, Action action); boolean isValidString(final Pattern pattern, final String name);  }