use of org.openmrs.FormResource in project openmrs-core by openmrs.
the class FormServiceTest method saveFormResource_shouldBeAbleToSaveAnXSLT.
/**
* @throws IOException
* @see FormService#saveFormResource(FormResource)
*/
@Test
public void saveFormResource_shouldBeAbleToSaveAnXSLT() throws IOException {
// set up new form
Form form = new Form();
form.setName("form resource test form");
form.setVersion("42");
form.setDescription("bleh");
form = Context.getFormService().saveForm(form);
// save a resource
String name = "org.openmrs.module.formentry.xslt";
String expected = getResourceAsString(FORM_SAMPLE_RESOURCE);
FormResource resource = new FormResource();
resource.setForm(form);
resource.setName(name);
resource.setDatatypeClassname("org.openmrs.customdatatype.datatype.LongFreeTextDatatype");
resource.setValue(expected);
Context.getFormService().saveFormResource(resource);
// make sure the resource is saved
Collection<FormResource> formResourcesForForm = Context.getFormService().getFormResourcesForForm(form);
Assert.assertEquals(1, formResourcesForForm.size());
FormResource actual = formResourcesForForm.iterator().next();
Assert.assertEquals(expected, actual.getValue());
}
use of org.openmrs.FormResource in project openmrs-core by openmrs.
the class FormServiceTest method purgeForm_shouldDeleteFormResourcesForDeletedForm.
/**
* @throws ParseException
* @see FormService#purgeForm(Form)
*/
@Test
public void purgeForm_shouldDeleteFormResourcesForDeletedForm() throws ParseException {
// create a new form
Form form = new Form();
form.setName("form resource test form");
form.setVersion("42");
form.setDescription("bleh");
form = Context.getFormService().saveForm(form);
// save a resource
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);
Context.getFormService().saveFormResource(resource);
// make sure the resource is saved
FormResource actual = Context.getFormService().getFormResource(form, name);
assertEquals(expected, actual.getValue());
// retain the resource id
Integer savedId = actual.getFormResourceId();
// delete the form
Context.getFormService().purgeForm(form);
// check for the resource
Assert.assertNull(Context.getFormService().getFormResource(savedId));
}
use of org.openmrs.FormResource in project openmrs-core by openmrs.
the class FormServiceTest method saveFormResource_shouldOverwriteAnExistingResourceWithSameName.
/**
* @throws ParseException
* @see FormService#saveFormResource(FormResource)
*/
@Test
public void saveFormResource_shouldOverwriteAnExistingResourceWithSameName() throws ParseException {
String name = "Start Date";
// save an original resource
Form form = Context.getFormService().getForm(1);
FormResource resource = new FormResource();
resource.setForm(form);
resource.setName(name);
resource.setDatatypeClassname("org.openmrs.customdatatype.datatype.DateDatatype");
Date previous = new SimpleDateFormat("yyyy-MM-dd").parse("2011-10-16");
resource.setValue(previous);
Context.getFormService().saveFormResource(resource);
// clear the session
Context.flushSession();
// save a new resource with the same name
form = Context.getFormService().getForm(1);
resource = new FormResource();
resource.setForm(form);
resource.setName(name);
resource.setDatatypeClassname("org.openmrs.customdatatype.datatype.DateDatatype");
Date expected = new SimpleDateFormat("yyyy-MM-dd").parse("2010-10-16");
resource.setValue(expected);
Context.getFormService().saveFormResource(resource);
// get the current value
FormResource actual = Context.getFormService().getFormResource(form, name);
Assert.assertFalse(previous.equals(actual.getValue()));
Assert.assertEquals(expected, actual.getValue());
}
Aggregations