use of org.activityinfo.model.form.FormClass 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)));
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class UpdaterTest method invalidParsedQuantity.
@Test(expected = InvalidUpdateException.class)
public void invalidParsedQuantity() 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", "4.1.3");
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.form.FormClass in project activityinfo by bedatadriven.
the class NodeMatcherTest method formClass.
private FormClass formClass(String id, FormField... fields) {
FormClass formClass = new FormClass(ResourceId.valueOf(id));
formClass.setLabel(id);
for (FormField field : fields) {
formClass.addElement(field);
}
return formClass;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class NodeMatcherTest method givenRootForm.
private void givenRootForm(String label, FormField... fields) {
if (rootFormClass != null) {
throw new IllegalStateException("Root Form Class already set");
}
rootFormClass = new FormClass(ResourceId.valueOf(label));
rootFormClass.setLabel(label);
rootFormClass.getElements().addAll(Arrays.asList(fields));
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class QueryEvaluatorTest method circularReference.
@Test
public void circularReference() throws Exception {
final FormClass formClass = new FormClass(ResourceId.valueOf("XYZ"));
formClass.addField(ResourceId.valueOf("FA")).setCode("A").setLabel("Field A").setType(new CalculatedFieldType("B"));
formClass.addField(ResourceId.valueOf("FB")).setCode("B").setLabel("Field B").setType(new CalculatedFieldType("A"));
FormStorageProviderStub catalog = new FormStorageProviderStub();
catalog.addForm(formClass).withRowCount(10);
ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormScanCache(), new NullFormSupervisor());
FormScanBatch batch = builder.createNewBatch();
QueryEvaluator evaluator = new QueryEvaluator(FilterLevel.BASE, catalog.getTree(formClass.getId()), batch);
Slot<ColumnView> a = evaluator.evaluateExpression(new SymbolNode("A"));
Slot<ColumnView> aPlusOne = evaluator.evaluateExpression(FormulaParser.parse("A+1"));
builder.execute(batch);
assertThat(a.get().numRows(), equalTo(10));
assertThat(a.get().getString(0), nullValue());
assertThat(aPlusOne.get().getString(0), nullValue());
assertThat(aPlusOne.get().getDouble(0), equalTo(1d));
}
Aggregations