|
33 | 33 | import org.apache.commons.lang3.RandomStringUtils; |
34 | 34 | import org.junit.jupiter.api.Test; |
35 | 35 | import software.amazon.awssdk.awscore.DefaultAwsResponseMetadata; |
| 36 | +import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration; |
36 | 37 | import software.amazon.awssdk.core.SdkField; |
37 | 38 | import software.amazon.awssdk.core.SdkPojo; |
38 | 39 | import software.amazon.awssdk.http.SdkHttpFullResponse; |
@@ -244,6 +245,160 @@ void toListPartsRequest_putObject_shouldCopyProperties() { |
244 | 245 | assertThat(convertedObject.uploadId()).isEqualTo("uploadId"); |
245 | 246 | } |
246 | 247 |
|
| 248 | + @Test |
| 249 | + void toCreateMultipartUploadRequest_putObjectWithOverrideConfig_shouldPropagateOverrideConfig() { |
| 250 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 251 | + .putHeader("x-custom", "value") |
| 252 | + .build(); |
| 253 | + PutObjectRequest request = PutObjectRequest.builder() |
| 254 | + .bucket("bucket") |
| 255 | + .key("key") |
| 256 | + .overrideConfiguration(overrideConfig) |
| 257 | + .build(); |
| 258 | + CreateMultipartUploadRequest converted = SdkPojoConversionUtils.toCreateMultipartUploadRequest(request); |
| 259 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 260 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 261 | + } |
| 262 | + |
| 263 | + @Test |
| 264 | + void toUploadPartRequest_withOverrideConfig_shouldPropagateOverrideConfig() { |
| 265 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 266 | + .putHeader("x-custom", "value") |
| 267 | + .build(); |
| 268 | + PutObjectRequest request = PutObjectRequest.builder() |
| 269 | + .bucket("bucket") |
| 270 | + .key("key") |
| 271 | + .overrideConfiguration(overrideConfig) |
| 272 | + .build(); |
| 273 | + UploadPartRequest converted = SdkPojoConversionUtils.toUploadPartRequest(request, 1, "uploadId"); |
| 274 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 275 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 276 | + } |
| 277 | + |
| 278 | + @Test |
| 279 | + void toCompleteMultipartUploadRequest_withOverrideConfig_shouldPropagateOverrideConfig() { |
| 280 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 281 | + .putHeader("x-custom", "value") |
| 282 | + .build(); |
| 283 | + PutObjectRequest request = PutObjectRequest.builder() |
| 284 | + .bucket("bucket") |
| 285 | + .key("key") |
| 286 | + .overrideConfiguration(overrideConfig) |
| 287 | + .build(); |
| 288 | + CompletedPart[] parts = { CompletedPart.builder().partNumber(1).build() }; |
| 289 | + CompleteMultipartUploadRequest converted = |
| 290 | + SdkPojoConversionUtils.toCompleteMultipartUploadRequest(request, "uploadId", parts, 100L); |
| 291 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 292 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 293 | + } |
| 294 | + |
| 295 | + @Test |
| 296 | + void toAbortMultipartUploadRequest_putObjectWithOverrideConfig_shouldPropagateOverrideConfig() { |
| 297 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 298 | + .putHeader("x-custom", "value") |
| 299 | + .build(); |
| 300 | + PutObjectRequest request = PutObjectRequest.builder() |
| 301 | + .bucket("bucket") |
| 302 | + .key("key") |
| 303 | + .overrideConfiguration(overrideConfig) |
| 304 | + .build(); |
| 305 | + AbortMultipartUploadRequest converted = SdkPojoConversionUtils.toAbortMultipartUploadRequest(request).build(); |
| 306 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 307 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 308 | + } |
| 309 | + |
| 310 | + @Test |
| 311 | + void toListPartsRequest_withOverrideConfig_shouldPropagateOverrideConfig() { |
| 312 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 313 | + .putHeader("x-custom", "value") |
| 314 | + .build(); |
| 315 | + PutObjectRequest request = PutObjectRequest.builder() |
| 316 | + .bucket("bucket") |
| 317 | + .key("key") |
| 318 | + .overrideConfiguration(overrideConfig) |
| 319 | + .build(); |
| 320 | + ListPartsRequest converted = SdkPojoConversionUtils.toListPartsRequest("uploadId", request); |
| 321 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 322 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 323 | + } |
| 324 | + |
| 325 | + @Test |
| 326 | + void toCreateMultipartUploadRequest_copyObjectWithOverrideConfig_shouldPropagateOverrideConfig() { |
| 327 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 328 | + .putHeader("x-custom", "value") |
| 329 | + .build(); |
| 330 | + CopyObjectRequest request = CopyObjectRequest.builder() |
| 331 | + .sourceBucket("src") |
| 332 | + .sourceKey("srcKey") |
| 333 | + .destinationBucket("dst") |
| 334 | + .destinationKey("dstKey") |
| 335 | + .overrideConfiguration(overrideConfig) |
| 336 | + .build(); |
| 337 | + CreateMultipartUploadRequest converted = SdkPojoConversionUtils.toCreateMultipartUploadRequest(request); |
| 338 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 339 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 340 | + } |
| 341 | + |
| 342 | + @Test |
| 343 | + void toHeadObjectRequest_withOverrideConfig_shouldPropagateOverrideConfig() { |
| 344 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 345 | + .putHeader("x-custom", "value") |
| 346 | + .build(); |
| 347 | + CopyObjectRequest request = CopyObjectRequest.builder() |
| 348 | + .sourceBucket("src") |
| 349 | + .sourceKey("srcKey") |
| 350 | + .overrideConfiguration(overrideConfig) |
| 351 | + .build(); |
| 352 | + HeadObjectRequest converted = SdkPojoConversionUtils.toHeadObjectRequest(request); |
| 353 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 354 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 355 | + } |
| 356 | + |
| 357 | + @Test |
| 358 | + void toAbortMultipartUploadRequest_copyObjectWithOverrideConfig_shouldPropagateOverrideConfig() { |
| 359 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 360 | + .putHeader("x-custom", "value") |
| 361 | + .build(); |
| 362 | + CopyObjectRequest request = CopyObjectRequest.builder() |
| 363 | + .sourceBucket("src") |
| 364 | + .sourceKey("srcKey") |
| 365 | + .destinationBucket("dst") |
| 366 | + .destinationKey("dstKey") |
| 367 | + .overrideConfiguration(overrideConfig) |
| 368 | + .build(); |
| 369 | + AbortMultipartUploadRequest converted = SdkPojoConversionUtils.toAbortMultipartUploadRequest(request).build(); |
| 370 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 371 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 372 | + } |
| 373 | + |
| 374 | + @Test |
| 375 | + void toUploadPartCopyRequest_withOverrideConfig_shouldPropagateOverrideConfig() { |
| 376 | + AwsRequestOverrideConfiguration overrideConfig = AwsRequestOverrideConfiguration.builder() |
| 377 | + .putHeader("x-custom", "value") |
| 378 | + .build(); |
| 379 | + CopyObjectRequest request = CopyObjectRequest.builder() |
| 380 | + .sourceBucket("src") |
| 381 | + .sourceKey("srcKey") |
| 382 | + .destinationBucket("dst") |
| 383 | + .destinationKey("dstKey") |
| 384 | + .overrideConfiguration(overrideConfig) |
| 385 | + .build(); |
| 386 | + UploadPartCopyRequest converted = SdkPojoConversionUtils.toUploadPartCopyRequest(request, 1, "uploadId", |
| 387 | + "bytes=0-1024"); |
| 388 | + assertThat(converted.overrideConfiguration()).isPresent(); |
| 389 | + assertThat(converted.overrideConfiguration().get()).isEqualTo(overrideConfig); |
| 390 | + } |
| 391 | + |
| 392 | + @Test |
| 393 | + void toCreateMultipartUploadRequest_putObjectWithoutOverrideConfig_shouldNotHaveOverrideConfig() { |
| 394 | + PutObjectRequest request = PutObjectRequest.builder() |
| 395 | + .bucket("bucket") |
| 396 | + .key("key") |
| 397 | + .build(); |
| 398 | + CreateMultipartUploadRequest converted = SdkPojoConversionUtils.toCreateMultipartUploadRequest(request); |
| 399 | + assertThat(converted.overrideConfiguration()).isNotPresent(); |
| 400 | + } |
| 401 | + |
247 | 402 | private static void verifyFieldsAreCopied(SdkPojo requestConvertedFrom, |
248 | 403 | SdkPojo requestConvertedTo, |
249 | 404 | Set<String> fieldsToIgnore, |
|
0 commit comments