Skip to content

Commit c6cef96

Browse files
committed
added unit test for the fix
1 parent 20ff084 commit c6cef96

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS Query Protocol",
4+
"contributor": "",
5+
"description": "Fixed the bug that EC2 DescribeInstances query uses locale-dependent formatting"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.protocols.query;
17+
18+
import static org.junit.Assert.assertEquals;
19+
20+
import java.util.Arrays;
21+
import java.util.Collections;
22+
import java.util.List;
23+
import java.util.Locale;
24+
import java.util.Map;
25+
import org.junit.jupiter.api.Test;
26+
import software.amazon.awssdk.core.SdkField;
27+
import software.amazon.awssdk.core.protocol.MarshallLocation;
28+
import software.amazon.awssdk.core.protocol.MarshallingType;
29+
import software.amazon.awssdk.core.traits.ListTrait;
30+
import software.amazon.awssdk.core.traits.LocationTrait;
31+
import software.amazon.awssdk.http.SdkHttpFullRequest;
32+
import software.amazon.awssdk.protocols.query.internal.marshall.ListQueryMarshaller;
33+
import software.amazon.awssdk.protocols.query.internal.marshall.QueryMarshaller;
34+
import software.amazon.awssdk.protocols.query.internal.marshall.QueryMarshallerContext;
35+
import software.amazon.awssdk.protocols.query.internal.marshall.QueryMarshallerRegistry;
36+
37+
38+
public class ListQueryMarshallerTest {
39+
40+
@Test
41+
public void localeSetAsNe_ParsedCorrectly() {
42+
Locale defaultLocale = Locale.getDefault();
43+
Locale.setDefault(new Locale("ne"));
44+
45+
ListQueryMarshaller marshaller = ListQueryMarshaller.ec2Query();
46+
47+
QueryMarshallerContext context = createTestContext();
48+
List<String> testList = Arrays.asList("value1", "value2");
49+
SdkField<List<?>> field = createTestField();
50+
51+
marshaller.marshall(context, "TestParam", testList, field);
52+
53+
Map<String, List<String>> params = context.request().rawQueryParameters();
54+
55+
assertEquals(Collections.singletonList("value1"), params.get("TestParam.1"));
56+
assertEquals(Collections.singletonList("value2"), params.get("TestParam.2"));
57+
Locale.setDefault(defaultLocale);
58+
}
59+
60+
private QueryMarshallerContext createTestContext() {
61+
62+
QueryMarshaller<String> stringMarshaller = (context, path, val, field) ->
63+
context.request().putRawQueryParameter(path, val);
64+
65+
QueryMarshallerRegistry registry = QueryMarshallerRegistry.builder()
66+
.marshaller(MarshallingType.STRING, stringMarshaller)
67+
.build();
68+
69+
return QueryMarshallerContext.builder()
70+
.request(SdkHttpFullRequest.builder())
71+
.marshallerRegistry(registry)
72+
.build();
73+
}
74+
75+
76+
77+
private SdkField<List<?>> createTestField() {
78+
SdkField<?> memberField = SdkField.builder(MarshallingType.STRING)
79+
.memberName("item")
80+
.traits(LocationTrait.builder()
81+
.location(MarshallLocation.PAYLOAD)
82+
.locationName("item")
83+
.build())
84+
.build();
85+
86+
ListTrait listTrait = ListTrait.builder()
87+
.memberFieldInfo(memberField)
88+
.memberLocationName("item")
89+
.isFlattened(true)
90+
.build();
91+
92+
return SdkField.builder(MarshallingType.LIST)
93+
.memberName("TestParam")
94+
.traits(LocationTrait.builder()
95+
.location(MarshallLocation.QUERY_PARAM)
96+
.locationName("TestParam")
97+
.build(),listTrait)
98+
.build();
99+
}
100+
}

0 commit comments

Comments
 (0)