use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormValidatorTest method validate_shouldFailValidationIfRetiredReasonIsEmpty.
/**
* @see FormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfRetiredReasonIsEmpty() {
Form form = new Form();
form.setName("test");
form.setVersion("1.0");
form.setRetired(true);
form.setRetireReason("");
Errors errors = new BindException(form, "form");
new FormValidator().validate(form, errors);
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormValidatorTest method validate_shouldFailValidationIfVersionIsNull.
/**
* @see FormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfVersionIsNull() {
Form form = new Form();
form.setName("test");
Errors errors = new BindException(form, "form");
new FormValidator().validate(form, errors);
Assert.assertFalse(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("version"));
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see FormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Form form = new Form();
form.setName("name");
form.setVersion("1.0");
form.setDescription("description");
form.setRetireReason("retireReason");
Errors errors = new BindException(form, "form");
new FormValidator().validate(form, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormValidatorTest method validate_shouldFailValidationIfVersionDoesNotMatchRegex.
/**
* @see FormValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfVersionDoesNotMatchRegex() {
Form form = new Form();
form.setName("test");
form.setVersion("first");
Errors errors = new BindException(form, "form");
new FormValidator().validate(form, errors);
Assert.assertFalse(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("version"));
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class HibernateFormDAO method getForm.
/**
* @see org.openmrs.api.db.FormDAO#getForm(java.lang.String, java.lang.String)
*/
@Override
public Form getForm(String name, String version) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Form.class);
crit.add(Restrictions.eq("name", name));
crit.add(Restrictions.eq("version", version));
return (Form) crit.uniqueResult();
}
Aggregations