Search in sources :

Example 6 with ParseResult

use of org.javarosa.xform.parse.FormParserHelper.ParseResult in project javarosa by opendatakit.

the class XFormParserTest method parseFormWithSubmissionElement.

@Test
public void parseFormWithSubmissionElement() throws IOException {
    // Given & When
    ParseResult parseResult = parse(r("submission-element.xml"));
    // Then
    assertEquals(parseResult.formDef.getTitle(), "Single Submission Element");
    assertNoParseErrors(parseResult);
    SubmissionProfile submissionProfile = parseResult.formDef.getSubmissionProfile();
    assertEquals("http://some.destination.com", submissionProfile.getAction());
    assertEquals("form-data-post", submissionProfile.getMethod());
    assertNull(submissionProfile.getMediaType());
    assertEquals("/data/text", submissionProfile.getRef().getReference().toString());
}
Also used : ParseResult(org.javarosa.xform.parse.FormParserHelper.ParseResult) SubmissionProfile(org.javarosa.core.model.SubmissionProfile) Test(org.junit.Test)

Example 7 with ParseResult

use of org.javarosa.xform.parse.FormParserHelper.ParseResult in project javarosa by opendatakit.

the class XFormParserTest method parseFormWithTemplateRepeat.

@Test
public void parseFormWithTemplateRepeat() throws IOException {
    // Given & When
    ParseResult parseResult = parse(r("template-repeat.xml"));
    // Then
    assertEquals(parseResult.formDef.getTitle(), "Repeat with template");
    assertNoParseErrors(parseResult);
}
Also used : ParseResult(org.javarosa.xform.parse.FormParserHelper.ParseResult) Test(org.junit.Test)

Example 8 with ParseResult

use of org.javarosa.xform.parse.FormParserHelper.ParseResult in project javarosa by opendatakit.

the class XFormParserTest method parseGroupWithNodesetAttrForm.

@Test
public void parseGroupWithNodesetAttrForm() throws IOException {
    // Given & When
    ParseResult parseResult = parse(r("group-with-nodeset-attr.xml"));
    // Then
    assertEquals(parseResult.formDef.getTitle(), "group with nodeset attribute");
    assertEquals("Number of error messages", 0, parseResult.errorMessages.size());
    final TreeReference expectedTreeReference = new TreeReference();
    // absolute reference
    expectedTreeReference.setRefLevel(-1);
    // the instance root
    expectedTreeReference.add("data", -1);
    // the outer repeat
    expectedTreeReference.add("R1", -1);
    // the inner group
    expectedTreeReference.add("G2", -1);
    final IDataReference expectedXPathReference = new XPathReference(expectedTreeReference);
    IFormElement groupElement = parseResult.formDef.getChild(0).getChild(0);
    assertThat(groupElement, instanceOf(GroupDef.class));
    assertThat(((GroupDef) groupElement).getRepeat(), is(false));
    assertThat(groupElement.getBind(), is(expectedXPathReference));
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) ParseResult(org.javarosa.xform.parse.FormParserHelper.ParseResult) TreeReference(org.javarosa.core.model.instance.TreeReference) IDataReference(org.javarosa.core.model.IDataReference) XPathReference(org.javarosa.model.xform.XPathReference) GroupDef(org.javarosa.core.model.GroupDef) Test(org.junit.Test)

Example 9 with ParseResult

use of org.javarosa.xform.parse.FormParserHelper.ParseResult 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)

Aggregations

ParseResult (org.javarosa.xform.parse.FormParserHelper.ParseResult)9 Test (org.junit.Test)9 FormDef (org.javarosa.core.model.FormDef)3 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)3 TreeElement (org.javarosa.core.model.instance.TreeElement)3 GroupDef (org.javarosa.core.model.GroupDef)1 IDataReference (org.javarosa.core.model.IDataReference)1 IFormElement (org.javarosa.core.model.IFormElement)1 QuestionDef (org.javarosa.core.model.QuestionDef)1 SubmissionProfile (org.javarosa.core.model.SubmissionProfile)1 StringData (org.javarosa.core.model.data.StringData)1 FormInstance (org.javarosa.core.model.instance.FormInstance)1 InstanceInitializationFactory (org.javarosa.core.model.instance.InstanceInitializationFactory)1 TreeReference (org.javarosa.core.model.instance.TreeReference)1 ByteArrayPayload (org.javarosa.core.services.transport.payload.ByteArrayPayload)1 XFormSerializingVisitor (org.javarosa.model.xform.XFormSerializingVisitor)1 XPathReference (org.javarosa.model.xform.XPathReference)1