use of org.javarosa.core.test.FormParseInit in project javarosa by opendatakit.
the class TreeElementTests method testPopulate_withNodesAttributes.
@Test
public void testPopulate_withNodesAttributes() {
// Given
FormParseInit formParseInit = new FormParseInit();
formParseInit.setFormToParse(Paths.get(PathConst.getTestResourcePath().getAbsolutePath(), "populate-nodes-attributes.xml").toString());
FormEntryController formEntryController = formParseInit.getFormEntryController();
byte[] formInstanceAsBytes = null;
try {
formInstanceAsBytes = Files.readAllBytes(Paths.get(PathConst.getTestResourcePath().getAbsolutePath(), "populate-nodes-attributes-instance.xml"));
} catch (IOException e) {
fail("There was a problem with reading the test data.\n" + e.getMessage());
}
TreeElement savedRoot = XFormParser.restoreDataModel(formInstanceAsBytes, null).getRoot();
FormDef formDef = formEntryController.getModel().getForm();
TreeElement dataRootNode = formDef.getInstance().getRoot().deepCopy(true);
// When
dataRootNode.populate(savedRoot, formDef);
// Then
assertEquals(2, dataRootNode.getNumChildren());
TreeElement freeText1Question = dataRootNode.getChildAt(0);
TreeElement regularGroup = dataRootNode.getChildAt(1);
assertEquals(1, regularGroup.getNumChildren());
TreeElement freeText2Question = regularGroup.getChildAt(0);
assertEquals("free_text_1", freeText1Question.getName());
assertEquals(1, freeText1Question.getAttributeCount());
TreeElement customAttr1 = freeText1Question.getAttribute(null, "custom_attr_1");
assertNotNull(customAttr1);
assertEquals("custom_attr_1", customAttr1.getName());
assertEquals("", customAttr1.getNamespace());
assertEquals("xyz1", customAttr1.getAttributeValue());
assertEquals("regular_group", regularGroup.getName());
assertEquals(1, regularGroup.getAttributeCount());
customAttr1 = regularGroup.getAttribute(null, "custom_attr_1");
assertNotNull(customAttr1);
assertEquals("custom_attr_1", customAttr1.getName());
assertEquals("custom_name_space", customAttr1.getNamespace());
assertEquals("xyz2", customAttr1.getAttributeValue());
assertEquals("free_text_2", freeText2Question.getName());
assertEquals(1, freeText1Question.getAttributeCount());
TreeElement customAttr2 = freeText2Question.getAttribute(null, "custom_attr_2");
assertNotNull(customAttr2);
assertEquals("custom_attr_2", customAttr2.getName());
assertEquals("", customAttr2.getNamespace());
assertEquals("xyz3", customAttr2.getAttributeValue());
}
use of org.javarosa.core.test.FormParseInit in project javarosa by opendatakit.
the class QuestionDefTest method setUp.
@Before
public void setUp() {
fpi = new FormParseInit();
fpi.getFirstQuestionDef();
}
use of org.javarosa.core.test.FormParseInit in project javarosa by opendatakit.
the class OutputInComputedConstraintTextTest method setUp.
@Before
public void setUp() {
FormParseInit fpi = new FormParseInit();
fpi.setFormToParse(r("constraint-message-error.xml").toString());
formDef = fpi.getFormDef();
formDef.getLocalizer().setLocale("English");
ctrl = fpi.getFormEntryController();
model = fpi.getFormEntryModel();
buildIndexes();
}
use of org.javarosa.core.test.FormParseInit in project javarosa by opendatakit.
the class FormNavigationTestCase method testIndices.
@Test
public // Verify the expected indices before and after each operation.
void testIndices() {
FormParseInit fpi = new FormParseInit();
fpi.setFormToParse(r("navigation/" + formName).toString());
FormEntryController formEntryController = fpi.getFormEntryController();
FormEntryModel formEntryModel = fpi.getFormEntryModel();
int repeatCount = 0;
for (int i = 0; i < expectedIndices.length - 1; i++) {
// navigate forwards
// check the current index
assertEquals(expectedIndices[i], formEntryModel.getFormIndex().toString());
if (repeatCount < 3 && formEntryController.getModel().getEvent() == EVENT_PROMPT_NEW_REPEAT) {
formEntryController.newRepeat();
repeatCount++;
}
formEntryModel.setQuestionIndex(formEntryModel.incrementIndex(formEntryModel.getFormIndex()));
// check the index again after increasing the index
assertEquals(expectedIndices[i + 1], formEntryModel.getFormIndex().toString());
}
for (int i = expectedIndices.length - 1; i > 0; i--) {
// navigate backwards
// check the current index
assertEquals(expectedIndices[i], formEntryModel.getFormIndex().toString());
formEntryModel.setQuestionIndex(formEntryModel.decrementIndex(formEntryModel.getFormIndex()));
// check the index again after decreasing the index
assertEquals(expectedIndices[i - 1], formEntryModel.getFormIndex().toString());
}
}
use of org.javarosa.core.test.FormParseInit in project javarosa by opendatakit.
the class RecalculateTest method setUp.
@Before
public void setUp() {
FormParseInit fpi = new FormParseInit();
fpi.setFormToParse(r("calculate-now.xml").toString());
formDef = fpi.getFormDef();
formDef.initialize(true, new InstanceInitializationFactory());
}
Aggregations