use of org.odk.collect.forms.FormsRepository in project collect by opendatakit.
the class FormsRepositoryTest method getLatestByFormIdAndVersion_whenMultipleExist_returnsLatest.
@Test
public void getLatestByFormIdAndVersion_whenMultipleExist_returnsLatest() {
Supplier<Long> mockClock = mock(Supplier.class);
when(mockClock.get()).thenReturn(2L, 3L, 1L);
FormsRepository formsRepository = buildSubject(mockClock);
formsRepository.save(FormUtils.buildForm("1", "1", getFormFilesPath()).build());
formsRepository.save(FormUtils.buildForm("1", "1", getFormFilesPath()).build());
formsRepository.save(FormUtils.buildForm("1", "1", getFormFilesPath()).build());
Form form = formsRepository.getLatestByFormIdAndVersion("1", "1");
assertThat(form, notNullValue());
assertThat(form.getDbId(), is(2L));
}
use of org.odk.collect.forms.FormsRepository in project collect by opendatakit.
the class FormsRepositoryTest method delete_deletesFiles.
@Test
public void delete_deletesFiles() throws Exception {
FormsRepository formsRepository = buildSubject();
Form form = formsRepository.save(FormUtils.buildForm("id", "version", getFormFilesPath()).build());
// FormRepository doesn't automatically create all form files
File mediaDir = new File(form.getFormMediaPath());
mediaDir.mkdir();
File cacheFile = new File(form.getJrCacheFilePath());
cacheFile.createNewFile();
File formFile = new File(form.getFormFilePath());
assertThat(formFile.exists(), is(true));
assertThat(mediaDir.exists(), is(true));
assertThat(cacheFile.exists(), is(true));
formsRepository.delete(form.getDbId());
assertThat(formFile.exists(), is(false));
assertThat(mediaDir.exists(), is(false));
assertThat(cacheFile.exists(), is(false));
}
use of org.odk.collect.forms.FormsRepository in project collect by opendatakit.
the class FormsRepositoryTest method getOneByMd5Hash_returnsMatchingForm.
@Test
public void getOneByMd5Hash_returnsMatchingForm() {
FormsRepository formsRepository = buildSubject();
formsRepository.save(FormUtils.buildForm("id1", "version", getFormFilesPath()).build());
Form form2 = formsRepository.save(FormUtils.buildForm("id2", "version", getFormFilesPath()).build());
assertThat(formsRepository.getOneByMd5Hash(form2.getMD5Hash()), is(form2));
}
use of org.odk.collect.forms.FormsRepository in project collect by opendatakit.
the class FormsRepositoryTest method save_whenFormHasId_updatesHash.
@Test
public void save_whenFormHasId_updatesHash() throws IOException {
FormsRepository formsRepository = buildSubject();
Form originalForm = formsRepository.save(FormUtils.buildForm("id", "version", getFormFilesPath()).displayName("original").build());
String newFormBody = FormUtils.createXFormBody("id", "version", "A different title");
File formFile = new File(originalForm.getFormFilePath());
FileUtils.writeByteArrayToFile(formFile, newFormBody.getBytes());
formsRepository.save(new Form.Builder(originalForm).displayName("changed").build());
String expectedHash = Md5.getMd5Hash(formFile);
assertThat(formsRepository.get(originalForm.getDbId()).getMD5Hash(), is(expectedHash));
}
use of org.odk.collect.forms.FormsRepository in project collect by opendatakit.
the class FormsRepositoryTest method save_whenNoFormFilePath_explodes.
@Test(expected = Exception.class)
public void save_whenNoFormFilePath_explodes() {
FormsRepository formsRepository = buildSubject();
Form form = FormUtils.buildForm("id", "version", getFormFilesPath()).build();
form = new Form.Builder(form).formFilePath(null).build();
formsRepository.save(form);
}
Aggregations