diff --git a/collect_app/src/test/java/org/odk/collect/android/formmanagement/download/ServerFormDownloaderTest.java b/collect_app/src/test/java/org/odk/collect/android/formmanagement/download/ServerFormDownloaderTest.java index 1c078e80181..e2276a6e619 100644 --- a/collect_app/src/test/java/org/odk/collect/android/formmanagement/download/ServerFormDownloaderTest.java +++ b/collect_app/src/test/java/org/odk/collect/android/formmanagement/download/ServerFormDownloaderTest.java @@ -349,7 +349,7 @@ public void whenFormHasMediaFiles_andFetchingMediaFileFails_throwsFetchErrorAndD Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), true, false, - new ManifestFile("", asList( + new ManifestFile("", List.of( new MediaFile("file1", "hash-1", "http://file1") ))); @@ -380,7 +380,7 @@ public void whenFormHasMediaFiles_andFileExistsInMediaDirPath_throwsDiskExceptio Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), true, false, - new ManifestFile("", asList( + new ManifestFile("", List.of( new MediaFile("file1", "hash-1", "http://file1") ))); @@ -545,7 +545,7 @@ public void whenFormAlreadyDownloaded_andFormHasNewMediaFiles_updatesMediaFilesA Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), true, false, - new ManifestFile("", asList( + new ManifestFile("", List.of( new MediaFile("file1", Md5.getMd5Hash(new ByteArrayInputStream("contents".getBytes())), "http://file1") ))); @@ -571,7 +571,7 @@ public void whenFormAlreadyDownloaded_andFormHasNewMediaFiles_updatesMediaFilesA Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), false, false, - new ManifestFile("", asList( + new ManifestFile("", List.of( new MediaFile("file1", Md5.getMd5Hash(new ByteArrayInputStream("contents-updated".getBytes())), "http://file1") ))); @@ -608,7 +608,7 @@ public void whenFormAlreadyDownloaded_andFormHasNewMediaFiles_andMediaFetchFails Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), true, false, - new ManifestFile("", asList( + new ManifestFile("", List.of( new MediaFile("file1", Md5.getMd5Hash(new ByteArrayInputStream("contents".getBytes())), "http://file1") ))); @@ -630,7 +630,7 @@ public void whenFormAlreadyDownloaded_andFormHasNewMediaFiles_andMediaFetchFails Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), false, false, - new ManifestFile("", asList( + new ManifestFile("", List.of( new MediaFile("file1", Md5.getMd5Hash(new ByteArrayInputStream("contents-updated".getBytes())), "http://file1") ))); @@ -706,6 +706,118 @@ public void afterDownloadingMediaFile_cancelling_throwsDownloadingInterruptedExc } } + @Test + public void whenFormHasEntityAttachmentsButDoesNotContainAnEntityBlock_downloadsAndSavesFormAsAFormThatUsesEntities() throws Exception { + String xform = createXFormBody("id", "version"); + ServerFormDetails serverFormDetails = new ServerFormDetails( + "Form", + "http://downloadUrl", + "id", + "version", + Md5.getMd5Hash(new ByteArrayInputStream(xform.getBytes())), + true, + false, + new ManifestFile("", List.of( + new MediaFile("file1", "hash-1", "http://file1", true) + ))); + + FormSource formSource = mock(FormSource.class); + when(formSource.fetchForm("http://downloadUrl")).thenReturn(new ByteArrayInputStream(xform.getBytes())); + when(formSource.fetchMediaFile("http://file1")).thenReturn(new ByteArrayInputStream("contents1".getBytes())); + + ServerFormDownloader downloader = new ServerFormDownloader(formSource, formsRepository, cacheDir, formsDir.getAbsolutePath(), FormMetadataParser.INSTANCE, clock, entitiesRepository); + downloader.downloadForm(serverFormDetails, null, null); + + List