Search in sources :

Example 81 with BindException

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

the class DrugOrderValidatorTest method validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType.

/**
 * @see DrugOrderValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfDoseIsNullForSimpleDosingInstructionsDosingType() {
    DrugOrder order = new DrugOrder();
    order.setDosingType(SimpleDosingInstructions.class);
    order.setDose(null);
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors("dose"));
}
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)

Example 82 with BindException

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

the class EncounterRoleValidatorTest method validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace.

/**
 * @see org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailIfTheNameOfTheEncounterRoleIsNullEmptyOrWhitespace() {
    EncounterRole encounterRoleNo1 = new EncounterRole();
    encounterRoleNo1.setName(null);
    Errors errorsNo1 = new BindException(encounterRoleNo1, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo1, errorsNo1);
    Assert.assertTrue(errorsNo1.hasFieldErrors("name"));
    EncounterRole encounterRoleNo2 = new EncounterRole();
    encounterRoleNo2.setName("");
    Errors errorsNo2 = new BindException(encounterRoleNo2, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo2, errorsNo2);
    Assert.assertTrue(errorsNo2.hasFieldErrors("name"));
    EncounterRole encounterRoleNo3 = new EncounterRole();
    encounterRoleNo3.setName("  ");
    Errors errorsNo3 = new BindException(encounterRoleNo3, "encounterRole");
    new EncounterRoleValidator().validate(encounterRoleNo3, errorsNo3);
    Assert.assertTrue(errorsNo3.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) EncounterRole(org.openmrs.EncounterRole) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 83 with BindException

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

the class EncounterRoleValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * {@link org.openmrs.validator.EncounterRoleValidator#validate(Object, org.springframework.validation.Errors)}
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    EncounterRole encounterRole = Context.getEncounterService().getEncounterRoleByName("Unknown");
    Assert.assertNotNull(encounterRole);
    encounterRole.setName("name");
    encounterRole.setDescription("desc");
    encounterRole.setRetireReason("retireReason");
    Errors errors = new BindException(encounterRole, "encounterRole");
    new EncounterRoleValidator().validate(encounterRole, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) EncounterRole(org.openmrs.EncounterRole) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 84 with BindException

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

the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsAfterCurrentDateTime.

/**
 * @see EncounterValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfEncounterDateTimeIsAfterCurrentDateTime() {
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    // Set encounter dateTime after the current dateTime.
    Calendar calendar = new GregorianCalendar();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    Date tomorrowDate = calendar.getTime();
    encounter.setEncounterDatetime(tomorrowDate);
    errors = new BindException(encounter, "encounter");
    encounterValidator.validate(encounter, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime"));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 85 with BindException

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

the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsAfterVisitStopDateTime.

/**
 * @see EncounterValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfEncounterDateTimeIsAfterVisitStopDateTime() {
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    Visit visit = Context.getVisitService().getVisit(1);
    visit.setPatient(encounter.getPatient());
    encounter.setVisit(visit);
    // Set encounter dateTime to after the visit stopDateTime.
    visit.setStopDatetime(new Date());
    Date date = new Date(visit.getStopDatetime().getTime() + 1);
    encounter.setEncounterDatetime(date);
    errors = new BindException(encounter, "encounter");
    encounterValidator.validate(encounter, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime"));
}
Also used : Visit(org.openmrs.Visit) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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