use of org.odk.collect.forms.Form in project collect by opendatakit.
the class FormsRepositoryTest method getAllNotDeletedByFormIdAndVersion_onlyReturnsNotDeletedFormsThatMatchVersion.
@Test
public void getAllNotDeletedByFormIdAndVersion_onlyReturnsNotDeletedFormsThatMatchVersion() {
FormsRepository formsRepository = buildSubject();
formsRepository.save(FormUtils.buildForm("id", "1", getFormFilesPath()).deleted(true).build());
formsRepository.save(FormUtils.buildForm("id", "1", getFormFilesPath()).deleted(false).build());
formsRepository.save(FormUtils.buildForm("id", "2", getFormFilesPath()).deleted(true).build());
formsRepository.save(FormUtils.buildForm("id", "2", getFormFilesPath()).deleted(false).build());
List<Form> forms = formsRepository.getAllNotDeletedByFormIdAndVersion("id", "2");
assertThat(forms.size(), is(1));
assertThat(forms.get(0).getVersion(), equalTo("2"));
}
use of org.odk.collect.forms.Form in project collect by opendatakit.
the class FormsRepositoryTest method save_addsHashBasedOnFormFile.
@Test
public void save_addsHashBasedOnFormFile() {
FormsRepository formsRepository = buildSubject();
Form form = FormUtils.buildForm("id", "version", getFormFilesPath()).build();
assertThat(form.getMD5Hash(), equalTo(null));
formsRepository.save(form);
String expectedHash = Md5.getMd5Hash(new File(form.getFormFilePath()));
assertThat(formsRepository.get(1L).getMD5Hash(), equalTo(expectedHash));
}
use of org.odk.collect.forms.Form 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()));
}
use of org.odk.collect.forms.Form in project collect by opendatakit.
the class InMemFormsRepository method delete.
@Override
public void delete(Long id) {
Optional<Form> formToRemove = forms.stream().filter(f -> f.getDbId().equals(id)).findFirst();
if (formToRemove.isPresent()) {
Form form = formToRemove.get();
deleteFilesForForm(form);
forms.remove(form);
}
}
use of org.odk.collect.forms.Form 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"));
}
Aggregations