Search in sources :

Example 26 with FormDef

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());
}
Also used : InstanceInitializationFactory(org.javarosa.core.model.instance.InstanceInitializationFactory) ParseResult(org.javarosa.xform.parse.FormParserHelper.ParseResult) FormDef(org.javarosa.core.model.FormDef) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement) Test(org.junit.Test)

Example 27 with FormDef

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);
}
Also used : XPathParseTool.parseXPath(org.javarosa.xpath.XPathParseTool.parseXPath) Path(java.nio.file.Path) FormDef(org.javarosa.core.model.FormDef) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream)

Example 28 with FormDef

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");
}
Also used : FormDef(org.javarosa.core.model.FormDef) Test(org.junit.Test)

Example 29 with FormDef

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);
}
Also used : ParseResult(org.javarosa.xform.parse.FormParserHelper.ParseResult) FormDef(org.javarosa.core.model.FormDef) Test(org.junit.Test)

Example 30 with FormDef

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());
}
Also used : FormDef(org.javarosa.core.model.FormDef) Test(org.junit.Test)

Aggregations

FormDef (org.javarosa.core.model.FormDef)31 Test (org.junit.Test)10 IOException (java.io.IOException)9 TreeElement (org.javarosa.core.model.instance.TreeElement)7 FormInstance (org.javarosa.core.model.instance.FormInstance)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)4 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)4 DataInputStream (java.io.DataInputStream)3 SubmissionProfile (org.javarosa.core.model.SubmissionProfile)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 TreeReference (org.javarosa.core.model.instance.TreeReference)3 FormEntryController (org.javarosa.form.api.FormEntryController)3 ParseResult (org.javarosa.xform.parse.FormParserHelper.ParseResult)3 XPathExpression (org.javarosa.xpath.expr.XPathExpression)3 InputStream (java.io.InputStream)2 GroupDef (org.javarosa.core.model.GroupDef)2 IDataReference (org.javarosa.core.model.IDataReference)2 QuestionDef (org.javarosa.core.model.QuestionDef)2