Skip to content

Commit dfea2d8

Browse files
committed
add completeuploadresponse mapping to turesponse object
1 parent b3572ed commit dfea2d8

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-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/ResponseMapperTests.cs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,117 @@ public void ValidateTransferUtilityUploadResponseDefinitionCompleteness()
245245
"TransferUtilityUploadResponse");
246246
}
247247

248+
[TestMethod]
249+
[TestCategory("S3")]
250+
public void MapCompleteMultipartUploadResponse_AllMappedProperties_WorkCorrectly()
251+
{
252+
// Get the expected mappings from JSON
253+
var completeMultipartMappings = _mappingJson.RootElement
254+
.GetProperty("Conversion")
255+
.GetProperty("CompleteMultipartResponse")
256+
.GetProperty("UploadResponse")
257+
.EnumerateArray()
258+
.Select(prop => prop.GetString())
259+
.ToList();
260+
261+
// Create source object with dynamically generated test data
262+
var sourceResponse = new CompleteMultipartUploadResponse();
263+
var sourceType = typeof(CompleteMultipartUploadResponse);
264+
var testDataValues = new Dictionary<string, object>();
265+
266+
// Generate test data for each mapped property
267+
foreach (var propertyName in completeMultipartMappings)
268+
{
269+
// Resolve alias to actual property name
270+
var resolvedPropertyName = ResolvePropertyName(propertyName);
271+
var sourceProperty = sourceType.GetProperty(resolvedPropertyName);
272+
if (sourceProperty?.CanWrite == true)
273+
{
274+
var testValue = GenerateTestValue(sourceProperty.PropertyType, propertyName);
275+
sourceProperty.SetValue(sourceResponse, testValue);
276+
testDataValues[propertyName] = testValue;
277+
}
278+
}
279+
280+
// Add inherited properties for comprehensive testing
281+
sourceResponse.HttpStatusCode = HttpStatusCode.OK;
282+
sourceResponse.ContentLength = 2048;
283+
284+
// Map the response
285+
var mappedResponse = ResponseMapper.MapCompleteMultipartUploadResponse(sourceResponse);
286+
Assert.IsNotNull(mappedResponse, "Mapped response should not be null");
287+
288+
// Verify all mapped properties using reflection
289+
var targetType = typeof(TransferUtilityUploadResponse);
290+
var failedAssertions = new List<string>();
291+
292+
foreach (var propertyName in completeMultipartMappings)
293+
{
294+
// Resolve alias to actual property name for reflection lookups
295+
var resolvedPropertyName = ResolvePropertyName(propertyName);
296+
var sourceProperty = sourceType.GetProperty(resolvedPropertyName);
297+
var targetProperty = targetType.GetProperty(resolvedPropertyName);
298+
299+
if (sourceProperty == null)
300+
{
301+
failedAssertions.Add($"Source property '{propertyName}' (resolved to: {resolvedPropertyName}) not found in CompleteMultipartUploadResponse");
302+
continue;
303+
}
304+
305+
if (targetProperty == null)
306+
{
307+
failedAssertions.Add($"Target property '{propertyName}' (resolved to: {resolvedPropertyName}) not found in TransferUtilityUploadResponse");
308+
continue;
309+
}
310+
311+
var sourceValue = sourceProperty.GetValue(sourceResponse);
312+
var targetValue = targetProperty.GetValue(mappedResponse);
313+
314+
// Special handling for complex object comparisons
315+
if (!AreValuesEqual(sourceValue, targetValue))
316+
{
317+
failedAssertions.Add($"{propertyName}: Expected '{sourceValue ?? "null"}', got '{targetValue ?? "null"}'");
318+
}
319+
}
320+
321+
// Test inherited properties
322+
Assert.AreEqual(sourceResponse.HttpStatusCode, mappedResponse.HttpStatusCode, "HttpStatusCode should match");
323+
Assert.AreEqual(sourceResponse.ContentLength, mappedResponse.ContentLength, "ContentLength should match");
324+
325+
// Report any failures
326+
if (failedAssertions.Any())
327+
{
328+
Assert.Fail($"Property mapping failures:\n{string.Join("\n", failedAssertions)}");
329+
}
330+
}
331+
332+
[TestMethod]
333+
[TestCategory("S3")]
334+
public void MapCompleteMultipartUploadResponse_NullValues_HandledCorrectly()
335+
{
336+
// Test null handling scenarios
337+
var testCases = new[]
338+
{
339+
// Test null Expiration
340+
new CompleteMultipartUploadResponse { Expiration = null },
341+
342+
// Test null enum conversions
343+
new CompleteMultipartUploadResponse { ChecksumType = null, RequestCharged = null, ServerSideEncryption = null }
344+
};
345+
346+
foreach (var testCase in testCases)
347+
{
348+
var mapped = ResponseMapper.MapCompleteMultipartUploadResponse(testCase);
349+
Assert.IsNotNull(mapped, "Response should always be mappable");
350+
351+
// Test null handling
352+
if (testCase.Expiration == null)
353+
{
354+
Assert.IsNull(mapped.Expiration, "Null Expiration should map to null");
355+
}
356+
}
357+
}
358+
248359
[TestMethod]
249360
[TestCategory("S3")]
250361
public void ValidateCompleteMultipartUploadResponseConversionCompleteness()

0 commit comments

Comments
 (0)