Search in sources :

Example 91 with BindException

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

Example 92 with BindException

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

the class FieldValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    Field ff = new Field();
    FieldType ft = new FieldType();
    Boolean retired = Boolean.FALSE;
    ft.setId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setName("name");
    ff.setRetired(retired);
    Boolean multiple = Boolean.FALSE;
    ff.setSelectMultiple(multiple);
    ff.setTableName("tableName");
    ff.setAttributeName("attributeName");
    ff.setRetireReason("retireReason");
    Errors errors = new BindException(ff, "field");
    new FieldValidator().validate(ff, errors);
    Assert.assertFalse(errors.hasErrors());
}
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 93 with BindException

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

the class FieldValidatorTest method validate_shouldFailValidationIfRetiredIsNull.

/**
 * @see FieldValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfRetiredIsNull() {
    Field ff = new Field();
    ff.setName("good");
    FieldType ft = new FieldType();
    ft.setFieldTypeId(0xdeadcafe);
    ff.setFieldType(ft);
    ff.setName("valid");
    Boolean retired = null;
    ff.setRetired(retired);
    Boolean multiple = Boolean.TRUE;
    ff.setSelectMultiple(multiple);
    Errors errors = new BindException(ff, "retired");
    new FieldValidator().validate(ff, errors);
    Assert.assertTrue(errors.hasFieldErrors("retired"));
}
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 94 with BindException

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

the class HL7SourceValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see HL7SourceValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    HL7Source hl7Source = new HL7Source();
    hl7Source.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(hl7Source, "hl7Source");
    new HL7SourceValidator().validate(hl7Source, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) HL7Source(org.openmrs.hl7.HL7Source) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 95 with BindException

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

the class LocationAttributeTypeValidatorTest method validate_shouldFailIfLocationAttributeTypeNameIsDuplicate.

/**
 * @see LocationAttributeTypeValidator#validate(Object, Errors)
 */
@Test
public void validate_shouldFailIfLocationAttributeTypeNameIsDuplicate() {
    Assert.assertNotNull(Context.getLocationService().getLocationAttributeTypeByName("Audit Date"));
    LocationAttributeType type = new LocationAttributeType();
    type.setName("Audit Date");
    type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
    Errors errors = new BindException(type, "locationAttributeType");
    new LocationAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) LocationAttributeType(org.openmrs.LocationAttributeType) 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