Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add test for uploading file using stream #1258

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading