Skip to content

Commit 2263452

Browse files
Add mapping of CompletemultipartUploadResponse to TransferUtilityUploadResponse (#4060)
1 parent 36f083b commit 2263452

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "patch",
6+
"changeLogMessages": [
7+
"Added CompleteMultipartUploadResponse to TransferUtilityUploadResponse mapping"
8+
]
9+
}
10+
]
11+
}

sdk/src/Services/S3/Custom/Transfer/Internal/ResponseMapper.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,67 @@ internal static TransferUtilityUploadResponse MapPutObjectResponse(PutObjectResp
9999

100100
return response;
101101
}
102+
103+
/// <summary>
104+
/// Maps a CompleteMultipartUploadResponse to TransferUtilityUploadResponse.
105+
/// Uses the field mappings defined in mapping.json "Conversion" -> "CompleteMultipartResponse" -> "UploadResponse".
106+
/// </summary>
107+
/// <param name="source">The CompleteMultipartUploadResponse to map from</param>
108+
/// <returns>A new TransferUtilityUploadResponse with mapped fields</returns>
109+
internal static TransferUtilityUploadResponse MapCompleteMultipartUploadResponse(CompleteMultipartUploadResponse source)
110+
{
111+
if (source == null)
112+
return null;
113+
114+
var response = new TransferUtilityUploadResponse();
115+
116+
// Map all fields as defined in mapping.json "Conversion" -> "CompleteMultipartResponse" -> "UploadResponse"
117+
if (source.IsSetBucketKeyEnabled())
118+
response.BucketKeyEnabled = source.BucketKeyEnabled.GetValueOrDefault();
119+
120+
if (source.IsSetChecksumCRC32())
121+
response.ChecksumCRC32 = source.ChecksumCRC32;
122+
123+
if (source.IsSetChecksumCRC32C())
124+
response.ChecksumCRC32C = source.ChecksumCRC32C;
125+
126+
if (source.IsSetChecksumCRC64NVME())
127+
response.ChecksumCRC64NVME = source.ChecksumCRC64NVME;
128+
129+
if (source.IsSetChecksumSHA1())
130+
response.ChecksumSHA1 = source.ChecksumSHA1;
131+
132+
if (source.IsSetChecksumSHA256())
133+
response.ChecksumSHA256 = source.ChecksumSHA256;
134+
135+
if (source.ChecksumType != null)
136+
response.ChecksumType = source.ChecksumType;
137+
138+
if (source.IsSetETag())
139+
response.ETag = source.ETag;
140+
141+
if (source.Expiration != null)
142+
response.Expiration = source.Expiration;
143+
144+
if (source.IsSetRequestCharged())
145+
response.RequestCharged = source.RequestCharged;
146+
147+
if (source.ServerSideEncryptionMethod != null)
148+
response.ServerSideEncryptionMethod = source.ServerSideEncryptionMethod;
149+
150+
if (source.IsSetServerSideEncryptionKeyManagementServiceKeyId())
151+
response.ServerSideEncryptionKeyManagementServiceKeyId = source.ServerSideEncryptionKeyManagementServiceKeyId;
152+
153+
if (source.IsSetVersionId())
154+
response.VersionId = source.VersionId;
155+
156+
// Copy response metadata
157+
response.ResponseMetadata = source.ResponseMetadata;
158+
response.ContentLength = source.ContentLength;
159+
response.HttpStatusCode = source.HttpStatusCode;
160+
161+
return response;
162+
}
102163

103164
}
104165
}

sdk/test/Services/S3/UnitTests/Custom/EmbeddedResource/property-aliases.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
},
113113
"AbortMultipartUploadRequest": {
114114
"Bucket": "BucketName"
115+
},
116+
"CompleteMultipartUploadResponse": {
117+
"ServerSideEncryption": "ServerSideEncryptionMethod",
118+
"SSEKMSKeyId": "ServerSideEncryptionKeyManagementServiceKeyId"
115119
}
116120
}
117121
}

sdk/test/Services/S3/UnitTests/Custom/ResponseMapperTests.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,56 @@ public void ValidateTransferUtilityUploadResponseDefinitionCompleteness()
487487
"TransferUtilityUploadResponse");
488488
}
489489

490+
[TestMethod]
491+
[TestCategory("S3")]
492+
public void MapCompleteMultipartUploadResponse_AllMappedProperties_WorkCorrectly()
493+
{
494+
ValidateMappingTransferUtilityAndSdkRequests<CompleteMultipartUploadResponse, TransferUtilityUploadResponse>(
495+
new[] { "Conversion", "CompleteMultipartResponse", "UploadResponse" },
496+
(sourceResponse) =>
497+
{
498+
return ResponseMapper.MapCompleteMultipartUploadResponse(sourceResponse);
499+
},
500+
usesHeadersCollection: false,
501+
(sourceResponse) =>
502+
{
503+
sourceResponse.HttpStatusCode = HttpStatusCode.OK;
504+
sourceResponse.ContentLength = 2048;
505+
},
506+
(sourceResponse, targetResponse) =>
507+
{
508+
Assert.AreEqual(sourceResponse.HttpStatusCode, targetResponse.HttpStatusCode, "HttpStatusCode should match");
509+
Assert.AreEqual(sourceResponse.ContentLength, targetResponse.ContentLength, "ContentLength should match");
510+
});
511+
}
512+
513+
[TestMethod]
514+
[TestCategory("S3")]
515+
public void MapCompleteMultipartUploadResponse_NullValues_HandledCorrectly()
516+
{
517+
// Test null handling scenarios
518+
var testCases = new[]
519+
{
520+
// Test null Expiration
521+
new CompleteMultipartUploadResponse { Expiration = null },
522+
523+
// Test null enum conversions
524+
new CompleteMultipartUploadResponse { ChecksumType = null, RequestCharged = null, ServerSideEncryptionMethod = null }
525+
};
526+
527+
foreach (var testCase in testCases)
528+
{
529+
var mapped = ResponseMapper.MapCompleteMultipartUploadResponse(testCase);
530+
Assert.IsNotNull(mapped, "Response should always be mappable");
531+
532+
// Test null handling
533+
if (testCase.Expiration == null)
534+
{
535+
Assert.IsNull(mapped.Expiration, "Null Expiration should map to null");
536+
}
537+
}
538+
}
539+
490540
[TestMethod]
491541
[TestCategory("S3")]
492542
public void ValidateCompleteMultipartUploadResponseConversionCompleteness()

0 commit comments

Comments
 (0)