Skip to content

Commit 84a017a

Browse files
committed
Update integration tests
1 parent 61e1f91 commit 84a017a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/intTest/java/com/box/sdk/BoxFileIT.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.box.sdk;
22

3+
import static com.box.sdk.BinaryBodyUtils.writeStream;
34
import static com.box.sdk.BoxApiProvider.jwtApiForServiceAccount;
45
import static com.box.sdk.BoxFile.ALL_VERSION_FIELDS;
6+
import static com.box.sdk.BoxFile.CONTENT_URL_TEMPLATE;
57
import static com.box.sdk.BoxRetentionPolicyAssignment.createAssignmentToFolder;
68
import static com.box.sdk.BoxSharedLink.Access.OPEN;
79
import static com.box.sdk.CleanupTools.deleteFile;
@@ -237,10 +239,17 @@ public void uploadAndDownloadFileUseZstdSucceeds() throws IOException {
237239
BoxFile file = null;
238240
try {
239241
file = uploadSampleFileToUniqueFolder(api, fileName);
242+
240243
ByteArrayOutputStream downloadStream = new ByteArrayOutputStream();
241244
ProgressListener mockDownloadListener = mock(ProgressListener.class);
242-
file.download(downloadStream, mockDownloadListener);
245+
246+
URL url = CONTENT_URL_TEMPLATE.build(api.getBaseURL(), file.getID());
247+
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
248+
BoxAPIResponse response = request.send();
249+
writeStream(response, downloadStream, mockDownloadListener);
250+
243251
byte[] downloadedFileContent = downloadStream.toByteArray();
252+
assertThat(response.getHeaders().get("X-Content-Encoding").get(0), is(equalTo("zstd")));
244253
assertThat(downloadedFileContent, is(equalTo(fileContent)));
245254
} finally {
246255
deleteFile(file);
@@ -259,10 +268,17 @@ public void uploadAndDownloadFileDisabledZstdSucceeds() throws IOException {
259268
BoxFile file = null;
260269
try {
261270
file = uploadSampleFileToUniqueFolder(api, fileName);
271+
262272
ByteArrayOutputStream downloadStream = new ByteArrayOutputStream();
263273
ProgressListener mockDownloadListener = mock(ProgressListener.class);
264-
file.download(downloadStream, mockDownloadListener);
274+
275+
URL url = CONTENT_URL_TEMPLATE.build(api.getBaseURL(), file.getID());
276+
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
277+
BoxAPIResponse response = request.send();
278+
writeStream(response, downloadStream, mockDownloadListener);
279+
265280
byte[] downloadedFileContent = downloadStream.toByteArray();
281+
assertThat(response.getHeaders().get("X-Content-Encoding"), is(nullValue()));
266282
assertThat(downloadedFileContent, is(equalTo(fileContent)));
267283
} finally {
268284
deleteFile(file);

src/main/java/com/box/sdk/ZstdInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public Response intercept(Chain chain) throws IOException {
6565

6666
return response.newBuilder()
6767
.body(decompressedBody)
68-
.removeHeader("X-Content-Encoding")
68+
.addHeader("X-Content-Encoding", contentEncoding)
69+
.removeHeader("Content-Encoding")
6970
.removeHeader("Content-Length")
7071
.build();
7172
}

0 commit comments

Comments
 (0)