Search in sources :

Example 1 with FormParseInit

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());
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) FormDef(org.javarosa.core.model.FormDef) IOException(java.io.IOException) FormParseInit(org.javarosa.core.test.FormParseInit) TreeElement(org.javarosa.core.model.instance.TreeElement) Test(org.junit.Test)

Example 2 with FormParseInit

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();
}
Also used : FormParseInit(org.javarosa.core.test.FormParseInit) Before(org.junit.Before)

Example 3 with FormParseInit

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();
}
Also used : FormParseInit(org.javarosa.core.test.FormParseInit) Before(org.junit.Before)

Example 4 with FormParseInit

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

Example 5 with FormParseInit

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());
}
Also used : InstanceInitializationFactory(org.javarosa.core.model.instance.InstanceInitializationFactory) FormParseInit(org.javarosa.core.test.FormParseInit) Before(org.junit.Before)

Aggregations

FormParseInit (org.javarosa.core.test.FormParseInit)8 Before (org.junit.Before)3 Test (org.junit.Test)3 FormEntryController (org.javarosa.form.api.FormEntryController)2 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 IOException (java.io.IOException)1 FormDef (org.javarosa.core.model.FormDef)1 FormIndex (org.javarosa.core.model.FormIndex)1 InstanceInitializationFactory (org.javarosa.core.model.instance.InstanceInitializationFactory)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 DummyFormEntryPrompt (org.javarosa.core.model.test.DummyFormEntryPrompt)1