use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class EncounterRoleValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* {@link org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)}
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
EncounterRole encounterRole = Context.getEncounterService().getEncounterRoleByName("Unknown");
Assert.assertNotNull(encounterRole);
encounterRole.setName("name");
encounterRole.setDescription("desc");
encounterRole.setRetireReason("retireReason");
Errors errors = new BindException(encounterRole, "encounterRole");
new EncounterRoleValidator().validate(encounterRole, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class FieldValidatorTest method validate_shouldFailValidationIfNameIsAllWhitespace.
/**
* @see FieldValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsAllWhitespace() {
Field ff = new Field();
ff.setName(" ");
FieldType ft = new FieldType();
Boolean retired = Boolean.FALSE;
ft.setId(0xdeadcafe);
ff.setFieldType(ft);
ff.setRetired(retired);
Boolean multiple = Boolean.FALSE;
ff.setSelectMultiple(multiple);
Errors errors = new BindException(ff, "name");
new FieldValidator().validate(ff, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class FieldValidatorTest method validate_shouldFailValidationIfSelectMultipleIsNull.
/**
* @see FieldValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfSelectMultipleIsNull() {
Field ff = new Field();
ff.setName("good");
FieldType ft = new FieldType();
ft.setFieldTypeId(0xdeadcafe);
Boolean retired = Boolean.FALSE;
ff.setFieldType(ft);
ff.setName("valid");
ff.setRetired(retired);
Boolean multiple = null;
ff.setSelectMultiple(multiple);
Errors errors = new BindException(ff, "selectMultiple");
new FieldValidator().validate(ff, errors);
Assert.assertTrue(errors.hasFieldErrors("selectMultiple"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class FieldValidatorTest method validate_shouldFailValidationIfNameIsEmpty.
/**
* @see FieldValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsEmpty() {
Field ff = new Field();
ff.setName("");
FieldType ft = new FieldType();
Boolean retired = Boolean.FALSE;
ft.setId(0xdeadcafe);
ff.setFieldType(ft);
ff.setRetired(retired);
Boolean multiple = Boolean.FALSE;
ff.setSelectMultiple(multiple);
Errors errors = new BindException(ff, "name");
new FieldValidator().validate(ff, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class FieldValidatorTest method validate_shouldFailValidationIfNameIsNull.
/**
* @see FieldValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNull() {
Field ff = new Field();
ff.setName(null);
FieldType ft = new FieldType();
Boolean retired = Boolean.FALSE;
ft.setId(0xdeadcafe);
ff.setFieldType(ft);
ff.setRetired(retired);
Boolean multiple = Boolean.FALSE;
ff.setSelectMultiple(multiple);
Errors errors = new BindException(ff, "name");
new FieldValidator().validate(ff, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
Aggregations