Search in sources :

Example 81 with Errors

use of org.springframework.validation.Errors 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 82 with Errors

use of org.springframework.validation.Errors 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 83 with Errors

use of org.springframework.validation.Errors 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 84 with Errors

use of org.springframework.validation.Errors 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)

Example 85 with Errors

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

the class FieldValidatorTest method validate_shouldFailValidationIfNameIsNull.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsNull() {
    Field ff = new Field();
    ff.setName(null);
    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

Errors (org.springframework.validation.Errors)468 BindException (org.springframework.validation.BindException)387 Test (org.junit.Test)376 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)356 OrderUtilTest (org.openmrs.order.OrderUtilTest)58 DrugOrder (org.openmrs.DrugOrder)56 Date (java.util.Date)53 Test (org.junit.jupiter.api.Test)36 Patient (org.openmrs.Patient)36 TestBean (org.springframework.beans.testfixture.beans.TestBean)33 Calendar (java.util.Calendar)28 Concept (org.openmrs.Concept)25 TestOrder (org.openmrs.TestOrder)23 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)23 OrderType (org.openmrs.OrderType)22 Encounter (org.openmrs.Encounter)21 Obs (org.openmrs.Obs)20 Order (org.openmrs.Order)20 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)19 PageContext (jakarta.servlet.jsp.PageContext)17