use of org.springframework.validation.BindException in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailIfConceptIsNullAndCannotInferItFromDrug.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailIfConceptIsNullAndCannotInferItFromDrug() {
DrugOrder order = new DrugOrder();
Drug drug = Context.getConceptService().getDrug(3);
drug.setConcept(null);
order.setDrug(drug);
Errors errors = new BindException(order, "order");
adminService.validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors("concept"));
}
use of org.springframework.validation.BindException 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.BindException 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.BindException in project openmrs-core by openmrs.
the class AllergyValidatorTest method setUp.
@Before
public void setUp() {
allergy = new Allergy();
errors = new BindException(allergy, "allergy");
}
use of org.springframework.validation.BindException 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());
}
Aggregations