Skip to content

Commit 0d4fe5d

Browse files
committed
Add AWS query protocol tests
1 parent 6e23720 commit 0d4fe5d

17 files changed

+1827
-10
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// This file defines test cases that test the basics of empty input and
2+
// output shape serialization.
3+
4+
$version: "0.5.0"
5+
6+
namespace aws.protocols.tests.query
7+
8+
use smithy.test#httpRequestTests
9+
use smithy.test#httpResponseTests
10+
11+
/// The example tests how requests and responses are serialized when there's
12+
/// no request or response payload because the operation has no input or output.
13+
///
14+
/// While this should be rare, code generators must support this.
15+
operation NoInputAndNoOutput()
16+
17+
apply NoInputAndNoOutput @httpRequestTests([
18+
{
19+
id: "QueryNoInputAndNoOutput",
20+
description: "No input serializes no additional query params",
21+
protocol: "aws.query",
22+
method: "POST",
23+
uri: "/",
24+
headers: {
25+
"Content-Type": "application/x-www-form-urlencoded"
26+
},
27+
body: """
28+
Action=NoInputAndNoOutput
29+
&Version=2020-01-08""",
30+
bodyMediaType: "application/x-www-form-urlencoded"
31+
}
32+
])
33+
34+
apply NoInputAndNoOutput @httpResponseTests([
35+
{
36+
id: "QueryNoInputAndNoOutput",
37+
description: "No output serializes no payload",
38+
protocol: "aws.query",
39+
code: 200,
40+
body: ""
41+
}
42+
])
43+
44+
/// The example tests how requests and responses are serialized when there's
45+
/// no request or response payload because the operation has no input and the
46+
/// output is empty.
47+
///
48+
/// While this should be rare, code generators must support this.
49+
operation NoInputAndOutput() -> NoInputAndOutputOutput
50+
51+
apply NoInputAndOutput @httpRequestTests([
52+
{
53+
id: "QueryNoInputAndOutput",
54+
description: "No input serializes no payload",
55+
protocol: "aws.query",
56+
method: "POST",
57+
uri: "/",
58+
headers: {
59+
"Content-Type": "application/x-www-form-urlencoded"
60+
},
61+
body: """
62+
Action=NoInputAndOutput
63+
&Version=2020-01-08""",
64+
bodyMediaType: "application/x-www-form-urlencoded"
65+
}
66+
])
67+
68+
apply NoInputAndOutput @httpResponseTests([
69+
{
70+
id: "QueryNoInputAndOutput",
71+
description: "Empty output serializes no payload",
72+
protocol: "aws.query",
73+
code: 200,
74+
body: ""
75+
}
76+
])
77+
78+
structure NoInputAndOutputOutput {}
79+
80+
/// The example tests how requests and responses are serialized when there's
81+
/// no request or response payload because the operation has an empty input
82+
/// and empty output structure that reuses the same shape.
83+
///
84+
/// While this should be rare, code generators must support this.
85+
operation EmptyInputAndEmptyOutput(EmptyInputAndEmptyOutputInput) -> EmptyInputAndEmptyOutputOutput
86+
87+
apply EmptyInputAndEmptyOutput @httpRequestTests([
88+
{
89+
id: "QueryEmptyInputAndEmptyOutput",
90+
description: "Empty input serializes no extra query params",
91+
protocol: "aws.query",
92+
method: "POST",
93+
uri: "/",
94+
headers: {
95+
"Content-Type": "application/x-www-form-urlencoded"
96+
},
97+
body: """
98+
Action=EmptyInputAndEmptyOutput
99+
&Version=2020-01-08""",
100+
bodyMediaType: "application/x-www-form-urlencoded"
101+
},
102+
])
103+
104+
apply EmptyInputAndEmptyOutput @httpResponseTests([
105+
{
106+
id: "QueryEmptyInputAndEmptyOutput",
107+
description: "Empty output serializes no payload",
108+
protocol: "aws.query",
109+
code: 200,
110+
body: ""
111+
},
112+
])
113+
114+
structure EmptyInputAndEmptyOutputInput {}
115+
structure EmptyInputAndEmptyOutputOutput {}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// This file defines test cases that test list query serialization.
2+
3+
$version: "0.5.0"
4+
5+
namespace aws.protocols.tests.query
6+
7+
use aws.protocols.tests.shared#EpochSeconds
8+
use aws.protocols.tests.shared#FooEnum
9+
use aws.protocols.tests.shared#GreetingList
10+
use aws.protocols.tests.shared#StringList
11+
use smithy.test#httpRequestTests
12+
13+
/// This test serializes simple and complex lists.
14+
operation QueryLists(QueryListsInput)
15+
16+
apply QueryLists @httpRequestTests([
17+
{
18+
id: "QueryLists",
19+
description: "Serializes query lists",
20+
protocol: "aws.query",
21+
method: "POST",
22+
uri: "/",
23+
headers: {
24+
"Content-Type": "application/x-www-form-urlencoded"
25+
},
26+
body: """
27+
Action=QueryLists
28+
&Version=2020-01-08
29+
&ListArg.member.1=foo
30+
&ListArg.member.2=bar
31+
&ListArg.member.3=baz
32+
&ComplexListArg.member.1.hi=hello
33+
&ComplexListArg.member.2.hi=hola""",
34+
bodyMediaType: "application/x-www-form-urlencoded",
35+
params: {
36+
ListArg: ["foo", "bar", "baz"],
37+
ComplexListArg: [
38+
{
39+
hi: "hello"
40+
},
41+
{
42+
hi: "hola"
43+
}
44+
]
45+
}
46+
},
47+
{
48+
id: "EmptyQueryLists",
49+
description: "Does not serialize empty query lists",
50+
protocol: "aws.query",
51+
method: "POST",
52+
uri: "/",
53+
headers: {
54+
"Content-Type": "application/x-www-form-urlencoded"
55+
},
56+
body: """
57+
Action=QueryLists
58+
&Version=2020-01-08""",
59+
bodyMediaType: "application/x-www-form-urlencoded",
60+
params: {
61+
ListArg: []
62+
}
63+
},
64+
{
65+
id: "FlattenedQueryLists",
66+
description: "Flattens query lists by repeating the member name and removing the member element",
67+
protocol: "aws.query",
68+
method: "POST",
69+
uri: "/",
70+
headers: {
71+
"Content-Type": "application/x-www-form-urlencoded"
72+
},
73+
body: """
74+
Action=QueryLists
75+
&Version=2020-01-08
76+
&FlattenedListArg.1=A
77+
&FlattenedListArg.2=B""",
78+
bodyMediaType: "application/x-www-form-urlencoded",
79+
params: {
80+
FlattenedListArg: ["A", "B"]
81+
}
82+
},
83+
{
84+
id: "QueryListArgWithXmlNameMember",
85+
description: "Changes the member of lists using xmlName trait",
86+
protocol: "aws.query",
87+
method: "POST",
88+
uri: "/",
89+
headers: {
90+
"Content-Type": "application/x-www-form-urlencoded"
91+
},
92+
body: """
93+
Action=QueryLists
94+
&Version=2020-01-08
95+
&ListArgWithXmlNameMember.item.1=A
96+
&ListArgWithXmlNameMember.item.2=B""",
97+
bodyMediaType: "application/x-www-form-urlencoded",
98+
params: {
99+
ListArgWithXmlNameMember: ["A", "B"]
100+
}
101+
},
102+
{
103+
id: "QueryFlattenedListArgWithXmlName",
104+
description: "Changes the name of flattened lists using xmlName trait on the structure member",
105+
protocol: "aws.query",
106+
method: "POST",
107+
uri: "/",
108+
headers: {
109+
"Content-Type": "application/x-www-form-urlencoded"
110+
},
111+
body: """
112+
Action=QueryLists
113+
&Version=2020-01-08
114+
&Hi.1=A
115+
&Hi.2=B""",
116+
bodyMediaType: "application/x-www-form-urlencoded",
117+
params: {
118+
ListArgWithXmlNameMember: ["A", "B"]
119+
}
120+
},
121+
])
122+
123+
structure QueryListsInput {
124+
ListArg: StringList,
125+
ComplexListArg: GreetingList,
126+
127+
@xmlFlattened
128+
FlattenedListArg: StringList,
129+
130+
ListArgWithXmlNameMember: ListWithXmlName,
131+
132+
// Notice that the xmlName on the targeted list member is ignored.
133+
@xmlFlattened
134+
@xmlName("Hi")
135+
FlattenedListArgWithXmlName: ListWithXmlName,
136+
}
137+
138+
list ListWithXmlName {
139+
@xmlName("item")
140+
member: String
141+
}

0 commit comments

Comments
 (0)