use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormServiceTest method saveFormResource_shouldPersistAFormResource.
/**
* @throws ParseException
* @see FormService#saveFormResource(org.openmrs.FormResource)
*/
@Test
public void saveFormResource_shouldPersistAFormResource() throws ParseException {
Form form = Context.getFormService().getForm(1);
FormResource resource = new FormResource();
resource.setForm(form);
resource.setName("Start Date");
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);
Integer resourceId = resource.getFormResourceId();
Context.clearSession();
FormResource actual = Context.getFormService().getFormResource(resourceId);
Assert.assertNotNull(actual);
Assert.assertEquals(expected, actual.getValue());
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormServiceTest method duplicateForm_shouldClearChangedDetailsAndUpdateCreationDetails.
/**
* @see FormService#duplicateForm(Form)
*/
@Test
public void duplicateForm_shouldClearChangedDetailsAndUpdateCreationDetails() {
Date startOfTest = DateUtil.truncateToSeconds(new Date());
FormService formService = Context.getFormService();
Form form = formService.getForm(1);
Form dupForm = formService.duplicateForm(form);
Assert.assertNull(dupForm.getChangedBy());
Assert.assertNull(dupForm.getDateChanged());
assertEquals(Context.getAuthenticatedUser(), dupForm.getCreator());
assertFalse(dupForm.getDateCreated().before(startOfTest));
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormServiceTest method getFormField_shouldNotFailWithNullIgnoreFormFieldsArgument.
/**
* @see FormService#getFormField(Form,Concept,Collection<QFormField;>,null)
*/
@Test
public void getFormField_shouldNotFailWithNullIgnoreFormFieldsArgument() {
// test that a null ignoreFormFields doesn't error out
FormField ff = Context.getFormService().getFormField(new Form(1), new Concept(3), null, false);
assertNotNull(ff);
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormServiceTest method saveFormField_shouldPropagateSaveToTheFieldPropertyOnTheGivenFormField.
/**
* @see FormService#saveFormField(FormField)
*/
@Test
public void saveFormField_shouldPropagateSaveToTheFieldPropertyOnTheGivenFormField() {
// create a new Field
Field field = new Field();
field.setName("This is a new field");
field.setDescription("It should be saved along with the formField");
// put that field on a new FormField.
FormField formField = new FormField();
formField.setField(field);
formField.setForm(new Form(1));
// save the FormField
Context.getFormService().saveFormField(formField);
// the uuid should be set by this method so that the field can be saved successfully
Assert.assertNotNull(field.getUuid());
}
use of org.openmrs.Form in project openmrs-core by openmrs.
the class FormServiceTest method duplicateForm_shouldGiveANewUuidToTheDuplicatedForm.
/**
* @see FormService#duplicateForm(Form)
*/
@Test
public void duplicateForm_shouldGiveANewUuidToTheDuplicatedForm() {
FormService formService = Context.getFormService();
Form form = formService.getForm(1);
String originalUUID = form.getUuid();
Form dupForm = formService.duplicateForm(form);
Assert.assertNotNull(dupForm.getUuid());
Assert.assertNotSame(originalUUID, dupForm.getUuid());
}
Aggregations