Skip to content

Commit c9687e7

Browse files
committed
add completeuploadresponse mapping to turesponse object
1 parent 352afda commit c9687e7

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
@@ -217,6 +217,117 @@ public void ValidateTransferUtilityUploadResponseDefinitionCompleteness()
217217
"TransferUtilityUploadResponse");
218218
}
219219

220+
[TestMethod]
221+
[TestCategory("S3")]
222+
public void MapCompleteMultipartUploadResponse_AllMappedProperties_WorkCorrectly()
223+
{
224+
// Get the expected mappings from JSON
225+
var completeMultipartMappings = _mappingJson.RootElement
226+
.GetProperty("Conversion")
227+
.GetProperty("CompleteMultipartResponse")
228+
.GetProperty("UploadResponse")
229+
.EnumerateArray()
230+
.Select(prop => prop.GetString())
231+
.ToList();
232+
233+
// Create source object with dynamically generated test data
234+
var sourceResponse = new CompleteMultipartUploadResponse();
235+
var sourceType = typeof(CompleteMultipartUploadResponse);
236+
var testDataValues = new Dictionary<string, object>();
237+
238+
// Generate test data for each mapped property
239+
foreach (var propertyName in completeMultipartMappings)
240+
{
241+
// Resolve alias to actual property name
242+
var resolvedPropertyName = ResolvePropertyName(propertyName);
243+
var sourceProperty = sourceType.GetProperty(resolvedPropertyName);
244+
if (sourceProperty?.CanWrite == true)
245+
{
246+
var testValue = GenerateTestValue(sourceProperty.PropertyType, propertyName);
247+
sourceProperty.SetValue(sourceResponse, testValue);
248+
testDataValues[propertyName] = testValue;
249+
}
250+
}
251+
252+
// Add inherited properties for comprehensive testing
253+
sourceResponse.HttpStatusCode = HttpStatusCode.OK;
254+
sourceResponse.ContentLength = 2048;
255+
256+
// Map the response
257+
var mappedResponse = ResponseMapper.MapCompleteMultipartUploadResponse(sourceResponse);
258+
Assert.IsNotNull(mappedResponse, "Mapped response should not be null");
259+
260+
// Verify all mapped properties using reflection
261+
var targetType = typeof(TransferUtilityUploadResponse);
262+
var failedAssertions = new List<string>();
263+
264+
foreach (var propertyName in completeMultipartMappings)
265+
{
266+
// Resolve alias to actual property name for reflection lookups
267+
var resolvedPropertyName = ResolvePropertyName(propertyName);
268+
var sourceProperty = sourceType.GetProperty(resolvedPropertyName);
269+
var targetProperty = targetType.GetProperty(resolvedPropertyName);
270+
271+
if (sourceProperty == null)
272+
{
273+
failedAssertions.Add($"Source property '{propertyName}' (resolved to: {resolvedPropertyName}) not found in CompleteMultipartUploadResponse");
274+
continue;
275+
}
276+
277+
if (targetProperty == null)
278+
{
279+
failedAssertions.Add($"Target property '{propertyName}' (resolved to: {resolvedPropertyName}) not found in TransferUtilityUploadResponse");
280+
continue;
281+
}
282+
283+
var sourceValue = sourceProperty.GetValue(sourceResponse);
284+
var targetValue = targetProperty.GetValue(mappedResponse);
285+
286+
// Special handling for complex object comparisons
287+
if (!AreValuesEqual(sourceValue, targetValue))
288+
{
289+
failedAssertions.Add($"{propertyName}: Expected '{sourceValue ?? "null"}', got '{targetValue ?? "null"}'");
290+
}
291+
}
292+
293+
// Test inherited properties
294+
Assert.AreEqual(sourceResponse.HttpStatusCode, mappedResponse.HttpStatusCode, "HttpStatusCode should match");
295+
Assert.AreEqual(sourceResponse.ContentLength, mappedResponse.ContentLength, "ContentLength should match");
296+
297+
// Report any failures
298+
if (failedAssertions.Any())
299+
{
300+
Assert.Fail($"Property mapping failures:\n{string.Join("\n", failedAssertions)}");
301+
}
302+
}
303+
304+
[TestMethod]
305+
[TestCategory("S3")]
306+
public void MapCompleteMultipartUploadResponse_NullValues_HandledCorrectly()
307+
{
308+
// Test null handling scenarios
309+
var testCases = new[]
310+
{
311+
// Test null Expiration
312+
new CompleteMultipartUploadResponse { Expiration = null },
313+
314+
// Test null enum conversions
315+
new CompleteMultipartUploadResponse { ChecksumType = null, RequestCharged = null, ServerSideEncryption = null }
316+
};
317+
318+
foreach (var testCase in testCases)
319+
{
320+
var mapped = ResponseMapper.MapCompleteMultipartUploadResponse(testCase);
321+
Assert.IsNotNull(mapped, "Response should always be mappable");
322+
323+
// Test null handling
324+
if (testCase.Expiration == null)
325+
{
326+
Assert.IsNull(mapped.Expiration, "Null Expiration should map to null");
327+
}
328+
}
329+
}
330+
220331
[TestMethod]
221332
[TestCategory("S3")]
222333
public void ValidateCompleteMultipartUploadResponseConversionCompleteness()

0 commit comments

Comments
 (0)