use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class ConceptSourceValidatorTest method validate_shouldFailValidationIfDescriptionIsNullOrEmptyOrWhitespace.
/**
* @see ConceptSourceValidator#validate(Object, Errors)
*/
@Test
public void validate_shouldFailValidationIfDescriptionIsNullOrEmptyOrWhitespace() {
ConceptSource conceptSource = new ConceptSource();
conceptSource.setName("New name");
conceptSource.setDescription(null);
Errors errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertTrue(errors.hasFieldErrors("description"));
conceptSource.setDescription("");
errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertTrue(errors.hasFieldErrors("description"));
conceptSource.setDescription(" ");
errors = new BindException(conceptSource, "conceptSource");
new ConceptSourceValidator().validate(conceptSource, errors);
Assert.assertTrue(errors.hasFieldErrors("description"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfQuantityUnitsItNotAQuantityUnitConcept.
/**
* @see DrugOrderValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfQuantityUnitsItNotAQuantityUnitConcept() {
Concept concept = Context.getConceptService().getConcept(3);
assertThat(concept, not(isIn(Context.getOrderService().getDrugDispensingUnits())));
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("quantityUnits"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet.
@Test
public void saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet() {
Patient patient = Context.getPatientService().getPatient(7);
CareSetting careSetting = Context.getOrderService().getCareSetting(2);
OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
Context.getAdministrationService().saveGlobalProperty(gp);
// place drug order
DrugOrder order = new DrugOrder();
Encounter encounter = Context.getEncounterService().getEncounter(3);
order.setEncounter(encounter);
order.setPatient(patient);
order.setCareSetting(careSetting);
order.setOrderer(Context.getProviderService().getProvider(1));
order.setDateActivated(encounter.getEncounterDatetime());
order.setOrderType(orderType);
order.setDosingType(FreeTextDosingInstructions.class);
order.setInstructions("None");
order.setDosingInstructions("Test Instruction");
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertTrue(errors.hasFieldErrors());
assertEquals("DrugOrder.error.drugIsRequired", errors.getFieldError("drug").getCode());
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldNotValidateACustomDosingTypeAgainstAnyOtherDosingTypeValidation.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldNotValidateACustomDosingTypeAgainstAnyOtherDosingTypeValidation() {
DrugOrder order = new DrugOrder();
order.setDosingType(CustomDosingInstructions.class);
order.setDosingInstructions(null);
Errors errors = new BindException(order, "order");
new DrugOrderValidator().validate(order, errors);
Assert.assertFalse(errors.hasFieldErrors("dosingInstructions"));
}
use of org.springframework.validation.Errors in project openmrs-core by openmrs.
the class DrugOrderValidatorTest method validate_shouldFailValidationIfNumberOfRefillsIsNullForOutpatientCareSetting.
/**
* @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldFailValidationIfNumberOfRefillsIsNullForOutpatientCareSetting() {
DrugOrder OutpatientOrder = new DrugOrder();
OutpatientOrder.setCareSetting(Context.getOrderService().getCareSetting(1));
OutpatientOrder.setNumRefills(null);
Errors OutpatientOrderErrors = new BindException(OutpatientOrder, "order");
new DrugOrderValidator().validate(OutpatientOrder, OutpatientOrderErrors);
Assert.assertTrue(OutpatientOrderErrors.hasFieldErrors("numRefills"));
DrugOrder inPatientOrder = new DrugOrder();
inPatientOrder.setCareSetting(Context.getOrderService().getCareSetting(2));
inPatientOrder.setNumRefills(null);
Errors InpatientOrderErrors = new BindException(inPatientOrder, "order");
new DrugOrderValidator().validate(inPatientOrder, InpatientOrderErrors);
Assert.assertFalse(InpatientOrderErrors.hasFieldErrors("numRefills"));
}
Aggregations