use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType() {
DrugOrder order = new DrugOrder();
order.setDosingType(SimpleDosingInstructions.class);
order.setDose(null);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("dose"));
}
use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class EncounterRoleValidatorTest method validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace.
/**
* @see org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace() {
EncounterRole encounterRoleNo1 = new EncounterRole();
encounterRoleNo1.setName(null);
Errors errorsNo1 = new BindException(encounterRoleNo1, "encounterRole");
new EncounterRoleValidator().validate(encounterRoleNo1, errorsNo1);
Assert.assertTrue(errorsNo1.hasFieldErrors("name"));
EncounterRole encounterRoleNo2 = new EncounterRole();
encounterRoleNo2.setName("");
Errors errorsNo2 = new BindException(encounterRoleNo2, "encounterRole");
new EncounterRoleValidator().validate(encounterRoleNo2, errorsNo2);
Assert.assertTrue(errorsNo2.hasFieldErrors("name"));
EncounterRole encounterRoleNo3 = new EncounterRole();
encounterRoleNo3.setName(" ");
Errors errorsNo3 = new BindException(encounterRoleNo3, "encounterRole");
new EncounterRoleValidator().validate(encounterRoleNo3, errorsNo3);
Assert.assertTrue(errorsNo3.hasFieldErrors("name"));
}
use of org.springframework.validation.BindException 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.BindException in project openmrs-core by openmrs.
the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsAfterCurrentDateTime.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEncounterDateTimeIsAfterCurrentDateTime() {
Encounter encounter = Context.getEncounterService().getEncounter(3);
// Set encounter dateTime after the current dateTime.
Calendar calendar = new GregorianCalendar();
calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrowDate = calendar.getTime();
encounter.setEncounterDatetime(tomorrowDate);
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 validate_shouldFailIfEncounterDateTimeIsAfterVisitStopDateTime.
/**
* @see EncounterValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEncounterDateTimeIsAfterVisitStopDateTime() {
Encounter encounter = Context.getEncounterService().getEncounter(3);
Visit visit = Context.getVisitService().getVisit(1);
visit.setPatient(encounter.getPatient());
encounter.setVisit(visit);
// Set encounter dateTime to after the visit stopDateTime.
visit.setStopDatetime(new Date());
Date date = new Date(visit.getStopDatetime().getTime() + 1);
encounter.setEncounterDatetime(date);
errors = new BindException(encounter, "encounter");
encounterValidator.validate(encounter, errors);
Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime"));
}
Aggregations