Skip to content

Commit f2a1388

Browse files
committed
Add protocol test
1 parent fd9411d commit f2a1388

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

test/protocol-tests/src/main/resources/codegen-resources/restjson/service-2.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@
255255
"requestUri":"/2016-03-11/documentInputOperation"
256256
},
257257
"input":{"shape":"StructureWithDocumentMember"}
258+
},
259+
"NestedLocationOperation":{
260+
"name":"NestedLocationOperation",
261+
"http":{
262+
"method":"POST",
263+
"requestUri":"/2016-03-11/nestedLocationOperation"
264+
},
265+
"input":{"shape":"NestedLocationOperationInput"}
258266
}
259267
},
260268
"shapes":{
@@ -782,6 +790,28 @@
782790
"StringMember":{"shape":"String"}
783791
}
784792
},
793+
"NestedLocationOperationInput":{
794+
"type":"structure",
795+
"members":{
796+
"TopLevelQueryParam":{
797+
"shape":"String",
798+
"location":"querystring",
799+
"locationName":"topLevel"
800+
},
801+
"Nested":{"shape":"NestedShapeWithLocations"}
802+
}
803+
},
804+
"NestedShapeWithLocations":{
805+
"type":"structure",
806+
"members":{
807+
"NestedQueryParam":{
808+
"shape":"String",
809+
"location":"querystring",
810+
"locationName":"shouldBeIgnored"
811+
},
812+
"StringMember":{"shape":"String"}
813+
}
814+
},
785815
"StatusCodeInOutputStructure":{
786816
"type":"structure",
787817
"members":{
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.protocol.tests;
17+
18+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
19+
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
20+
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
21+
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
22+
import static com.github.tomakehurst.wiremock.client.WireMock.post;
23+
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
24+
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
25+
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
26+
27+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
28+
import java.net.URI;
29+
import org.junit.Before;
30+
import org.junit.Rule;
31+
import org.junit.Test;
32+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
33+
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
34+
import software.amazon.awssdk.regions.Region;
35+
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient;
36+
import software.amazon.awssdk.services.protocolrestjson.model.NestedLocationOperationRequest;
37+
import software.amazon.awssdk.services.protocolrestjson.model.NestedShapeWithLocations;
38+
39+
/**
40+
* Verifies that HTTP binding locations on non-input shapes are ignored per the Smithy spec,
41+
* and the members are serialized into the request body instead.
42+
*/
43+
public class NestedLocationSerializationTest {
44+
45+
@Rule
46+
public WireMockRule wireMock = new WireMockRule(0);
47+
48+
private ProtocolRestJsonClient client;
49+
50+
@Before
51+
public void setup() {
52+
client = ProtocolRestJsonClient.builder()
53+
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid")))
54+
.region(Region.US_EAST_1)
55+
.endpointOverride(URI.create("http://localhost:" + wireMock.port()))
56+
.build();
57+
}
58+
59+
@Test
60+
public void nestedMemberWithLocation_serializedToBodyNotQueryParam() {
61+
stubFor(post(anyUrl()).willReturn(aResponse().withStatus(200).withBody("{}")));
62+
63+
client.nestedLocationOperation(NestedLocationOperationRequest.builder()
64+
.topLevelQueryParam("topValue")
65+
.nested(NestedShapeWithLocations.builder()
66+
.nestedQueryParam("nestedValue")
67+
.stringMember("hello")
68+
.build())
69+
.build());
70+
71+
verify(postRequestedFor(anyUrl()).withQueryParam("topLevel", equalTo("topValue")));
72+
73+
verify(postRequestedFor(anyUrl()).withRequestBody(
74+
equalToJson("{\"Nested\":{\"shouldBeIgnored\":\"nestedValue\",\"StringMember\":\"hello\"}}")));
75+
}
76+
}

0 commit comments

Comments
 (0)