Skip to content

Commit f3d3476

Browse files
committed
Update tests
1 parent 067b942 commit f3d3476

File tree

8 files changed

+48
-10
lines changed

8 files changed

+48
-10
lines changed

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/model/TestCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public String getId() {
3131
public void setId(String id) {
3232
this.id = id;
3333
}
34+
3435
public String getDescription() {
3536
return description;
3637
}

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/model/Then.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ public class Then {
2929
private final MarshallingAssertion serializedAs;
3030
private final UnmarshallingAssertion deserializedAs;
3131
private final UnmarshallingAssertion errorDeserializedAs;
32+
private final String errorCode;
3233

3334
@JsonCreator
3435
public Then(@JsonProperty("serializedAs") SerializedAs serializedAs,
35-
@JsonProperty("deserializedAs") JsonNode deserializedAs) {
36+
@JsonProperty("deserializedAs") JsonNode deserializedAs,
37+
@JsonProperty("errorCode") String errorCode) {
3638
this.serializedAs = serializedAs;
3739
this.deserializedAs = new UnmarshalledResultAssertion(deserializedAs);
3840
this.errorDeserializedAs = new UnmarshalledErrorAssertion(deserializedAs);
41+
this.errorCode = errorCode;
3942
}
4043

4144
/**
@@ -59,4 +62,12 @@ public UnmarshallingAssertion getUnmarshallingAssertion() {
5962
public UnmarshallingAssertion getErrorUnmarshallingAssertion() {
6063
return errorDeserializedAs;
6164
}
65+
66+
/**
67+
*
68+
* @return The errorCode String to use for error unmarshalling tests
69+
*/
70+
public String getErrorCode() {
71+
return errorCode;
72+
}
6273
}

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/runners/UnmarshallingTestRunner.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@
2525
import com.github.tomakehurst.wiremock.client.WireMock;
2626
import java.lang.reflect.InvocationTargetException;
2727
import java.util.Base64;
28+
import org.junit.Assert;
29+
import software.amazon.awssdk.awscore.exception.AwsErrorDetails;
30+
import software.amazon.awssdk.awscore.exception.AwsServiceException;
2831
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
2932
import software.amazon.awssdk.codegen.model.intermediate.Metadata;
3033
import software.amazon.awssdk.core.sync.ResponseTransformer;
3134
import software.amazon.awssdk.http.AbortableInputStream;
3235
import software.amazon.awssdk.protocol.asserts.unmarshalling.UnmarshallingTestContext;
3336
import software.amazon.awssdk.protocol.model.GivenResponse;
3437
import software.amazon.awssdk.protocol.model.TestCase;
38+
import software.amazon.awssdk.protocol.model.Then;
3539
import software.amazon.awssdk.protocol.reflect.ClientReflector;
3640
import software.amazon.awssdk.protocol.reflect.ShapeModelReflector;
3741
import software.amazon.awssdk.utils.IoUtils;
@@ -90,9 +94,30 @@ private void runErrorUnmarshallTest(TestCase testCase) throws Exception {
9094
throw new IllegalStateException("Test case expected client to throw error");
9195
} catch (InvocationTargetException t) {
9296
String errorName = testCase.getWhen().getErrorName();
93-
testCase.getThen().getErrorUnmarshallingAssertion().assertMatches(
94-
createErrorContext(operationName, errorName), t.getCause());
97+
Throwable cause = t.getCause();
98+
Then then = testCase.getThen();
99+
100+
then.getErrorUnmarshallingAssertion().assertMatches(
101+
createErrorContext(operationName, errorName), cause);
102+
103+
validateErrorCodeIfPresent(then, cause);
104+
}
105+
}
106+
107+
private void validateErrorCodeIfPresent(Then then, Throwable cause) {
108+
String expectedErrorCode = then.getErrorCode();
109+
if (expectedErrorCode != null) {
110+
String actualErrorCode = extractErrorCode(cause);
111+
Assert.assertEquals(expectedErrorCode, actualErrorCode);
112+
}
113+
}
114+
115+
private String extractErrorCode(Throwable cause) {
116+
if (!(cause instanceof AwsServiceException)) {
117+
return null;
95118
}
119+
AwsErrorDetails awsErrorDetails = ((AwsServiceException) cause).awsErrorDetails();
120+
return awsErrorDetails.errorCode();
96121
}
97122

98123
private UnmarshallingTestContext createErrorContext(String operationName, String errorName) {

test/protocol-tests-core/src/main/resources/software/amazon/awssdk/protocol/suites/cases/json-querycompatible-output.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"then": {
4444
"deserializedAs": {
4545
"message": "Hi"
46-
}
46+
},
47+
"errorCode": "Customized"
4748
}
4849
}
4950
]

test/protocol-tests-core/src/main/resources/software/amazon/awssdk/protocol/suites/cases/smithy-rpcv2-querycompatible-output.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"then": {
4646
"deserializedAs": {
4747
"message": "Hi"
48-
}
48+
},
49+
"errorCode": "Customized"
4950
}
5051
}
5152
]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"aws.auth#sigv4"
77
],
88
"awsQueryCompatible": {},
9-
"endpointPrefix": "query-compatible-jsonrpc10",
9+
"endpointPrefix": "querycompatiblejsonrpc10",
1010
"jsonVersion": "1.0",
1111
"protocol": "json",
1212
"protocols": [
1313
"json"
1414
],
15-
"serviceFullName": "Query Compatible Json 1.0 Protocol Service",
15+
"serviceFullName": "QueryCompatibleJsonRpc10",
1616
"serviceId": "Query Compatible JSON RPC 10",
1717
"signatureVersion": "v4",
18-
"signingName": "query-compatible-jsonrpc10",
18+
"signingName": "QueryCompatibleJsonRpc10",
1919
"targetPrefix": "QueryCompatibleJsonRpc10",
2020
"uid": "query-compatible-json-rpc-10-2020-07-14"
2121
},

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@
2929
},
3030
"shapes": {}
3131
}
32-

test/protocol-tests/src/test/java/software/amazon/awssdk/protocol/tests/JsonQueryCompatibleProtocolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static List<TestCase> data() throws IOException {
4141

4242
@BeforeClass
4343
public static void setupFixture() {
44-
testRunner = new ProtocolTestRunner("/models/query-compatible-jsonrpc10-2020-07-14-intermediate.json");
44+
testRunner = new ProtocolTestRunner("/models/querycompatiblejsonrpc10-2020-07-14-intermediate.json");
4545
}
4646

4747
@Test

0 commit comments

Comments
 (0)