Search in sources :

Example 86 with Errors

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

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

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

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

Example 90 with Errors

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

the class LocationAttributeTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see LocationAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    LocationAttributeType type = new LocationAttributeType();
    type.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");
    type.setDatatypeClassname("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");
    type.setDescription("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 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 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 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");
    type.setPreferredHandlerClassname("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");
    type.setRetireReason("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(type, "type");
    new LocationAttributeTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("datatypeClassname"));
    Assert.assertTrue(errors.hasFieldErrors("description"));
    Assert.assertTrue(errors.hasFieldErrors("preferredHandlerClassname"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
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

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