Skip to content

Commit

Permalink
ProtocolTest: Add protocol test for Unions in REST-XML
Browse files Browse the repository at this point in the history
Adds REST-XML protocol test for union used input and output parameters.
  • Loading branch information
jasdel authored and mtdowling committed Jan 22, 2021
1 parent 8b37522 commit a115f59
Show file tree
Hide file tree
Showing 2 changed files with 279 additions and 0 deletions.
278 changes: 278 additions & 0 deletions smithy-aws-protocol-tests/model/restXml/document-unions.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
// This file defines test cases that serialize synthesized XML documents
// in the payload of HTTP requests and responses.

$version: "1.0"

namespace aws.protocoltests.restxml

use aws.protocols#restXml
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

// This example serializes simple scalar types in the top level XML document.
// Note that headers are not serialized in the payload.
@idempotent
@http(uri: "/XmlUnions", method: "PUT")
operation XmlUnions {
input: XmlUnionsInputOutput,
output: XmlUnionsInputOutput
}

apply XmlUnions @httpRequestTests([
{
id: "XmlUnionsWithStructMember",
documentation: "Serializes union struct member",
protocol: restXml,
method: "PUT",
uri: "/XmlUnions",
body: """
<XmlUnionsInputOutput>
<unionValue>
<structValue>
<stringValue>string</stringValue>
<booleanValue>true</booleanValue>
<byteValue>1</byteValue>
<shortValue>2</shortValue>
<integerValue>3</integerValue>
<longValue>4</longValue>
<floatValue>5.5</floatValue>
<doubleValue>6.5</doubleValue>
</structValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
structValue: {
stringValue: "string",
booleanValue: true,
byteValue: 1,
shortValue: 2,
integerValue: 3,
longValue: 4,
floatValue: 5.5,
doubleValue: 6.5,
},
},
}
},
{
id: "XmlUnionsWithStringMember",
documentation: "serialize union string member",
protocol: restXml,
method: "PUT",
uri: "/XmlUnions",
body: """
<XmlUnionsInputOutput>
<unionValue>
<stringValue>some string</stringValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
stringValue: "some string",
},
}
},
{
id: "XmlUnionsWithBooleanMember",
documentation: "Serializes union boolean member",
protocol: restXml,
method: "PUT",
uri: "/XmlUnions",
body: """
<XmlUnionsInputOutput>
<unionValue>
<booleanValue>true</booleanValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
booleanValue: true,
},
}
},
{
id: "XmlUnionsWithUnionMember",
documentation: "Serializes union union member",
protocol: restXml,
method: "PUT",
uri: "/XmlUnions",
body: """
<XmlUnionsInputOutput>
<unionValue>
<unionValue>
<booleanValue>true</booleanValue>
</unionValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
unionValue: {
booleanValue: true,
},
},
}
},
])

apply XmlUnions @httpResponseTests([
{
id: "XmlUnionsWithStructMember",
documentation: "Serializes union struct member",
protocol: restXml,
code: 200,
body: """
<XmlUnionsInputOutput>
<unionValue>
<structValue>
<stringValue>string</stringValue>
<booleanValue>true</booleanValue>
<byteValue>1</byteValue>
<shortValue>2</shortValue>
<integerValue>3</integerValue>
<longValue>4</longValue>
<floatValue>5.5</floatValue>
<doubleValue>6.5</doubleValue>
</structValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
structValue: {
stringValue: "string",
booleanValue: true,
byteValue: 1,
shortValue: 2,
integerValue: 3,
longValue: 4,
floatValue: 5.5,
doubleValue: 6.5,
},
},
}
},
{
id: "XmlUnionsWithStringMember",
documentation: "Serializes union string member",
protocol: restXml,
code: 200,
body: """
<XmlUnionsInputOutput>
<unionValue>
<stringValue>some string</stringValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
stringValue: "some string",
},
}
},
{
id: "XmlUnionsWithBooleanMember",
documentation: "Serializes union boolean member",
protocol: restXml,
code: 200,
body: """
<XmlUnionsInputOutput>
<unionValue>
<booleanValue>true</booleanValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
booleanValue: true,
},
}
},
{
id: "XmlUnionsWithUnionMember",
documentation: "Serializes union union member",
protocol: restXml,
code: 200,
body: """
<XmlUnionsInputOutput>
<unionValue>
<unionValue>
<booleanValue>true</booleanValue>
</unionValue>
</unionValue>
</XmlUnionsInputOutput>
""",
bodyMediaType: "application/xml",
headers: {
"Content-Type": "application/xml",
},
params: {
unionValue: {
unionValue: {
booleanValue: true,
},
},
}
},
])

structure XmlUnionsInputOutput {
unionValue: XmlUnionShape,
}

union XmlUnionShape {
stringValue: String,
booleanValue: Boolean,
byteValue: Byte,
shortValue: Short,
integerValue: Integer,
longValue: Long,
floatValue: Float,
doubleValue: Double,

unionValue: XmlUnionShape,
structValue: XmlNestedUnionStruct,
}

structure XmlNestedUnionStruct {
stringValue: String,
booleanValue: Boolean,
byteValue: Byte,
shortValue: Short,
integerValue: Integer,
longValue: Long,
floatValue: Float,
doubleValue: Double,
}
1 change: 1 addition & 0 deletions smithy-aws-protocol-tests/model/restXml/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ service RestXml {

// Synthesized XML document body tests
SimpleScalarProperties,
XmlUnions,
XmlBlobs,
XmlTimestamps,
XmlEnums,
Expand Down

0 comments on commit a115f59

Please sign in to comment.