use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfDoseUnitsIsNotADoseUnitConcept() {
Concept concept = Context.getConceptService().getConcept(3);
assertThat(concept, not(isIn(Context.getOrderService().getDrugDosingUnits())));
DrugOrder order = new DrugOrder();
order.setDosingType(FreeTextDosingInstructions.class);
order.setDuration(5);
order.setDurationUnits(concept);
order.setDose(1.0);
order.setDoseUnits(concept);
order.setQuantity(30.0);
order.setQuantityUnits(concept);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("doseUnits"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfDurationUnitsIsNotADurationUnitConcept.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfDurationUnitsIsNotADurationUnitConcept() {
Concept concept = Context.getConceptService().getConcept(3);
assertThat(concept, not(isIn(Context.getOrderService().getDurationUnits())));
DrugOrder order = new DrugOrder();
order.setDosingType(FreeTextDosingInstructions.class);
order.setDuration(5);
order.setDurationUnits(concept);
order.setDose(1.0);
order.setDoseUnits(concept);
order.setQuantity(30.0);
order.setQuantityUnits(concept);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("durationUnits"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class AllergyValidatorTest method validate_shouldPassForAValidAllergy.
/**
* @see AllergyValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassForAValidAllergy() {
Allergies allergies = new Allergies();
Concept aspirin = new Concept();
Allergen allergen1 = new Allergen(AllergenType.DRUG, aspirin, null);
allergies.add(new Allergy(null, allergen1, null, null, null));
when(ps.getAllergies(any(Patient.class))).thenReturn(allergies);
Allergen anotherAllergen = new Allergen(AllergenType.DRUG, new Concept(), null);
Allergy allergy = new Allergy(mock(Patient.class), anotherAllergen, null, null, null);
Errors errors = new BindException(allergy, "allergy");
validator.validate(allergy, errors);
assertFalse(errors.hasErrors());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class CohortValidatorTest method validate_shouldPassIfMembershipStartDateIsAfterEndDate.
@Test
public void validate_shouldPassIfMembershipStartDateIsAfterEndDate() throws Exception {
Cohort cohort = new Cohort(2);
CohortMembership membership = new CohortMembership(patient.getPatientId());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = dateFormat.parse("2016-11-01 00:00:00");
Date endDate = dateFormat.parse("2015-01-01 00:00:00");
membership.setStartDate(startDate);
membership.setEndDate(endDate);
Errors errors = new BindException(cohort, "cohort");
new CohortValidator().validate(cohort, errors);
Assert.assertFalse(errors.hasFieldErrors("memberships"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class ConceptClassValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see ConceptClassValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
ConceptClass cc = new ConceptClass();
cc.setName("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");
cc.setDescription("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");
cc.setRetireReason("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(cc, "cc");
new ConceptClassValidator().validate(cc, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Aggregations