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