Search in sources :

Example 6 with FormsRepository

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

the class FormsRepositoryTest method getAllByFormIdAndVersion_whenFormHasNullVersion_returnsAllMatchingForms.

@Test
public void getAllByFormIdAndVersion_whenFormHasNullVersion_returnsAllMatchingForms() {
    FormsRepository formsRepository = buildSubject();
    formsRepository.save(FormUtils.buildForm("1", null, getFormFilesPath()).build());
    formsRepository.save(FormUtils.buildForm("1", null, getFormFilesPath()).build());
    formsRepository.save(FormUtils.buildForm("1", "7", getFormFilesPath()).build());
    List<Form> forms = formsRepository.getAllByFormIdAndVersion("1", null);
    assertThat(forms.size(), is(2));
    assertThat(forms.get(0).getVersion(), is(nullValue()));
    assertThat(forms.get(1).getVersion(), is(nullValue()));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 7 with FormsRepository

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

the class FormsRepositoryTest method deleteByMd5Hash_deletesFormsWithMatchingHash.

@Test
public void deleteByMd5Hash_deletesFormsWithMatchingHash() {
    FormsRepository formsRepository = buildSubject();
    formsRepository.save(FormUtils.buildForm("id1", "version", getFormFilesPath()).build());
    formsRepository.save(FormUtils.buildForm("id1", "version", getFormFilesPath()).build());
    formsRepository.save(FormUtils.buildForm("id2", "version", getFormFilesPath()).build());
    List<Form> id1Forms = formsRepository.getAllByFormIdAndVersion("id1", "version");
    assertThat(id1Forms.size(), is(2));
    assertThat(id1Forms.get(0).getMD5Hash(), is(id1Forms.get(1).getMD5Hash()));
    formsRepository.deleteByMd5Hash(id1Forms.get(0).getMD5Hash());
    assertThat(formsRepository.getAll().size(), is(1));
    assertThat(formsRepository.getAll().get(0).getFormId(), is("id2"));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 8 with FormsRepository

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

the class FormsRepositoryTest method restore_marksDeletedAsFalse.

@Test
public void restore_marksDeletedAsFalse() {
    FormsRepository formsRepository = buildSubject();
    formsRepository.save(FormUtils.buildForm("1", null, getFormFilesPath()).deleted(true).build());
    formsRepository.restore(1L);
    assertThat(formsRepository.get(1L).isDeleted(), is(false));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Test(org.junit.Test)

Example 9 with FormsRepository

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

the class FormsRepositoryTest method getAllNotDeletedByFormId_doesNotReturnDeletedForms.

@Test
public void getAllNotDeletedByFormId_doesNotReturnDeletedForms() {
    FormsRepository formsRepository = buildSubject();
    formsRepository.save(FormUtils.buildForm("1", "deleted", getFormFilesPath()).deleted(true).build());
    formsRepository.save(FormUtils.buildForm("1", "not-deleted", getFormFilesPath()).deleted(false).build());
    List<Form> forms = formsRepository.getAllNotDeletedByFormId("1");
    assertThat(forms.size(), is(1));
    assertThat(forms.get(0).getVersion(), equalTo("not-deleted"));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Example 10 with FormsRepository

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

the class FormsRepositoryTest method save_addsId.

@Test
public void save_addsId() {
    FormsRepository formsRepository = buildSubject();
    Form form = FormUtils.buildForm("id", "version", getFormFilesPath()).build();
    formsRepository.save(form);
    assertThat(formsRepository.getAll().get(0).getDbId(), notNullValue());
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) Test(org.junit.Test)

Aggregations

FormsRepository (org.odk.collect.forms.FormsRepository)26 Form (org.odk.collect.forms.Form)21 Test (org.junit.Test)20 File (java.io.File)8 Instance (org.odk.collect.forms.instances.Instance)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 AsyncTask (android.os.AsyncTask)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 BUTTON_NEGATIVE (android.content.DialogInterface.BUTTON_NEGATIVE)2 BUTTON_POSITIVE (android.content.DialogInterface.BUTTON_POSITIVE)2 IntentFilter (android.content.IntentFilter)2 LocationManager (android.location.LocationManager)2 MediaPlayer (android.media.MediaPlayer)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2 ContextMenu (android.view.ContextMenu)2 ContextMenuInfo (android.view.ContextMenu.ContextMenuInfo)2