### Question:
VirtualDataSourceValidator extends DefaultResourceValidator { public boolean validateSubDsId(String value, String nameField, ValidationErrors errors) { if(!validateNameString(value, nameField, errors)) { return false; } if(subDsIdInvalidChars.matcher(value).find()) { errors.add(new ValidationErrorImpl(getErrorMessagePrefix() + "error.invalid.chars", null, "Only letters, digits and underscore allowed in subDsId", nameField)); } if(!StringUtils.isEmpty(value)) { char firstChar = value.charAt(0); if(firstChar == '_' || Character.isDigit(firstChar)) { errors.add(new ValidationErrorImpl(getErrorMessagePrefix() + "error.first.letter.required", null, "Should start with letter", nameField)); } } return true; }  boolean validateSubDsId(String value, String nameField, ValidationErrors errors); @Override ValidationErrors validate(Resource resource, ValidationErrorFilter filter);  }### Answer:
@Test public void validateSubDsIdOk() { ValidationErrors errors = new ValidationErrorsImpl(); validator.validateSubDsId("subDatasource", "subDsId", errors); Assert.assertTrue("Should be no validation errors", errors.getErrors().isEmpty()); Assert.assertFalse("Errors flag should be false", errors.isError()); }
@Test public void validateSubDsIdInvalidDotFail() { ValidationErrors errors = new ValidationErrorsImpl(); validator.validateSubDsId("sub.Datasource", "subDsId", errors); Assert.assertEquals("Expected one validation error", 1, errors.getErrors().size()); Assert.assertTrue("Errors flag should be true", errors.isError()); Assert.assertEquals("Error code", "error.invalid.chars", ((ValidationErrorImpl)errors.getErrors().get(0)).getErrorCode()); }
@Test public void validateSubDsIdInvalidStartWithUnderscoreFail() { ValidationErrors errors = new ValidationErrorsImpl(); validator.validateSubDsId("_subDatasource", "subDsId", errors); Assert.assertEquals("Expected one validation error", 1, errors.getErrors().size()); Assert.assertTrue("Errors flag should be true", errors.isError()); Assert.assertEquals("Error code", "error.first.letter.required", ((ValidationErrorImpl)errors.getErrors().get(0)).getErrorCode()); }