Skip to content

Commit

Permalink
Merge branch 'main' into allow-overriding-okhttp-call-creation-method
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsocha2 authored Jul 15, 2024
2 parents bf231fe + cabe78f commit 029dde3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/intTest/java/com/box/sdk/BoxFileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.<BoxItem.Info>hasProperty("ID", equalTo(uploadedFile.getID()))));
} finally {
deleteFile(uploadedFile);
}
}

@Test
public void uploadAndDownloadFileSucceeds() throws IOException {
BoxAPIConnection api = jwtApiForServiceAccount();
Expand Down

0 comments on commit 029dde3

Please sign in to comment.