Search in sources :

Example 36 with FormDef

use of org.javarosa.core.model.FormDef 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)

Example 37 with FormDef

use of org.javarosa.core.model.FormDef in project javarosa by opendatakit.

the class XFormParserTest method parsesForm2.

@Test
public void parsesForm2() throws IOException {
    FormDef formDef = parse(r("form2.xml")).formDef;
    assertEquals("My Survey", formDef.getTitle());
    assertEquals(3, formDef.getChildren().size());
    assertEquals("What is your first name?", formDef.getChild(0).getLabelInnerText());
}
Also used : FormDef(org.javarosa.core.model.FormDef) Test(org.junit.Test)

Example 38 with FormDef

use of org.javarosa.core.model.FormDef in project javarosa by opendatakit.

the class FormParseInit method printStuff.

/*
     * Makes an 'extremely basic' print out of the xform model.
     */
public String printStuff() {
    String stuff = "";
    // go to the beginning of the form
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    do {
        FormEntryCaption fep = femodel.getCaptionPrompt();
        boolean choiceFlag = false;
        if (fep.getFormElement() instanceof QuestionDef) {
            stuff += "\t[Type:QuestionDef, ";
            List<SelectChoice> s = ((QuestionDef) fep.getFormElement()).getChoices();
            stuff += "ContainsChoices: " + ((s != null && s.size() > 0) ? "true " : "false") + ", ";
            if (s != null && s.size() > 0)
                choiceFlag = true;
        } else if (fep.getFormElement() instanceof FormDef) {
            stuff += "\t[Type:FormDef, ";
        } else if (fep.getFormElement() instanceof GroupDef) {
            stuff += "\t[Type:GroupDef, ";
        } else {
            stuff += "\t[Type:Unknown]\n";
            continue;
        }
        stuff += "ID:" + fep.getFormElement().getID() + ", TextID:" + fep.getFormElement().getTextID() + ",InnerText:" + fep.getFormElement().getLabelInnerText();
        if (choiceFlag) {
            stuff += "] \n\t\t---Choices:" + ((QuestionDef) fep.getFormElement()).getChoices().toString() + "\n";
        } else {
            stuff += "]\n";
        }
    } while (fec.stepToNextEvent() != fec.EVENT_END_OF_FORM);
    return stuff;
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) FormDef(org.javarosa.core.model.FormDef) FormEntryCaption(org.javarosa.form.api.FormEntryCaption) QuestionDef(org.javarosa.core.model.QuestionDef) GroupDef(org.javarosa.core.model.GroupDef)

Example 39 with FormDef

use of org.javarosa.core.model.FormDef in project collect by opendatakit.

the class FormEntryViewModelTest method setup.

@Before
public void setup() {
    formController = mock(FormController.class);
    startingIndex = new FormIndex(null, 0, 0, new TreeReference());
    when(formController.getFormIndex()).thenReturn(startingIndex);
    when(formController.getFormDef()).thenReturn(new FormDef());
    AuditEventLogger auditEventLogger = mock(AuditEventLogger.class);
    when(formController.getAuditEventLogger()).thenReturn(auditEventLogger);
    viewModel = new FormEntryViewModel(mock(Supplier.class));
    viewModel.formLoaded(formController);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) AuditEventLogger(org.odk.collect.android.formentry.audit.AuditEventLogger) TreeReference(org.javarosa.core.model.instance.TreeReference) FormDef(org.javarosa.core.model.FormDef) FormIndex(org.javarosa.core.model.FormIndex) Before(org.junit.Before)

Example 40 with FormDef

use of org.javarosa.core.model.FormDef in project collect by opendatakit.

the class OSMWidgetTest method setUp.

@Before
public void setUp() {
    widgetActivity = widgetTestActivity();
    shadowActivity = shadowOf(widgetActivity);
    intentLauncher = IntentLauncherImpl.INSTANCE;
    formController = mock(FormController.class);
    FormDef formDef = mock(FormDef.class);
    questionDef = mock(QuestionDef.class);
    when(formController.getInstanceFile()).thenReturn(instancePath);
    when(formController.getMediaFolder()).thenReturn(mediaFolder);
    when(formController.getSubmissionMetadata()).thenReturn(new FormController.InstanceMetadata("instanceId", "instanceTesTName", null));
    when(formController.getFormDef()).thenReturn(formDef);
    when(formDef.getID()).thenReturn(0);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormDef(org.javarosa.core.model.FormDef) QuestionDef(org.javarosa.core.model.QuestionDef) Before(org.junit.Before)

Aggregations

FormDef (org.javarosa.core.model.FormDef)44 IOException (java.io.IOException)13 TreeElement (org.javarosa.core.model.instance.TreeElement)10 Test (org.junit.Test)10 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)7 FormInstance (org.javarosa.core.model.instance.FormInstance)6 File (java.io.File)5 SubmissionProfile (org.javarosa.core.model.SubmissionProfile)5 TreeReference (org.javarosa.core.model.instance.TreeReference)5 XPathExpression (org.javarosa.xpath.expr.XPathExpression)5 FileInputStream (java.io.FileInputStream)4 QuestionDef (org.javarosa.core.model.QuestionDef)4 IAnswerData (org.javarosa.core.model.data.IAnswerData)4 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)4 FormEntryController (org.javarosa.form.api.FormEntryController)4 XPathNodeset (org.javarosa.xpath.XPathNodeset)4 FormController (org.odk.collect.android.javarosawrapper.FormController)4 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)4 DataInputStream (java.io.DataInputStream)3 FormIndex (org.javarosa.core.model.FormIndex)3