@Test public void test_isValid_happyPath() throws Exception { Object[][] serviceDefInput = new Object[][] { { "param1", true }, { "param2", true }, { "param3", false }, { "param4", false }, { "param5", true }, }; List<RangerServiceConfigDef> configDefs = _utils.createServiceConditionDefs(serviceDefInput); RangerServiceDef serviceDef = mock(RangerServiceDef.class); when(serviceDef.getConfigs()).thenReturn(configDefs); RangerService service = mock(RangerService.class); when(service.getName()).thenReturn("aName"); when(service.getDisplayName()).thenReturn("aDisplayName"); when(service.getType()).thenReturn("aType"); String[] configs = new String[] { "param1", "param2", "param3", "param5", "param6" }; Map<String, String> configMap = _utils.createMap(configs); when(service.getConfigs()).thenReturn(configMap); when(_store.getServiceByName("aName")).thenReturn(null); when(_store.getServiceDefByName("aType")).thenReturn(serviceDef); Assert.assertTrue(_validator.isValid(service, Action.CREATE, _failures)); when(service.getId()).thenReturn(7L); RangerService existingService = mock(RangerService.class); when(existingService.getId()).thenReturn(Long.valueOf(7L)); when(_store.getService(7L)).thenReturn(existingService); when(_store.getServiceByName("aName")).thenReturn(existingService); Assert.assertTrue(_validator.isValid(service, Action.UPDATE, _failures)); when(_store.getServiceByName("aName")).thenReturn(null); Assert.assertTrue(_validator.isValid(service, Action.UPDATE, _failures)); }
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);  }