use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class PrivilegeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see PrivilegeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
Privilege priv = new Privilege();
priv.setPrivilege("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
priv.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertTrue(errors.hasFieldErrors("privilege"));
Assert.assertTrue(errors.hasFieldErrors("description"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptNameTagValidatorTest method validate_shouldFailValidationIfConceptNameTagIsNull.
@Test(expected = IllegalArgumentException.class)
public void validate_shouldFailValidationIfConceptNameTagIsNull() {
Errors errors = new BindException(new ConceptNameTag(), "cnt");
new ConceptNameTagValidator().validate(null, errors);
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptNameTagValidatorTest method validate_shouldFailValidationIfTagIsNullOrEmptyOrWhitespace.
/**
* @see ConceptNameTagValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfTagIsNullOrEmptyOrWhitespace() {
ConceptNameTag cnt = new ConceptNameTag();
Errors errors = new BindException(cnt, "cnt");
new ConceptNameTagValidator().validate(cnt, errors);
Assert.assertTrue(errors.hasFieldErrors("tag"));
cnt.setTag("");
errors = new BindException(cnt, "cnt");
new ConceptNameTagValidator().validate(cnt, errors);
Assert.assertTrue(errors.hasFieldErrors("tag"));
cnt.setTag(" ");
errors = new BindException(cnt, "cnt");
new ConceptNameTagValidator().validate(cnt, errors);
Assert.assertTrue(errors.hasFieldErrors("tag"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptSourceValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
ConceptSource conceptSource = new ConceptSource();
conceptSource.setName("New name");
conceptSource.setDescription("Some description");
conceptSource.setHl7Code("Hl7Code");
conceptSource.setRetireReason("RetireReason");
Errors errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class ConceptSourceValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
ConceptSource conceptSource = new ConceptSource();
conceptSource.setName("New name");
conceptSource.setDescription("Some description");
Errors errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations