Search in sources :

Example 1 with HL7Source

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");
    }
}
Also used : HL7Source(org.openmrs.hl7.HL7Source)

Example 2 with HL7Source

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"));
}
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 3 with HL7Source

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();
}
Also used : HL7Source(org.openmrs.hl7.HL7Source) Criteria(org.hibernate.Criteria)

Example 4 with HL7Source

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

Aggregations

HL7Source (org.openmrs.hl7.HL7Source)4 Test (org.junit.Test)2 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)2 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 Criteria (org.hibernate.Criteria)1