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);
}
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());
}
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;
}
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);
}
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);
}
Aggregations