use of org.odk.collect.forms.Form 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.Form 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.Form 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.Form 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);
}
use of org.odk.collect.forms.Form 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));
}
Aggregations