X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0f5b0542513b572959e39400bae42e69aeb1a7b6..HEAD:/sdk/java-v2/src/test/java/org/arvados/client/logic/keep/FileDownloaderTest.java diff --git a/sdk/java-v2/src/test/java/org/arvados/client/logic/keep/FileDownloaderTest.java b/sdk/java-v2/src/test/java/org/arvados/client/logic/keep/FileDownloaderTest.java index 0fb1f0206c..741f80f7c9 100644 --- a/sdk/java-v2/src/test/java/org/arvados/client/logic/keep/FileDownloaderTest.java +++ b/sdk/java-v2/src/test/java/org/arvados/client/logic/keep/FileDownloaderTest.java @@ -19,7 +19,6 @@ import org.arvados.client.test.utils.FileTestUtils; import org.arvados.client.utils.FileMerge; import org.apache.commons.io.FileUtils; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,8 +26,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -36,6 +38,10 @@ import java.util.UUID; import static org.arvados.client.test.utils.FileTestUtils.*; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -80,17 +86,17 @@ public class FileDownloaderTest { List downloadedFiles = fileDownloader.downloadFilesFromCollection(collectionToDownload.getUuid(), FILE_DOWNLOAD_TEST_DIR); //then - Assert.assertEquals(3, downloadedFiles.size()); // 3 files downloaded + assertEquals(3, downloadedFiles.size()); // 3 files downloaded File collectionDir = new File(FILE_DOWNLOAD_TEST_DIR + Characters.SLASH + collectionToDownload.getUuid()); - Assert.assertTrue(collectionDir.exists()); // collection directory created + assertTrue(collectionDir.exists()); // collection directory created // 3 files correctly saved assertThat(downloadedFiles).allMatch(File::exists); for(int i = 0; i < downloadedFiles.size(); i ++) { File downloaded = new File(collectionDir + Characters.SLASH + files.get(i).getName()); - Assert.assertArrayEquals(FileUtils.readFileToByteArray(downloaded), FileUtils.readFileToByteArray(files.get(i))); + assertArrayEquals(FileUtils.readFileToByteArray(downloaded), FileUtils.readFileToByteArray(files.get(i))); } } @@ -108,9 +114,32 @@ public class FileDownloaderTest { File downloadedFile = fileDownloader.downloadSingleFileUsingKeepWeb(file.getName(), collectionToDownload.getUuid(), FILE_DOWNLOAD_TEST_DIR); //then - Assert.assertTrue(downloadedFile.exists()); - Assert.assertEquals(file.getName(), downloadedFile.getName()); - Assert.assertArrayEquals(FileUtils.readFileToByteArray(downloadedFile), FileUtils.readFileToByteArray(file)); + assertTrue(downloadedFile.exists()); + assertEquals(file.getName(), downloadedFile.getName()); + assertArrayEquals(FileUtils.readFileToByteArray(downloadedFile), FileUtils.readFileToByteArray(file)); + } + + @Test + public void testDownloadFileWithResume() throws Exception { + //given + String collectionUuid = "some-collection-uuid"; + String expectedDataString = "testData"; + String fileName = "sample-file-name"; + long start = 0; + Long end = null; + + InputStream inputStream = new ByteArrayInputStream(expectedDataString.getBytes()); + + when(keepWebApiClient.get(collectionUuid, fileName, start, end)).thenReturn(inputStream); + + //when + File downloadedFile = fileDownloader.downloadFileWithResume(collectionUuid, fileName, FILE_DOWNLOAD_TEST_DIR, start, end); + + //then + assertNotNull(downloadedFile); + assertTrue(downloadedFile.exists()); + String actualDataString = Files.readString(downloadedFile.toPath()); + assertEquals("The content of the file does not match the expected data.", expectedDataString, actualDataString); } @After