use of org.openmrs.hl7.HL7Source in project openmrs-core by openmrs.
the class HL7SourceValidator method validate.
/**
* Checks the form object for any inconsistencies/errors
*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail validation if name is null
* @should pass validation if description is null or empty or whitespace
* @should pass validation if all required fields have proper values
* @should pass validation if field lengths are correct
* @should fail validation if field lengths are not correct
*/
@Override
public void validate(Object obj, Errors errors) {
HL7Source hl7Source = (HL7Source) obj;
if (hl7Source == null) {
errors.rejectValue("hl7Source", "error.general");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name");
}
}
use of org.openmrs.hl7.HL7Source 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.openmrs.hl7.HL7Source in project openmrs-core by openmrs.
the class HibernateHL7DAO method getHL7SourceByName.
/**
* @see org.openmrs.hl7.db.HL7DAO#getHL7SourceByName(java.lang.String)
*/
@Override
public HL7Source getHL7SourceByName(String name) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(HL7Source.class);
crit.add(Restrictions.eq("name", name));
return (HL7Source) crit.uniqueResult();
}
use of org.openmrs.hl7.HL7Source in project openmrs-core by openmrs.
the class HL7SourceValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see HL7SourceValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
HL7Source hl7Source = new HL7Source();
hl7Source.setName("name");
Errors errors = new BindException(hl7Source, "hl7Source");
new HL7SourceValidator().validate(hl7Source, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations