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