-
Notifications
You must be signed in to change notification settings - Fork 107
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
Expose created entities after finalizing form #691
Changes from 1 commit
c15d279
0798659
19e83e7
c6e0d57
6b458a7
0b036bd
7b31a82
d4f3c49
b547b78
b6ba302
15a0861
444143d
8072261
a8e5023
488511c
98aac67
4aec176
4497074
ee3e78d
de9ad87
96a057b
d8d28c6
43fff8d
eb6568e
6946ecc
ced91b0
71b75af
c3f86f2
331acd6
e978f64
d4b9100
35652f6
f69c9b2
9b34f4c
c20aa0b
9afa909
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.javarosa.entities; | ||
|
||
import org.javarosa.xform.parse.XFormParseException; | ||
|
||
public class UnrecognizedEntityVersionException extends XFormParseException { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import kotlin.Pair; | ||
import org.javarosa.core.model.FormDef; | ||
import org.javarosa.core.util.XFormsElement; | ||
import org.javarosa.entities.UnrecognizedEntityVersionException; | ||
import org.javarosa.xform.parse.XFormParser; | ||
import org.junit.Test; | ||
|
||
|
@@ -25,6 +26,76 @@ | |
|
||
public class EntityFormParseProcessorTest { | ||
|
||
@Test(expected = UnrecognizedEntityVersionException.class) | ||
public void whenVersionIsNotRecognized_throwsException() throws IOException { | ||
XFormsElement form = XFormsElement.html( | ||
asList( | ||
new Pair<>("entities", "http://www.opendatakit.org/xforms/entities") | ||
), | ||
head( | ||
title("Create entity form"), | ||
t("model entities:entities-version=\"somethingElse\"", | ||
mainInstance( | ||
t("data id=\"create-entity-form\"", | ||
t("name"), | ||
t("orx:meta", | ||
t("entities:entity dataset=\"people\"", | ||
t("entities:create") | ||
) | ||
) | ||
) | ||
), | ||
bind("/data/name").type("string").withAttribute("entities", "saveto", "name") | ||
) | ||
), | ||
body( | ||
input("/data/name") | ||
) | ||
); | ||
|
||
EntityFormParseProcessor processor = new EntityFormParseProcessor(); | ||
|
||
XFormParser parser = new XFormParser(new InputStreamReader(new ByteArrayInputStream(form.asXml().getBytes()))); | ||
parser.addProcessor(processor); | ||
parser.parse(null); | ||
} | ||
|
||
@Test | ||
public void whenVersionIsNewPatch_doesNotThrowException() throws IOException { | ||
String newPatchVersion = EntityFormParseProcessor.SUPPORTED_VERSION + ".12"; | ||
|
||
XFormsElement form = XFormsElement.html( | ||
asList( | ||
new Pair<>("entities", "http://www.opendatakit.org/xforms/entities") | ||
), | ||
head( | ||
title("Create entity form"), | ||
t("model entities:entities-version=\"" + newPatchVersion + "\"", | ||
mainInstance( | ||
t("data id=\"create-entity-form\"", | ||
t("name"), | ||
t("orx:meta", | ||
t("entities:entity dataset=\"people\"", | ||
t("entities:create") | ||
) | ||
) | ||
) | ||
), | ||
bind("/data/name").type("string").withAttribute("entities", "saveto", "name") | ||
) | ||
), | ||
body( | ||
input("/data/name") | ||
) | ||
); | ||
|
||
EntityFormParseProcessor processor = new EntityFormParseProcessor(); | ||
|
||
XFormParser parser = new XFormParser(new InputStreamReader(new ByteArrayInputStream(form.asXml().getBytes()))); | ||
parser.addProcessor(processor); | ||
parser.parse(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't want to add any kind of assertion here? I think this is fine but I feel like I've seen you throw back tests like this so want to give you a chance to consider it again in case you do care. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it came from writing these out in order (in a TDD red-green cycle). The only needed a test where something didn't explode to get the code where I wanted, but you're right that it's a bit confusing to read after the fact. I'll add a "this is working as expected" assertion. |
||
} | ||
|
||
@Test | ||
public void saveTosWithIncorrectNamespaceAreIgnored() throws IOException { | ||
XFormsElement form = XFormsElement.html( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm always terrified to see any kind of nested iteration but I guess we don't really care too much about form parse time (within reason) and we generally expect at most a handful of attributes and processors.