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());
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations