Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document current verifyItemsetBindings behavior #781

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.javarosa.core.model.data.helper.Selection;
import org.javarosa.core.model.instance.AbstractTreeElement;
import org.javarosa.core.model.instance.TreeReference;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.test.FormParseInit;
import org.javarosa.test.Scenario;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.xpath.expr.XPathPathExpr;
import org.javarosa.xpath.parser.XPathSyntaxException;
import org.junit.Test;
Expand All @@ -24,6 +24,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.javarosa.core.reference.ReferenceManagerTestUtils.setUpSimpleReferenceManager;
import static org.javarosa.test.BindBuilderXFormsElement.bind;
import static org.javarosa.test.ResourcePathHelper.r;
import static org.javarosa.test.XFormsElement.body;
import static org.javarosa.test.XFormsElement.head;
import static org.javarosa.test.XFormsElement.html;
Expand All @@ -32,7 +33,6 @@
import static org.javarosa.test.XFormsElement.select1Dynamic;
import static org.javarosa.test.XFormsElement.t;
import static org.javarosa.test.XFormsElement.title;
import static org.javarosa.test.ResourcePathHelper.r;
import static org.javarosa.xform.parse.FormParserHelper.deserializeAndCleanUpSerializedForm;
import static org.javarosa.xform.parse.FormParserHelper.getSerializedFormPath;
import static org.javarosa.xform.parse.FormParserHelper.parse;
Expand Down Expand Up @@ -134,6 +134,59 @@ public void xformParseException_whenItemsetConfiguresValueOrLabelNotInExternalIn
}
}

@Test
public void itemsetBindingVerification_doesNotVerifySecondItem() throws IOException, XFormParser.ParseException {
configureReferenceManagerCorrectly();

Scenario.init("Some form", html(
head(
title("Some form"),
model(
mainInstance(t("data id=\"some-form\"",
t("first")
)),

t("instance id=\"mixed-schema\" src=\"jr://file/mixed-schema.xml\""),

bind("/data/first").type("string")
)
),
body(
// Define a select using value and label references that only exist for the first item
select1Dynamic("/data/first", "instance('mixed-schema')/root/item", "name", "label")
)));
}

@Test
public void itemsetBindingVerification_verifiesFirstItem() throws IOException {
configureReferenceManagerCorrectly();

try {
Scenario.init("Some form", html(
head(
title("Some form"),
model(
mainInstance(t("data id=\"some-form\"",
t("first")
)),

t("instance id=\"mixed-schema\" src=\"jr://file/mixed-schema2.xml\""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use inline instances here or would they not get verified? If we can, they'd make the test much easier to read in my opinion.


bind("/data/first").type("string")
)
),
body(
// Define a select using value and label references that only exist for the second item
select1Dynamic("/data/first", "instance('mixed-schema')/root/item", "name", "label")
)));
fail("Expected XFormParseException because itemset references don't exist in external instance");
} catch (XFormParseException e) {
// pass
} catch (XFormParser.ParseException e) {
throw new RuntimeException(e);
}
}

@Test
public void csvSecondaryInstanceWithHeaderOnly_parsesWithoutError() throws IOException, XFormParser.ParseException {
configureReferenceManagerCorrectly();
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/org/javarosa/xform/parse/mixed-schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<root>
<item>
<label>A</label>
<name>a</name>
</item>
<item>
<foo>bar</foo>
</item>
</root>
9 changes: 9 additions & 0 deletions src/test/resources/org/javarosa/xform/parse/mixed-schema2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<root>
<item>
<foo>bar</foo>
</item>
<item>
<label>A</label>
<name>a</name>
</item>
</root>