Skip to content

Commit 1921476

Browse files
committed
DX-2439 Update getMediaAsync to accept a Binary Response
Closes #56
1 parent e3912d4 commit 1921476

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/main/java/com/bandwidth/messaging/controllers/APIController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public CompletableFuture<ApiResponse<InputStream>> getMediaAsync(
215215
return makeHttpCallAsync(() -> buildGetMediaRequest(accountId, mediaId),
216216
req -> authManagers.get("messaging").applyAsync(req)
217217
.thenCompose(request -> getClientInstance()
218-
.executeAsync(request, false)),
218+
.executeAsync(request, true)),
219219
context -> handleGetMediaResponse(context));
220220
}
221221

@@ -861,4 +861,4 @@ private ApiResponse<BandwidthMessage> handleCreateMessageResponse(
861861
return new ApiResponse<BandwidthMessage>(response.getStatusCode(), response.getHeaders(), result);
862862
}
863863

864-
}
864+
}

src/test/java/com/bandwidth/MessagingApiTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.InputStream;
1414
import java.nio.file.Files;
1515
import java.util.Collections;
16+
import java.util.concurrent.CompletableFuture;
1617

1718
import org.junit.*;
1819
import static org.junit.Assert.*;
@@ -92,6 +93,9 @@ public void testUploadDownloadDeleteMedia() throws Exception {
9293
ApiResponse<InputStream> downloadMediaApiResponse = controller.getMedia(ACCOUNT_ID, mediaId);
9394
assertEquals("Response Code is not 200", 200, downloadMediaApiResponse.getStatusCode());
9495

96+
CompletableFuture<ApiResponse<InputStream>> asyncDownloadMediaAPiResponse = controller.getMediaAsync(ACCOUNT_ID, mediaId);
97+
assertEquals("Response Code is not 200", 200, asyncDownloadMediaAPiResponse.get().getStatusCode());
98+
9599
InputStream downloadMediaResponse = downloadMediaApiResponse.getResult();
96100

97101
int bRead;
@@ -103,7 +107,18 @@ public void testUploadDownloadDeleteMedia() throws Exception {
103107

104108
assertArrayEquals("Media download not equal to media upload", fileContents, responseContents);
105109

110+
InputStream asyncDownloadMediaResponse = asyncDownloadMediaAPiResponse.get().getResult();
111+
112+
int asyncBRead;
113+
ByteArrayOutputStream asyncByteArrayOutputStream = new ByteArrayOutputStream();
114+
while ((asyncBRead = asyncDownloadMediaResponse.read()) != -1){
115+
asyncByteArrayOutputStream.write(asyncBRead);
116+
}
117+
byte[] asyncResponseContents = asyncByteArrayOutputStream.toByteArray();
118+
119+
assertArrayEquals("Media download not equal to media upload", fileContents, asyncResponseContents);
120+
106121
ApiResponse<Void> deleteMediaApiResponse = controller.deleteMedia(ACCOUNT_ID, mediaId);
107122
assertEquals("Response Code is not 204", 204, deleteMediaApiResponse.getStatusCode());
108123
}
109-
}
124+
}

0 commit comments

Comments
 (0)