use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class UpdaterTest method serialNumber.
@Test
public void serialNumber() throws JsonMappingException {
FormClass formClass = new FormClass(ResourceId.valueOf("FORM1"));
formClass.addField(ResourceId.valueOf("FIELD0")).setType(TextType.SIMPLE).setLabel("Province Code").setCode("PROVINCE").setRequired(true);
FormField serialNumberField = formClass.addField(ResourceId.valueOf("FIELD1")).setType(new SerialNumberType("PROVINCE", 5)).setRequired(true).setLabel("File Number").setCode("SN");
JsonValue fields = Json.createObject();
fields.put("PROVINCE", "KUNDUZ");
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "FORM1");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
FormInstance effectiveRecord = updater.computeEffectiveRecord(formClass, Optional.<FormRecord>absent(), update);
updater.generateSerialNumber(formClass, serialNumberField, effectiveRecord, update);
FieldValue serialValue = update.getChangedFieldValues().get(serialNumberField.getId());
assertThat(serialValue, equalTo((FieldValue) new SerialNumber("KUNDUZ", 1)));
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class UpdaterTest method newResourceWithoutClass.
@Test(expected = InvalidUpdateException.class)
public void newResourceWithoutClass() {
JsonValue change = createObject();
change.put("formId", "XYZ123-new-id");
JsonValue changes = Json.createArray();
changes.add(change);
JsonValue updateObject = createObject();
updateObject.put("changes", changes);
updater.execute(updateObject);
}
use of org.activityinfo.json.JsonValue 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.json.JsonValue in project activityinfo by bedatadriven.
the class UpdaterTest method newResourceWithMissingCollection.
@Test(expected = InvalidUpdateException.class)
public void newResourceWithMissingCollection() {
JsonValue change = createObject();
change.put("recordId", "XYZ123");
change.put("formId", "foobar");
JsonValue changes = Json.createArray();
changes.add(change);
JsonValue updateObject = createObject();
updateObject.put("changes", changes);
updater.execute(updateObject);
}
use of org.activityinfo.json.JsonValue 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