use of org.javarosa.core.model.FormDef in project javarosa by opendatakit.
the class XFormParserTest method parseFormWithSetValueAction.
@Test
public void parseFormWithSetValueAction() throws IOException {
// Given & When
ParseResult parseResult = parse(r("form-with-setvalue-action.xml"));
FormDef formDef = parseResult.formDef;
// dispatch 'xforms-ready' action (Action.EVENT_XFORMS_READY)
formDef.initialize(true, new InstanceInitializationFactory());
// Then
assertEquals(formDef.getTitle(), "SetValue action");
assertNoParseErrors(parseResult);
assertEquals(1, formDef.getEventListeners(Action.EVENT_XFORMS_READY).size());
TreeElement textNode = formDef.getMainInstance().getRoot().getChildrenWithName("text").get(0);
assertEquals("Test Value", textNode.getValue().getValue());
}
use of org.javarosa.core.model.FormDef in project javarosa by opendatakit.
the class XFormParserTest method serAndDeserializeForm.
private void serAndDeserializeForm(Path formName) throws IOException, DeserializationException {
initSerialization();
FormDef formDef = parse(formName).formDef;
Path p = Files.createTempFile("serialized-form", null);
final DataOutputStream dos = new DataOutputStream(Files.newOutputStream(p));
formDef.writeExternal(dos);
dos.close();
final DataInputStream dis = new DataInputStream(Files.newInputStream(p));
formDef.readExternal(dis, defaultPrototypes());
dis.close();
Files.delete(p);
}
use of org.javarosa.core.model.FormDef in project javarosa by opendatakit.
the class XFormParserTest method parsesSimpleForm.
@Test
public void parsesSimpleForm() throws IOException {
FormDef formDef = parse(r("simple-form.xml")).formDef;
assertEquals(formDef.getTitle(), "Simple Form");
}
use of org.javarosa.core.model.FormDef in project javarosa by opendatakit.
the class XFormParserTest method parseFormWithTwoModels.
@Test
public void parseFormWithTwoModels() throws IOException {
// Given & When
ParseResult parseResult = parse(r("two-models.xml"));
// Then
FormDef formDef = parseResult.formDef;
assertEquals(formDef.getTitle(), "Two Models");
assertEquals("Number of error messages", 1, parseResult.errorMessages.size());
assertEquals("Multiple models not supported. Ignoring subsequent models.", parseResult.errorMessages.get(0));
String firstModelInstanceId = (String) formDef.getMainInstance().getRoot().getAttribute(null, "id").getValue().getValue();
assertEquals("first-model", firstModelInstanceId);
}
use of org.javarosa.core.model.FormDef in project javarosa by opendatakit.
the class XFormParserTest method parsesForm2.
@Test
public void parsesForm2() throws IOException {
FormDef formDef = parse(r("form2.xml")).formDef;
assertEquals("My Survey", formDef.getTitle());
assertEquals(3, formDef.getChildren().size());
assertEquals("What is your first name?", formDef.getChild(0).getLabelInnerText());
}
Aggregations