Search in sources :

Example 21 with FormsRepository

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

the class FormsRepositoryTest method delete_whenMediaPathIsFile_deletesFiles.

@Test
public void delete_whenMediaPathIsFile_deletesFiles() throws Exception {
    FormsRepository formsRepository = buildSubject();
    Form form = formsRepository.save(FormUtils.buildForm("id", "version", getFormFilesPath()).build());
    // FormRepository currently doesn't manage media file path other than deleting it
    String mediaPath = form.getFormMediaPath();
    new File(mediaPath).createNewFile();
    File formFile = new File(form.getFormFilePath());
    File mediaDir = new File(form.getFormMediaPath());
    assertThat(formFile.exists(), is(true));
    assertThat(mediaDir.exists(), is(true));
    formsRepository.delete(1L);
    assertThat(formFile.exists(), is(false));
    assertThat(mediaDir.exists(), is(false));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) Form(org.odk.collect.forms.Form) File(java.io.File) Test(org.junit.Test)

Example 22 with FormsRepository

use of org.odk.collect.forms.FormsRepository 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 23 with FormsRepository

use of org.odk.collect.forms.FormsRepository 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 24 with FormsRepository

use of org.odk.collect.forms.FormsRepository 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 25 with FormsRepository

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

the class FormsRepositoryTest method softDelete_marksDeletedAsTrue.

@Test
public void softDelete_marksDeletedAsTrue() {
    FormsRepository formsRepository = buildSubject();
    formsRepository.save(FormUtils.buildForm("1", null, getFormFilesPath()).build());
    formsRepository.softDelete(1L);
    assertThat(formsRepository.get(1L).isDeleted(), is(true));
}
Also used : FormsRepository(org.odk.collect.forms.FormsRepository) 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