use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.
the class ActivityTest method createActivity.
@Test
public void createActivity() {
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO db = schema.getDatabaseById(1);
LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
ActivityFormDTO act = new ActivityFormDTO();
act.setName("Household Survey");
act.setLocationType(locType);
act.setReportingFrequency(ActivityFormDTO.REPORT_ONCE);
CreateResult createResult = execute(CreateEntity.Activity(db, act));
ResourceId classId = activityFormClass(createResult.getNewId());
FormClass formClass = assertResolves(locator.getFormClass(classId));
FormField newField = new FormField(ResourceId.generateFieldId(QuantityType.TYPE_CLASS));
newField.setLabel("How old are you?");
newField.setType(new QuantityType().setUnits("years"));
formClass.addElement(newField);
FormField newTextField = new FormField(ResourceId.generateFieldId(TextType.TYPE_CLASS));
newTextField.setLabel("What is your name?");
newTextField.setType(TextType.SIMPLE);
formClass.addElement(newTextField);
assertResolves(locator.persist(formClass));
FormClass reform = assertResolves(locator.getFormClass(formClass.getId()));
assertHasFieldWithLabel(reform, "How old are you?");
newField.setLabel("How old are you today?");
// save again
assertResolves(locator.persist(formClass));
reform = assertResolves(locator.getFormClass(formClass.getId()));
assertHasFieldWithLabel(reform, "How old are you today?");
System.out.println(reform.getFields().toString());
assertThat(reform.getFields(), hasSize(8));
List<EnumItem> values = Lists.newArrayList();
values.add(new EnumItem(EnumItem.generateId(), "Option 1"));
values.add(new EnumItem(EnumItem.generateId(), "Option 2"));
}
use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.
the class ActivityTest method updateIndicatorWithLongUnits.
@Test
public void updateIndicatorWithLongUnits() {
TFormClass formClass = new TFormClass(assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(1))));
FormField beneficiaries = formClass.getFieldByLabel("beneficiaries");
QuantityType updatedType = new QuantityType().setUnits("imperial tonne with very long qualifying text");
beneficiaries.setType(updatedType);
assertResolves(locator.persist(formClass.getFormClass()));
ActivityFormDTO activity = getActivity(1);
assertThat(activity.getIndicatorById(1), hasProperty("units", Matchers.equalTo(updatedType.getUnits())));
}
use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.
the class UpdaterTest method invalidQuantity.
@Test(expected = InvalidUpdateException.class)
public void invalidQuantity() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = createObject();
fields.put("Q1", "Hello World");
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
Updater.parseChange(formClass, change, userId);
}
use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.
the class UpdaterTest method validQuantity.
@Test
public void validQuantity() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = createObject();
fields.put("Q1", 41.3);
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertThat(update.getChangedFieldValues().get(fieldId), equalTo((FieldValue) new Quantity(41.3)));
}
use of org.activityinfo.model.type.number.QuantityType in project activityinfo by bedatadriven.
the class UpdaterTest method parsedQuantity.
@Test
public void parsedQuantity() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = Json.createObject();
fields.put("Q1", "41.3");
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertThat(update.getChangedFieldValues().get(fieldId), equalTo((FieldValue) new Quantity(41.3)));
}
Aggregations