Skip to content

Commit 5ee139f

Browse files
committed
WIP - adding more new test features
1 parent cd347c6 commit 5ee139f

File tree

16 files changed

+1761
-38
lines changed

16 files changed

+1761
-38
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/XmlNamespace.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717

1818
public class XmlNamespace {
1919

20-
public XmlNamespace() {}
20+
private String prefix;
21+
private String uri;
22+
23+
public XmlNamespace() {
24+
25+
}
2126

2227
public XmlNamespace(String uri) {
2328
this.uri = uri;
2429
}
2530

26-
private String prefix;
27-
28-
private String uri;
29-
3031
public String getPrefix() {
3132
return prefix;
3233
}

codegen/src/main/java/software/amazon/awssdk/codegen/naming/DefaultNamingStrategy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ public String getEnumValueName(String enumValue) {
302302
// Special cases
303303
result = result.replace("textORcsv", "TEXT_OR_CSV");
304304

305+
// leading digits, add a prefix
306+
if (result.matches("^\\d.*")) {
307+
result = "VALUE_" + result;
308+
}
309+
305310
// Split into words
306311
result = String.join("_", splitOnWordBoundaries(result));
307312

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/asserts/marshalling/CompositeMarshallingAssertion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
1919
import java.util.ArrayList;
2020
import java.util.List;
21+
import software.amazon.awssdk.http.SdkHttpRequest;
2122

2223
/**
2324
* Composite for MarshallingAssertion objects.

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/asserts/marshalling/HeadersAssertion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void assertDoesNotContainHeaders(HttpHeaders actual) {
8080
}
8181

8282
private void assertMustContainHeaders(HttpHeaders actual) {
83-
doesNotContain.forEach(headerName -> {
83+
mustContain.forEach(headerName -> {
8484
assertTrue(String.format("Header '%s' was expected to be present", headerName),
8585
actual.getHeader(headerName).isPresent());
8686
});

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/asserts/marshalling/MarshallingAssertion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.protocol.asserts.marshalling;
1717

1818
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
19+
import software.amazon.awssdk.http.SdkHttpRequest;
1920

2021
/**
2122
* Assertion on the marshalled request.

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/asserts/marshalling/QueryBodyAssertion.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
2525
import java.util.List;
2626
import java.util.Map;
27+
import java.util.stream.Collectors;
2728

2829
public class QueryBodyAssertion extends MarshallingAssertion {
2930
private final String queryEquals;
@@ -49,8 +50,28 @@ protected void doAssert(LoggedRequest actual) throws Exception {
4950

5051
private void doAssert(Map<String, List<String>> expectedParams, Map<String, List<String>> actualParams) {
5152
assertThat(actualParams.keySet(), equalTo(expectedParams.keySet()));
52-
expectedParams.forEach((key, value) -> assertThat(
53-
actualParams.get(key), containsInAnyOrder(value.toArray())
54-
));
53+
expectedParams.forEach((key, value) -> assertParamsEqual(actualParams.get(key), value));
5554
}
55+
56+
private void assertParamsEqual(List<String> actual, List<String> expected) {
57+
if (expected.stream().allMatch(QueryBodyAssertion::isNumeric)) {
58+
assertThat(
59+
actual.stream().map(Double::parseDouble).collect(Collectors.toList()),
60+
containsInAnyOrder(expected.stream().map(Double::parseDouble).toArray()));
61+
} else {
62+
assertThat(actual, containsInAnyOrder(expected.toArray()));
63+
}
64+
}
65+
66+
public static boolean isNumeric(String str) {
67+
if (str == null || str.isEmpty()) return false;
68+
try {
69+
Double.parseDouble(str);
70+
return true;
71+
} catch (NumberFormatException e) {
72+
return false;
73+
}
74+
}
75+
76+
5677
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.asserts.marshalling;
17+
18+
import static org.junit.Assert.assertEquals;
19+
20+
import com.github.tomakehurst.wiremock.verification.LoggedRequest;
21+
22+
/**
23+
* Asserts the resolved host of a marshalled request.
24+
*/
25+
public class ResolvedHostAssertion extends MarshallingAssertion {
26+
private final String expectedHost;
27+
28+
public ResolvedHostAssertion(String host) {
29+
this.expectedHost = host;
30+
}
31+
32+
@Override
33+
protected void doAssert(LoggedRequest actual) throws Exception {
34+
// TODO:
35+
// assertEquals(removeTrailingSlash(expectedUri), removeTrailingSlash(getActualPath(actual)));
36+
}
37+
38+
}

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/asserts/marshalling/SerializedAs.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public void setUri(String uri) {
3737
addAssertion(new UriAssertion(uri));
3838
}
3939

40+
public void setResolvedHost(String resolvedHost) {
41+
addAssertion(new ResolvedHostAssertion(resolvedHost));
42+
}
43+
4044
@JsonDeserialize(using = SdkHttpMethodDeserializer.class)
4145
public void setMethod(SdkHttpMethod method) {
4246
addAssertion(new HttpMethodAssertion(method));

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class Given {
2424

2525
private GivenResponse response;
2626

27+
private String host;
28+
2729
public JsonNode getInput() {
2830
return input;
2931
}
@@ -39,4 +41,12 @@ public GivenResponse getResponse() {
3941
public void setResponse(GivenResponse response) {
4042
this.response = response;
4143
}
44+
45+
public String getHost() {
46+
return host;
47+
}
48+
49+
public void setHost(String host) {
50+
this.host = host;
51+
}
4252
}

test/protocol-tests-core/src/main/java/software/amazon/awssdk/protocol/reflect/ShapeModelReflector.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,15 @@ private Object getSimpleMemberValue(JsonNode currentNode, MemberModel memberMode
250250
case "Double":
251251
return currentNode.asDouble();
252252
case "Instant":
253-
return Instant.ofEpochMilli(currentNode.asLong());
253+
if (currentNode.isFloatingPointNumber()) {
254+
double fractionalEpoch = currentNode.asDouble();
255+
long seconds = (long) fractionalEpoch;
256+
long nanos = (long) ((fractionalEpoch - seconds) * 1_000_000_000L);
257+
//truncate to ms
258+
return Instant.ofEpochSecond(seconds, (nanos / 1_000_000) * 1_000_000);
259+
} else {
260+
return Instant.ofEpochSecond(currentNode.asLong());
261+
}
254262
case "SdkBytes":
255263
return SdkBytes.fromUtf8String(currentNode.asText());
256264
case "Float":

0 commit comments

Comments
 (0)