Search in sources :

Example 56 with BindException

use of org.springframework.validation.BindException in project openmrs-core by openmrs.

the class ConceptSourceValidatorTest method validate_shouldPassValidationIfHl7CodeIsNullOrEmptyOrWhitespace.

@Test
public void validate_shouldPassValidationIfHl7CodeIsNullOrEmptyOrWhitespace() {
    ConceptSource conceptSource = new ConceptSource();
    conceptSource.setName("New name");
    conceptSource.setDescription("Some description");
    conceptSource.setHl7Code(null);
    Errors errors = new BindException(conceptSource, "conceptSource");
    new ConceptSourceValidator().validate(conceptSource, errors);
    Assert.assertFalse(errors.hasFieldErrors("Hl7Code"));
    conceptSource.setHl7Code("");
    errors = new BindException(conceptSource, "conceptSource");
    new ConceptSourceValidator().validate(conceptSource, errors);
    Assert.assertFalse(errors.hasFieldErrors("Hl7Code"));
    conceptSource.setHl7Code("   ");
    errors = new BindException(conceptSource, "conceptSource");
    new ConceptSourceValidator().validate(conceptSource, errors);
    Assert.assertFalse(errors.hasFieldErrors("Hl7Code"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptSource(org.openmrs.ConceptSource) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 57 with BindException

use of org.springframework.validation.BindException 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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptSource(org.openmrs.ConceptSource) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 58 with BindException

use of org.springframework.validation.BindException 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"));
}
Also used : Concept(org.openmrs.Concept) DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 59 with BindException

use of org.springframework.validation.BindException 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());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 60 with BindException

use of org.springframework.validation.BindException 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"));
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Aggregations

BindException (org.springframework.validation.BindException)458 Test (org.junit.Test)402 Errors (org.springframework.validation.Errors)387 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)384 Date (java.util.Date)61 OrderUtilTest (org.openmrs.order.OrderUtilTest)58 DrugOrder (org.openmrs.DrugOrder)56 Patient (org.openmrs.Patient)40 Calendar (java.util.Calendar)30 Concept (org.openmrs.Concept)26 Encounter (org.openmrs.Encounter)25 TestOrder (org.openmrs.TestOrder)23 OrderType (org.openmrs.OrderType)22 Obs (org.openmrs.Obs)20 Order (org.openmrs.Order)20 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)19 Visit (org.openmrs.Visit)19 PatientProgram (org.openmrs.PatientProgram)18 PatientIdentifierType (org.openmrs.PatientIdentifierType)17 Drug (org.openmrs.Drug)15