Skip to content

Commit 4fe5d49

Browse files
committed
Create separate test for async
1 parent 1921476 commit 4fe5d49

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ public void testUploadDownloadDeleteMedia() throws Exception {
9393
ApiResponse<InputStream> downloadMediaApiResponse = controller.getMedia(ACCOUNT_ID, mediaId);
9494
assertEquals("Response Code is not 200", 200, downloadMediaApiResponse.getStatusCode());
9595

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

10198
int bRead;
@@ -107,18 +104,39 @@ public void testUploadDownloadDeleteMedia() throws Exception {
107104

108105
assertArrayEquals("Media download not equal to media upload", fileContents, responseContents);
109106

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-
121107
ApiResponse<Void> deleteMediaApiResponse = controller.deleteMedia(ACCOUNT_ID, mediaId);
122108
assertEquals("Response Code is not 204", 204, deleteMediaApiResponse.getStatusCode());
123109
}
110+
111+
@Test
112+
public void testUploadDownloadDeleteMediaAsync() throws Exception {
113+
final String fileName = "src/test/resources/mediaUpload.png";
114+
final String contentType = "image/png";
115+
116+
File file = new File(fileName);
117+
byte[] fileContents = Files.readAllBytes(file.toPath());
118+
FileWrapper body = new FileWrapper(file, contentType);
119+
120+
final String mediaId = "java-media-test_" + java.util.UUID.randomUUID();
121+
122+
CompletableFuture<ApiResponse<Void>> uploadMediaApiResponseAsync = controller.uploadMediaAsync(ACCOUNT_ID, mediaId, body, contentType, "no-cache");
123+
assertEquals("Response Code is not 204", 204, uploadMediaApiResponseAsync.get().getStatusCode());
124+
125+
CompletableFuture<ApiResponse<InputStream>> asyncDownloadMediaAPiResponse = controller.getMediaAsync(ACCOUNT_ID, mediaId);
126+
assertEquals("Response Code is not 200", 200, asyncDownloadMediaAPiResponse.get().getStatusCode());
127+
128+
InputStream asyncDownloadMediaResponse = asyncDownloadMediaAPiResponse.get().getResult();
129+
130+
int asyncBRead;
131+
ByteArrayOutputStream asyncByteArrayOutputStream = new ByteArrayOutputStream();
132+
while ((asyncBRead = asyncDownloadMediaResponse.read()) != -1){
133+
asyncByteArrayOutputStream.write(asyncBRead);
134+
}
135+
byte[] asyncResponseContents = asyncByteArrayOutputStream.toByteArray();
136+
137+
assertArrayEquals("Media download not equal to media upload", fileContents, asyncResponseContents);
138+
139+
CompletableFuture<ApiResponse<Void>> deleteMediaApiResponseAsync = controller.deleteMediaAsync(ACCOUNT_ID, mediaId);
140+
assertEquals("Response Code is not 204", 204, deleteMediaApiResponseAsync.get().getStatusCode());
141+
}
124142
}

0 commit comments

Comments
 (0)