use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class OrderValidatorTest method validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime.
/**
* @see OrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfDateActivatedIsBeforeEncountersEncounterDatetime() {
Date encounterDate = new Date();
Date orderDate = DateUtils.addDays(encounterDate, -1);
Encounter encounter = Context.getEncounterService().getEncounter(3);
encounter.setEncounterDatetime(encounterDate);
Order order = new Order();
order.setDateActivated(orderDate);
order.setConcept(Context.getConceptService().getConcept(88));
order.setPatient(Context.getPatientService().getPatient(2));
order.setEncounter(encounter);
order.setOrderer(Context.getProviderService().getProvider(1));
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class OrderValidatorTest method validate_shouldFailValidationIfOrdererIsNull.
/**
* @see OrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfOrdererIsNull() {
Order order = new Order();
order.setConcept(Context.getConceptService().getConcept(88));
order.setPatient(Context.getPatientService().getPatient(2));
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasFieldErrors("discontinued"));
Assert.assertFalse(errors.hasFieldErrors("concept"));
Assert.assertTrue(errors.hasFieldErrors("orderer"));
Assert.assertFalse(errors.hasFieldErrors("patient"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class OrderValidatorTest method validate_shouldNotAllowAFutureDateActivated.
/**
* @see OrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldNotAllowAFutureDateActivated() {
Patient patient = Context.getPatientService().getPatient(7);
TestOrder order = new TestOrder();
order.setPatient(patient);
order.setOrderType(orderService.getOrderTypeByName("Test order"));
order.setEncounter(Context.getEncounterService().getEncounter(3));
order.setConcept(Context.getConceptService().getConcept(5497));
order.setOrderer(Context.getProviderService().getProvider(1));
order.setCareSetting(orderService.getCareSetting(1));
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, 1);
order.setDateActivated(cal.getTime());
Errors errors = new BindException(order, "order");
new OrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("dateActivated"));
Assert.assertEquals("Order.error.dateActivatedInFuture", errors.getFieldError("dateActivated").getCode());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
PatientIdentifier pi = new PatientIdentifier("too long text too long text too long text too long text", new PatientIdentifierType(1), null);
PatientIdentifierType idType = pi.getIdentifierType();
idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
pi.setVoidReason("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(pi, "pi");
new PatientIdentifierValidator().validate(pi, errors);
Assert.assertTrue(errors.hasFieldErrors("identifier"));
Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class PatientValidatorTest method validate_shouldFailValidationIfGenderIsBlank.
/**
* @see org.openmrs.validator.PatientValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfGenderIsBlank() {
Patient pa = new Patient(1);
Errors errors = new BindException(pa, "patient");
validator.validate(pa, errors);
Assert.assertTrue(errors.hasFieldErrors("gender"));
}
Aggregations