use of org.openmrs.Field in project openmrs-core by openmrs.
the class FormServiceTest method getFieldByUuid_shouldFindObjectGivenValidUuid.
/**
* @see FormService#getFieldByUuid(String)
*/
@Test
public void getFieldByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "db016b7d-39a5-4911-89da-0eefbfef7cb2";
Field field = Context.getFormService().getFieldByUuid(uuid);
assertEquals(1, (int) field.getFieldId());
}
use of org.openmrs.Field in project openmrs-core by openmrs.
the class FormServiceTest method shouldFieldCreateModifyDelete.
/**
* Test create then update a field
*
* @throws Exception
*/
@Test
public void shouldFieldCreateModifyDelete() {
executeDataSet(INITIAL_FIELDS_XML);
FormService formService = Context.getFormService();
ConceptService conceptService = Context.getConceptService();
// testing creation
Concept concept1 = conceptService.getConcept(1);
String name1 = "name1";
String descript1 = "descript1";
FieldType fieldtype1 = formService.getAllFieldTypes().get(0);
String table1 = "table1";
String attr1 = "attr1";
Boolean multi1 = true;
Field field1 = new Field();
field1.setConcept(concept1);
field1.setName(name1);
field1.setDescription(descript1);
field1.setFieldType(fieldtype1);
field1.setTableName(table1);
field1.setAttributeName(attr1);
field1.setSelectMultiple(multi1);
formService.saveField(field1);
// testing update
Field field2 = formService.getField(field1.getFieldId());
Concept concept2 = conceptService.getConcept(2);
String name2 = "name2";
String descript2 = "descript2";
FieldType fieldtype2 = formService.getAllFieldTypes().get(1);
String table2 = "table2";
String attr2 = "attr2";
Boolean multi2 = false;
field2.setConcept(concept2);
field2.setName(name2);
field2.setDescription(descript2);
field2.setFieldType(fieldtype2);
field2.setTableName(table2);
field2.setAttributeName(attr2);
field2.setSelectMultiple(multi2);
formService.saveField(field2);
// testing differences
Field field3 = formService.getField(field2.getFieldId());
assertTrue(field3.equals(field1));
assertTrue(field1.getConcept().equals(concept2));
assertTrue(field1.getName().equals(name2));
assertTrue(field1.getDescription().equals(descript2));
assertTrue(field1.getFieldType().equals(fieldtype2));
assertTrue(field1.getTableName().equals(table2));
assertTrue(field1.getAttributeName().equals(attr2));
assertTrue(field1.getSelectMultiple().equals(multi2));
// testing deletion
formService.saveField(field3);
formService.purgeField(field3);
assertNull(formService.getField(field3.getFieldId()));
}
use of org.openmrs.Field 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.Field in project openmrs-core by openmrs.
the class FieldValidatorTest method validate_shouldFailValidationIfNameIsAllWhitespace.
/**
* @see FieldValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsAllWhitespace() {
Field ff = new Field();
ff.setName(" ");
FieldType ft = new FieldType();
Boolean retired = Boolean.FALSE;
ft.setId(0xdeadcafe);
ff.setFieldType(ft);
ff.setRetired(retired);
Boolean multiple = Boolean.FALSE;
ff.setSelectMultiple(multiple);
Errors errors = new BindException(ff, "name");
new FieldValidator().validate(ff, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
}
use of org.openmrs.Field in project openmrs-core by openmrs.
the class FieldValidatorTest method validate_shouldFailValidationIfSelectMultipleIsNull.
/**
* @see FieldValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfSelectMultipleIsNull() {
Field ff = new Field();
ff.setName("good");
FieldType ft = new FieldType();
ft.setFieldTypeId(0xdeadcafe);
Boolean retired = Boolean.FALSE;
ff.setFieldType(ft);
ff.setName("valid");
ff.setRetired(retired);
Boolean multiple = null;
ff.setSelectMultiple(multiple);
Errors errors = new BindException(ff, "selectMultiple");
new FieldValidator().validate(ff, errors);
Assert.assertTrue(errors.hasFieldErrors("selectMultiple"));
}
Aggregations