|
17 | 17 | import static org.apache.commons.lang3.RandomStringUtils.randomAscii;
|
18 | 18 | import static org.assertj.core.api.Assertions.assertThat;
|
19 | 19 |
|
| 20 | +import java.io.ByteArrayInputStream; |
20 | 21 | import java.net.URL;
|
21 | 22 | import java.nio.charset.StandardCharsets;
|
22 | 23 | import java.nio.file.Path;
|
|
51 | 52 | import software.amazon.awssdk.services.s3.presignedurl.model.PresignedUrlGetObjectRequest;
|
52 | 53 | import software.amazon.awssdk.services.s3.utils.S3TestUtils;
|
53 | 54 | import software.amazon.awssdk.testutils.service.S3BucketUtils;
|
| 55 | +import software.amazon.awssdk.utils.Md5Utils; |
54 | 56 |
|
55 | 57 | /**
|
56 | 58 | * Abstract test suite for AsyncPresignedUrlManager integration tests.
|
@@ -125,15 +127,24 @@ void getObject_withValidPresignedUrl_returnsContent(String testDescription,
|
125 | 127 | PresignedUrlGetObjectRequest request = createRequestForKey(objectKey);
|
126 | 128 |
|
127 | 129 | CompletableFuture<ResponseBytes<GetObjectResponse>> future =
|
128 |
| - presignedUrlManager.getObject(request, AsyncResponseTransformer.toBytes()); |
| 130 | + presignedUrlManager.getObject(request, AsyncResponseTransformer.toBytes()); |
129 | 131 | ResponseBytes<GetObjectResponse> response = future.get();
|
130 | 132 |
|
131 | 133 | assertThat(response).isNotNull();
|
132 | 134 | if (expectedContent != null) {
|
133 | 135 | assertThat(response.asUtf8String()).isEqualTo(expectedContent);
|
134 | 136 | assertThat(response.response().contentLength()).isEqualTo(expectedContent.length());
|
| 137 | + } else { |
| 138 | + try (ByteArrayInputStream originalStream = new ByteArrayInputStream(testLargeObjectContent); |
| 139 | + ByteArrayInputStream downloadedStream = new ByteArrayInputStream(response.asByteArray())) { |
| 140 | + |
| 141 | + String originalMd5 = Md5Utils.md5AsBase64(originalStream); |
| 142 | + String downloadedMd5 = Md5Utils.md5AsBase64(downloadedStream); |
| 143 | + assertThat(downloadedMd5).isEqualTo(originalMd5); |
| 144 | + assertThat(response.asByteArray().length).isEqualTo(testLargeObjectContent.length); |
| 145 | + } |
| 146 | + assertThat(response.response()).isNotNull(); |
135 | 147 | }
|
136 |
| - assertThat(response.response()).isNotNull(); |
137 | 148 | }
|
138 | 149 |
|
139 | 150 | @Test
|
|
0 commit comments