Search in sources :

Example 41 with Form

use of org.odk.collect.forms.Form in project collect by opendatakit.

the class FormsRepositoryTest method getAllFormId_returnsMatchingForms.

@Test
public void getAllFormId_returnsMatchingForms() {
    FormsRepository formsRepository = buildSubject();
    Form form1 = formsRepository.save(FormUtils.buildForm("id1", "version", getFormFilesPath()).build());
    Form form2 = formsRepository.save(FormUtils.buildForm("id1", "other_version", getFormFilesPath()).build());
    formsRepository.save(FormUtils.buildForm("id2", "version", getFormFilesPath()).build());
    List<Form> forms = formsRepository.getAllByFormId("id1");
    assertThat(forms.size(), is(2));
    assertThat(forms, contains(form1, form2));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 42 with Form

use of org.odk.collect.forms.Form in project collect by opendatakit.

the class FormsRepositoryTest method getOneByPath_returnsMatchingForm.

@Test
public void getOneByPath_returnsMatchingForm() {
    FormsRepository formsRepository = buildSubject();
    formsRepository.save(FormUtils.buildForm("id1", "version", getFormFilesPath()).build());
    Form form2 = FormUtils.buildForm("id2", "version", getFormFilesPath()).build();
    formsRepository.save(form2);
    assertThat(formsRepository.getOneByPath(form2.getFormFilePath()).getFormId(), is("id2"));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 43 with Form

use of org.odk.collect.forms.Form in project collect by opendatakit.

the class FormsRepositoryTest method getLatestByFormIdAndVersion_whenFormHasNullVersion_returnsForm.

@Test
public void getLatestByFormIdAndVersion_whenFormHasNullVersion_returnsForm() {
    FormsRepository formsRepository = buildSubject();
    formsRepository.save(FormUtils.buildForm("1", null, getFormFilesPath()).build());
    Form form = formsRepository.getLatestByFormIdAndVersion("1", null);
    assertThat(form, notNullValue());
    assertThat(form.getDbId(), is(1L));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 44 with Form

use of org.odk.collect.forms.Form in project collect by opendatakit.

the class InMemFormsRepository method restore.

@Override
public void restore(Long id) {
    Form form = forms.stream().filter(f -> f.getDbId().equals(id)).findFirst().orElse(null);
    if (form != null) {
        forms.remove(form);
        forms.add(new Form.Builder(form).deleted(false).build());
    }
}
Also used : Form(org.odk.collect.forms.Form)

Example 45 with Form

use of org.odk.collect.forms.Form in project collect by opendatakit.

the class InMemFormsRepository method softDelete.

@Override
public void softDelete(Long id) {
    Form form = forms.stream().filter(f -> f.getDbId().equals(id)).findFirst().orElse(null);
    if (form != null) {
        forms.remove(form);
        forms.add(new Form.Builder(form).deleted(true).build());
    }
}
Also used : Form(org.odk.collect.forms.Form)

Aggregations

Form (org.odk.collect.forms.Form)62 Test (org.junit.Test)35 File (java.io.File)22 FormsRepository (org.odk.collect.forms.FormsRepository)21 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Analytics (org.odk.collect.analytics.Analytics)13 FormSource (org.odk.collect.forms.FormSource)12 FormUtils.buildForm (org.odk.collect.formstest.FormUtils.buildForm)12 MediaFile (org.odk.collect.forms.MediaFile)9 FormsRepositoryProvider (org.odk.collect.android.utilities.FormsRepositoryProvider)7 ManifestFile (org.odk.collect.forms.ManifestFile)7 Instance (org.odk.collect.forms.instances.Instance)7 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)7 ArrayList (java.util.ArrayList)5 FormController (org.odk.collect.android.javarosawrapper.FormController)4 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3 DatabaseObjectMapper.getValuesFromForm (org.odk.collect.android.database.DatabaseObjectMapper.getValuesFromForm)3 Intent (android.content.Intent)2 View (android.view.View)2 TextView (android.widget.TextView)2