From cabe78fd23db2fd44deca726243bb5d980f192c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Socha?= <31014760+lukaszsocha2@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:25:43 +0200 Subject: [PATCH] test: Add test for uploading file using stream (#1258) Closes: SDK-3898 --- src/intTest/java/com/box/sdk/BoxFileIT.java | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/intTest/java/com/box/sdk/BoxFileIT.java b/src/intTest/java/com/box/sdk/BoxFileIT.java index 831701a62..92f40a8d5 100644 --- a/src/intTest/java/com/box/sdk/BoxFileIT.java +++ b/src/intTest/java/com/box/sdk/BoxFileIT.java @@ -66,6 +66,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Random; import org.hamcrest.Matchers; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -145,6 +146,31 @@ public void getRepresentationContentSucceeds() throws InterruptedException { } } + @Test + public void uploadFileStreamSucceeds() { + BoxAPIConnection api = jwtApiForServiceAccount(); + BoxFolder folder = getUniqueFolder(api); + + byte[] fileContent = new byte[10000]; + new Random().nextBytes(fileContent); + + BoxFile uploadedFile = null; + try { + InputStream uploadStream = new ByteArrayInputStream(fileContent); + BoxFile.Info uploadedFileInfo = folder.uploadFile(uploadStream, BoxFileIT.generateString()); + uploadedFile = uploadedFileInfo.getResource(); + + ByteArrayOutputStream downloadStream = new ByteArrayOutputStream(); + uploadedFile.download(downloadStream); + byte[] downloadedFileContent = downloadStream.toByteArray(); + + assertThat(downloadedFileContent, is(equalTo(fileContent))); + assertThat(folder, hasItem(Matchers.hasProperty("ID", equalTo(uploadedFile.getID())))); + } finally { + deleteFile(uploadedFile); + } + } + @Test public void uploadAndDownloadFileSucceeds() throws IOException { BoxAPIConnection api = jwtApiForServiceAccount();