Search in sources :

Example 41 with Form

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"));
}
Also used : Errors(org.springframework.validation.Errors) Form(org.openmrs.Form) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 42 with Form

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"));
}
Also used : Errors(org.springframework.validation.Errors) Form(org.openmrs.Form) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 43 with Form

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());
}
Also used : Errors(org.springframework.validation.Errors) Form(org.openmrs.Form) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 44 with Form

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"));
}
Also used : Errors(org.springframework.validation.Errors) Form(org.openmrs.Form) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 45 with Form

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

Aggregations

Form (org.openmrs.Form)45 Test (org.junit.Test)37 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)37 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Date (java.util.Date)7 Encounter (org.openmrs.Encounter)7 FormField (org.openmrs.FormField)6 FormResource (org.openmrs.FormResource)6 Message (ca.uhn.hl7v2.model.Message)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ArrayList (java.util.ArrayList)5 Patient (org.openmrs.Patient)3 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)2 HashSet (java.util.HashSet)2 Concept (org.openmrs.Concept)2 Field (org.openmrs.Field)2 Location (org.openmrs.Location)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 HL7Exception (ca.uhn.hl7v2.HL7Exception)1