@Test public void testIsValidServiceNameUpdationWithSpaceCharacter() throws Exception{ String serviceName = "Cluster 1_c1_yarn"; String serviceDisplayName = serviceName; ValidationErrorCode vErrCod = ValidationErrorCode.SERVICE_VALIDATION_ERR_SPECIAL_CHARACTERS_SERVICE_NAME; String errorMessage = vErrCod.getMessage(serviceName); int errorCode = vErrCod.getErrorCode(); RangerService rangerService = new RangerService(); rangerService.setId(1L); rangerService.setName(serviceName); rangerService.setDisplayName(serviceDisplayName); rangerService.setType("yarn"); rangerService.setTagService(""); RangerServiceConfigDef configDef = new RangerServiceConfigDef(); configDef.setMandatory(true); List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>(); listRangerServiceConfigDef.add(configDef); configDef.setName("myconfig1"); Map<String,String> testMap = new HashMap<String, String>(); testMap.put("myconfig1", "myconfig1"); rangerService.setConfigs(testMap); RangerServiceDef rangerServiceDef = new RangerServiceDef(); rangerServiceDef.setConfigs(listRangerServiceConfigDef); String serviceNameWithoutSpace = "Cluster_1_c1_yarn"; String serviceDisplayNameWithoutSpace = serviceNameWithoutSpace; RangerService rangerServiceWithoutSpace = new RangerService(); rangerServiceWithoutSpace.setId(1L); rangerServiceWithoutSpace.setName(serviceNameWithoutSpace); rangerServiceWithoutSpace.setDisplayName(serviceDisplayNameWithoutSpace); rangerServiceWithoutSpace.setType("yarn"); rangerServiceWithoutSpace.setTagService(""); when(_store.getService(1L)).thenReturn(rangerServiceWithoutSpace); when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef); boolean valid = _validator.isValid(rangerService, Action.UPDATE, _failures); ValidationFailureDetails failureMessage = _failures.get(0); Assert.assertFalse(valid); Assert.assertEquals("name",failureMessage.getFieldName()); Assert.assertEquals(errorMessage, failureMessage._reason); Assert.assertEquals(errorCode, failureMessage._errorCode); when(_store.getService(1L)).thenReturn(rangerService); when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef); boolean validWithSpace = _validator.isValid(rangerService, Action.UPDATE, _failures); Assert.assertTrue(validWithSpace); }
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);  }