Search in sources :

Example 26 with Form

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

the class ServerFormDownloaderTest method whenDownloadingFormWithVersion_andId_andHashOnDevice_doesNotLogAnalytics.

@Test
public void whenDownloadingFormWithVersion_andId_andHashOnDevice_doesNotLogAnalytics() throws Exception {
    String xform = FormUtils.createXFormBody("form", "version", "A title");
    Form form = buildForm("form", "version", getFormFilesPath(), xform).build();
    formsRepository.save(form);
    String xform2 = FormUtils.createXFormBody("form2", "version", "A different title");
    Form form2 = buildForm("form", "version", getFormFilesPath(), xform2).build();
    formsRepository.save(form2);
    ServerFormDetails serverFormDetails = new ServerFormDetails(form.getDisplayName(), "http://downloadUrl", form.getFormId(), form.getVersion(), Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), true, false, null);
    FormSource formSource = mock(FormSource.class);
    when(formSource.fetchForm("http://downloadUrl")).thenReturn(new ByteArrayInputStream(xform.getBytes()));
    Analytics mockAnalytics = mock(Analytics.class);
    ServerFormDownloader downloader = new ServerFormDownloader(formSource, formsRepository, cacheDir, formsDir.getAbsolutePath(), new FormMetadataParser(), mockAnalytics);
    downloader.downloadForm(serverFormDetails, null, null);
    verifyNoInteractions(mockAnalytics);
}
Also used : Form(org.odk.collect.forms.Form) FormUtils.buildForm(org.odk.collect.formstest.FormUtils.buildForm) ByteArrayInputStream(java.io.ByteArrayInputStream) FormSource(org.odk.collect.forms.FormSource) Analytics(org.odk.collect.analytics.Analytics) Test(org.junit.Test)

Example 27 with Form

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

the class FormDeleterTest method whenOtherVersionOfFormHasInstances_deletesForm.

@Test
public void whenOtherVersionOfFormHasInstances_deletesForm() {
    formsRepository.save(new Form.Builder().formId("1").version("old").formFilePath(FormUtils.createXFormFile("1", "old").getAbsolutePath()).build());
    Form formToDelete = formsRepository.save(new Form.Builder().formId("1").version("new").formFilePath(FormUtils.createXFormFile("1", "new").getAbsolutePath()).build());
    instancesRepository.save(new Instance.Builder().formId("1").formVersion("old").build());
    formDeleter.delete(formToDelete.getDbId());
    List<Form> forms = formsRepository.getAll();
    assertThat(forms.size(), is(1));
    assertThat(forms.get(0).getVersion(), is("old"));
}
Also used : Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 28 with Form

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

the class FormDeleterTest method whenFormHasNullVersion_butAnotherVersionHasInstances_deletesForm.

@Test
public void whenFormHasNullVersion_butAnotherVersionHasInstances_deletesForm() {
    formsRepository.save(new Form.Builder().formId("1").version("version").formFilePath(FormUtils.createXFormFile("1", "version").getAbsolutePath()).build());
    Form formToDelete = formsRepository.save(new Form.Builder().formId("1").version(null).formFilePath(FormUtils.createXFormFile("1", null).getAbsolutePath()).build());
    instancesRepository.save(new Instance.Builder().formId("1").formVersion("version").build());
    formDeleter.delete(formToDelete.getDbId());
    List<Form> forms = formsRepository.getAll();
    assertThat(forms.size(), is(1));
    assertThat(forms.get(0).getVersion(), is("version"));
}
Also used : Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 29 with Form

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

the class FormDeleterTest method whenFormIdAndVersionCombinationIsNotUnique_andInstanceExists_hardDeletesForm.

@Test
public void whenFormIdAndVersionCombinationIsNotUnique_andInstanceExists_hardDeletesForm() {
    Form formToDelete = formsRepository.save(new Form.Builder().formId("id").version("version").formFilePath(FormUtils.createXFormFile("id", "version").getAbsolutePath()).build());
    instancesRepository.save(new Instance.Builder().formId("id").formVersion("version").build());
    formsRepository.save(new Form.Builder().formId("id").version("version").formFilePath(FormUtils.createXFormFile("id", "version").getAbsolutePath()).build());
    formDeleter.delete(formToDelete.getDbId());
    List<Form> forms = formsRepository.getAll();
    assertThat(forms.size(), is(1));
    assertThat(forms.get(0).getDbId(), is(2L));
}
Also used : Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 30 with Form

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

the class FormDeleterTest method whenFormHasDeletedInstances_deletesForm.

@Test
public void whenFormHasDeletedInstances_deletesForm() {
    Form formToDelete = formsRepository.save(new Form.Builder().formId("id").version("version").formFilePath(FormUtils.createXFormFile("id", "version").getAbsolutePath()).build());
    instancesRepository.save(new Instance.Builder().formId("id").formVersion("version").deletedDate(0L).build());
    formDeleter.delete(formToDelete.getDbId());
    assertThat(formsRepository.getAll().size(), is(0));
}
Also used : Form(org.odk.collect.forms.Form) Instance(org.odk.collect.forms.instances.Instance) InstanceUtils.buildInstance(org.odk.collect.formstest.InstanceUtils.buildInstance) Test(org.junit.Test)

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