use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsBeforeVisitStartDateTime.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEncounterDateTimeIsBeforeVisitStartDateTime() {
Encounter encounter = Context.getEncounterService().getEncounter(3);
Visit visit = Context.getVisitService().getVisit(1);
visit.setPatient(encounter.getPatient());
encounter.setVisit(visit);
// Set encounter dateTime to before the visit startDateTime.
Date date = new Date(visit.getStartDatetime().getTime() - 1);
encounter.setEncounterDatetime(date);
errors = new BindException(encounter, "encounter");
encounterValidator.validate(encounter, errors);
Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class EncounterValidatorTest method setUp.
@Before
public void setUp() {
encounterValidator = new EncounterValidator();
encounter = new Encounter();
errors = new BindException(encounter, "encounter");
}
use of org.springframework.validation.BindException 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.BindException 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.BindException 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"));
}
Aggregations