use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationAttributeTypeValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.
/**
* @see LocationAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
LocationAttributeType type = new LocationAttributeType();
type.setName(null);
type.setDescription("description");
Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
type.setName("");
errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
type.setName(" ");
errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationAttributeTypeValidatorTest method validate_shouldPassEditingLocationAttributeTypeName.
/**
* @see LocationAttributeTypeValidator#validate(Object, Errors)
*/
@Test
public void validate_shouldPassEditingLocationAttributeTypeName() {
LocationAttributeType et = Context.getLocationService().getLocationAttributeTypeByName("Audit Date");
Assert.assertNotNull(et);
Errors errors = new BindException(et, "locationAttributeType");
new LocationAttributeTypeValidator().validate(et, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class LocationAttributeTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see LocationAttributeTypeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
LocationAttributeType type = new LocationAttributeType();
type.setName("name");
type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
type.setDescription("description");
type.setRetireReason("retireReason");
Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class VisitValidatorTest method validate_shouldFailIfPatientIsNotSet.
/**
* @see VisitValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfPatientIsNotSet() {
VisitService vs = Context.getVisitService();
Visit visit = new Visit();
visit.setVisitType(vs.getVisitType(1));
visit.setStartDatetime(new Date());
Errors errors = new BindException(visit, "visit");
new VisitValidator().validate(visit, errors);
assertTrue(errors.hasFieldErrors("patient"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class VisitValidatorTest method validate_shouldAcceptAVisitIfStopDateTimeFallsIntoAnotherVoidedVisitOfTheSamePatient.
/**
* @see VisitValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldAcceptAVisitIfStopDateTimeFallsIntoAnotherVoidedVisitOfTheSamePatient() {
Calendar calendar = Calendar.getInstance();
calendar.set(2014, Calendar.FEBRUARY, 2);
Visit visit = makeVisit(42);
visit.setStartDatetime(calendar.getTime());
calendar.set(2014, Calendar.FEBRUARY, 8);
visit.setStopDatetime(calendar.getTime());
assertTrue(patientHasVoidedVisit(visit.getPatient(), DATE_TIME_2014_02_05_00_00_00_0, DATE_TIME_2014_02_11_00_00_00_0));
Errors errors = new BindException(visit, "visit");
new VisitValidator().validate(visit, errors);
assertFalse(errors.hasFieldErrors("stopDatetime"));
}
Aggregations