Search in sources :

Example 86 with BindException

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

the class EncounterValidatorTest method validate_shouldFailIfEncounterDateTimeIsBeforeVisitStartDateTime.

/**
 * @see EncounterValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfEncounterDateTimeIsBeforeVisitStartDateTime() {
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    Visit visit = Context.getVisitService().getVisit(1);
    visit.setPatient(encounter.getPatient());
    encounter.setVisit(visit);
    // Set encounter dateTime to before the visit startDateTime.
    Date date = new Date(visit.getStartDatetime().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)

Example 87 with BindException

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

the class EncounterValidatorTest method setUp.

@Before
public void setUp() {
    encounterValidator = new EncounterValidator();
    encounter = new Encounter();
    errors = new BindException(encounter, "encounter");
}
Also used : Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) Before(org.junit.Before)

Example 88 with BindException

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

the class FieldValidatorTest method validate_shouldFailValidationIfNameIsAllWhitespace.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsAllWhitespace() {
    Field ff = new Field();
    ff.setName("    ");
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "name");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Field(org.openmrs.Field) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 89 with BindException

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

the class FieldValidatorTest method validate_shouldFailValidationIfSelectMultipleIsNull.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfSelectMultipleIsNull() {
    Field ff = new Field();
    ff.setName("good");
    FieldType ft = new FieldType();
    ft.setFieldTypeId(0xdeadcafe);
    Boolean retired = Boolean.FALSE;
    ff.setFieldType(ft);
    ff.setName("valid");
    ff.setRetired(retired);
    Boolean multiple = null;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "selectMultiple");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("selectMultiple"));
}
Also used : Field(org.openmrs.Field) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 90 with BindException

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

the class FieldValidatorTest method validate_shouldFailValidationIfNameIsEmpty.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsEmpty() {
    Field ff = new Field();
    ff.setName("");
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "name");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Field(org.openmrs.Field) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) FieldType(org.openmrs.FieldType) 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