Search in sources :

Example 1 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method saveForm_shouldThrowAnErrorWhenTryingToSaveAnExistingFormWhileFormsAreLocked.

/**
 * @see FormService#saveForm(Form)
 * @throws FormsLockedException
 */
@Test(expected = FormsLockedException.class)
public void saveForm_shouldThrowAnErrorWhenTryingToSaveAnExistingFormWhileFormsAreLocked() {
    FormService fs = Context.getFormService();
    createFormsLockedGPAndSetValue("true");
    Form form = fs.getForm(1);
    form.setName("modified basic form");
    fs.saveForm(form);
}
Also used : Form(org.openmrs.Form) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 2 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method saveForm_shouldSaveGivenFormSuccessfully.

/**
 * @see FormService#saveForm(Form)
 */
@Test
public void saveForm_shouldSaveGivenFormSuccessfully() {
    FormService fs = Context.getFormService();
    createFormsLockedGPAndSetValue("false");
    Form form = new Form();
    form.setName("new form");
    form.setVersion("1.0");
    form.setDescription("testing TRUNK-4030");
    Form formSave = fs.saveForm(form);
    assertTrue(form.equals(formSave));
}
Also used : Form(org.openmrs.Form) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method shouldFormCreateUpdateDelete.

/**
 * Creates then updates a form FIXME Break this test case into separate tests
 *
 * @throws Exception
 */
@Test
public void shouldFormCreateUpdateDelete() {
    FormService formService = Context.getFormService();
    // testing Form creation
    Form form1 = new Form();
    String name1 = "form name1";
    String version1 = "1.0";
    String descript1 = "descript1";
    form1.setName(name1);
    form1.setVersion(version1);
    form1.setDescription(descript1);
    formService.saveForm(form1);
    // testing get form
    Form form2 = formService.getForm(form1.getFormId());
    String name2 = "form name2";
    String version2 = "2.0";
    String descript2 = "descript2";
    form2.setName(name2);
    form2.setVersion(version2);
    form2.setDescription(descript2);
    formService.saveForm(form2);
    // testing correct updation
    Form form3 = formService.getForm(form2.getFormId());
    assertTrue(form1.equals(form3));
    assertTrue(form3.getName().equals(name2));
    assertTrue(form3.getVersion().equals(version2));
    assertTrue(form3.getDescription().equals(descript2));
    // testing (un)retiration
    formService.retireForm(form2, "reason");
    assertTrue(form2.getRetired());
    assertTrue(form2.getRetireReason().equals("reason"));
    formService.unretireForm(form2);
    assertFalse(form2.getRetired());
    assertNull(form2.getRetireReason());
    // testing deletion
    formService.purgeForm(form2);
// formService.deleteForm(form1); //deleting a deleted form
}
Also used : Form(org.openmrs.Form) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method getFormByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see FormService#getFormByUuid(String)
 */
@Test
public void getFormByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "d9218f76-6c39-45f4-8efa-4c5c6c199f50";
    Form form = Context.getFormService().getFormByUuid(uuid);
    assertEquals(1, (int) form.getFormId());
}
Also used : Form(org.openmrs.Form) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with Form

use of org.openmrs.Form in project openmrs-core by openmrs.

the class FormServiceTest method duplicateForm_shouldCopyResourcesForOldFormToNewForm.

/**
 * @throws ParseException
 * @see FormService#duplicateForm(Form)
 */
@Test
public void duplicateForm_shouldCopyResourcesForOldFormToNewForm() throws ParseException {
    // save an original resource
    Form form = Context.getFormService().getForm(1);
    String name = "Start Date";
    FormResource resource = new FormResource();
    resource.setForm(form);
    resource.setName(name);
    resource.setDatatypeClassname("org.openmrs.customdatatype.datatype.DateDatatype");
    Date expected = new SimpleDateFormat("yyyy-MM-dd").parse("2011-10-16");
    resource.setValue(expected);
    resource = Context.getFormService().saveFormResource(resource);
    Integer resourceId = resource.getFormResourceId();
    // duplicate the form
    Form newForm = Context.getFormService().duplicateForm(form);
    // get the resource
    FormResource actual = Context.getFormService().getFormResource(newForm, name);
    // check it
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected, actual.getValue());
}
Also used : Form(org.openmrs.Form) FormResource(org.openmrs.FormResource) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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