Skip to content

Commit e520f06

Browse files
committed
Ignore unknown properties in endpoint tests
1 parent 9ec6d43 commit e520f06

File tree

5 files changed

+296
-4
lines changed

5 files changed

+296
-4
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/rules/TestGeneratorUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.List;
3131
import java.util.Map;
3232
import java.util.Optional;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
3335
import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute;
3436
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4AuthScheme;
3537
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme;
@@ -45,6 +47,8 @@
4547
import software.amazon.awssdk.utils.StringUtils;
4648

4749
public final class TestGeneratorUtils {
50+
private static final Logger log = LoggerFactory.getLogger(TestGeneratorUtils.class);
51+
4852
private TestGeneratorUtils() {
4953
}
5054

@@ -114,10 +118,9 @@ private static void addEndpointAttributeBlock(CodeBlock.Builder builder, String
114118
} else if (knownEndpointAttributes.containsKey(attrName)) {
115119
addAttributeBlock(builder, attrValue, knownEndpointAttributes.get(attrName));
116120
} else {
117-
throw new RuntimeException(
118-
String.format("Encountered unknown expected endpoint attribute: %s. Known attributes: %s.",
121+
log.warn("Ignoring unknown expected endpoint attribute: {}. Known attributes: {}.",
119122
attrName,
120-
knownEndpointAttributes));
123+
knownEndpointAttributes);
121124
}
122125
}
123126

codegen/src/test/java/software/amazon/awssdk/codegen/poet/ClientTestModels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public static IntermediateModel queryServiceModelsWithUnknownEndpointProperties(
192192
File endpointRuleSetModel =
193193
new File(ClientTestModels.class.getResource("client/c2j/query/endpoint-rule-set-unknown-properties.json").getFile());
194194
File endpointTestsModel =
195-
new File(ClientTestModels.class.getResource("client/c2j/query/endpoint-tests.json").getFile());
195+
new File(ClientTestModels.class.getResource("client/c2j/query/endpoint-tests-unknown-properties.json").getFile());
196196

197197
C2jModels models = C2jModels
198198
.builder()

codegen/src/test/java/software/amazon/awssdk/codegen/poet/rules/EndpointRulesClientTestSpecTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ public void endpointProviderTestClassWithStringArray() {
3434
ClassSpec endpointProviderSpec = new EndpointProviderTestSpec(ClientTestModels.stringArrayServiceModels());
3535
assertThat(endpointProviderSpec, generatesTo("endpoint-rules-stringarray-test-class.java"));
3636
}
37+
38+
@Test
39+
public void endpointProviderTestClassWithUnknownProperties() {
40+
ClassSpec endpointProviderSpec = new EndpointProviderTestSpec(ClientTestModels.queryServiceModelsWithUnknownEndpointProperties());
41+
assertThat(endpointProviderSpec, generatesTo("endpoint-rules-unknownproperty-test-class.java"));
42+
}
3743
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
{
2+
"testCases": [
3+
{
4+
"documentation": "test case 1",
5+
"params": {
6+
"region": "us-east-1"
7+
},
8+
"expect": {
9+
"endpoint": {
10+
"url": "https://myservice.aws",
11+
"properties": {
12+
"unknownProperty": "value"
13+
}
14+
}
15+
}
16+
},
17+
{
18+
"documentation": "test case 2",
19+
"params": {
20+
"region": "us-east-1",
21+
"booleanContextParam": true,
22+
"stringContextParam": "this is a test"
23+
},
24+
"expect": {
25+
"endpoint": {
26+
"url": "https://myservice.aws"
27+
}
28+
}
29+
},
30+
{
31+
"documentation": "test case 3",
32+
"params": {
33+
"region": "us-east-1"
34+
},
35+
"operationInputs": [
36+
{
37+
"operationName": "OperationWithContextParam",
38+
"operationParams": {
39+
"StringMember": "this is a test"
40+
}
41+
}
42+
],
43+
"expect": {
44+
"endpoint": {
45+
"url": "https://myservice.aws"
46+
}
47+
}
48+
},
49+
{
50+
"documentation": "test case 4",
51+
"params": {
52+
"region": "us-east-6"
53+
},
54+
"operationInputs": [
55+
{
56+
"operationName": "OperationWithContextParam",
57+
"operationParams": {
58+
"StringMember": "this is a test"
59+
}
60+
}
61+
],
62+
"expect": {
63+
"endpoint": {
64+
"url": "https://myservice.aws"
65+
}
66+
}
67+
},
68+
{
69+
"documentation": "test case 5",
70+
"operationInputs": [
71+
{
72+
"operationName": "OperationWithContextParam",
73+
"operationParams": {
74+
"StringMember": "this is a test with AccountId and AccountIdEndpointMode"
75+
},
76+
"builtInParams": {
77+
"AWS::Region": "us-east-5",
78+
"AWS::Auth::AccountId": "012345678901",
79+
"AWS::Auth::AccountIdEndpointMode": "required"
80+
}
81+
}
82+
],
83+
"params": {
84+
"Region": "us-east-5",
85+
"AccountId": "012345678901",
86+
"AccountIdEndpointMode": "required"
87+
},
88+
"expect": {
89+
"endpoint": {
90+
"url": "https://012345678901.myservice.aws"
91+
}
92+
}
93+
},
94+
{
95+
"documentation": "test case 6",
96+
"operationInputs": [
97+
{
98+
"operationName": "OperationWithMapOperationContextParam",
99+
"operationParams": {
100+
"OperationWithMapOperationContextParam": {
101+
"key": {
102+
"S" : "value"
103+
}
104+
}
105+
},
106+
"builtInParams": {
107+
"AWS::Region": "us-east-5",
108+
"AWS::Auth::AccountId": "012345678901",
109+
"AWS::Auth::AccountIdEndpointMode": "required"
110+
}
111+
}
112+
],
113+
"params": {
114+
"Region": "us-east-5",
115+
"AccountId": "012345678901",
116+
"AccountIdEndpointMode": "required",
117+
"ArnList": [
118+
"arn:aws:dynamodb:us-east-6:012345678901:table/table_name"
119+
]
120+
},
121+
"expect": {
122+
"endpoint": {
123+
"url": "https://012345678901.myservice.aws"
124+
}
125+
}
126+
},
127+
{
128+
"documentation": "test case 7",
129+
"operationInputs": [
130+
{
131+
"operationName": "OperationWithMapOperationContextParam",
132+
"operationParams": {
133+
"OperationWithMapOperationContextParam": {
134+
"key": {
135+
"S" : "value"
136+
},
137+
"key2": {
138+
"S" : "value2"
139+
}
140+
}
141+
},
142+
"builtInParams": {
143+
"AWS::Region": "us-east-5",
144+
"AWS::Auth::AccountId": "012345678901",
145+
"AWS::Auth::AccountIdEndpointMode": "required"
146+
}
147+
}
148+
],
149+
"params": {
150+
"Region": "us-east-5",
151+
"AccountId": "012345678901",
152+
"AccountIdEndpointMode": "required",
153+
"ArnList": [
154+
"arn:aws:dynamodb:us-east-6:012345678901:table/table_name"
155+
]
156+
},
157+
"expect": {
158+
"endpoint": {
159+
"url": "https://012345678901.myservice.aws"
160+
}
161+
}
162+
},
163+
{
164+
"documentation": "For region us-iso-west-1 with FIPS enabled and DualStack enabled",
165+
"expect": {
166+
"error": "Should have been skipped!"
167+
},
168+
"params": {
169+
}
170+
},
171+
{
172+
"documentation": "Has complex operation input",
173+
"expect": {
174+
"error": "Missing info"
175+
},
176+
"params": {
177+
},
178+
"operationInputs": [
179+
{
180+
"operationName": "OperationWithContextParam",
181+
"operationParams": {
182+
"NestedMember": {
183+
"ChecksumMode": "foo"
184+
}
185+
}
186+
}
187+
]
188+
},
189+
{
190+
"documentation": "Has has undeclared input parameter",
191+
"expect": {
192+
"error": "Missing info"
193+
},
194+
"params": {
195+
"NotAParam": "ABC"
196+
}
197+
}
198+
],
199+
"version": "1.0"
200+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.services.query.endpoints;
17+
18+
import java.net.URI;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import org.junit.jupiter.params.ParameterizedTest;
22+
import org.junit.jupiter.params.provider.MethodSource;
23+
import software.amazon.awssdk.annotations.Generated;
24+
import software.amazon.awssdk.core.rules.testing.BaseEndpointProviderTest;
25+
import software.amazon.awssdk.core.rules.testing.EndpointProviderTestCase;
26+
import software.amazon.awssdk.core.rules.testing.model.Expect;
27+
import software.amazon.awssdk.endpoints.Endpoint;
28+
29+
@Generated("software.amazon.awssdk:codegen")
30+
public class QueryEndpointProviderTests extends BaseEndpointProviderTest {
31+
private static final QueryEndpointProvider PROVIDER = QueryEndpointProvider.defaultProvider();
32+
33+
@MethodSource("testCases")
34+
@ParameterizedTest
35+
public void resolvesCorrectEndpoint(EndpointProviderTestCase tc) {
36+
verify(tc);
37+
}
38+
39+
private static List<EndpointProviderTestCase> testCases() {
40+
List<EndpointProviderTestCase> testCases = new ArrayList<>();
41+
testCases.add(new EndpointProviderTestCase(() -> {
42+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
43+
return PROVIDER.resolveEndpoint(builder.build()).join();
44+
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://myservice.aws")).build()).build()));
45+
testCases.add(new EndpointProviderTestCase(() -> {
46+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
47+
return PROVIDER.resolveEndpoint(builder.build()).join();
48+
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://myservice.aws")).build()).build()));
49+
testCases.add(new EndpointProviderTestCase(() -> {
50+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
51+
return PROVIDER.resolveEndpoint(builder.build()).join();
52+
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://myservice.aws")).build()).build()));
53+
testCases.add(new EndpointProviderTestCase(() -> {
54+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
55+
return PROVIDER.resolveEndpoint(builder.build()).join();
56+
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://myservice.aws")).build()).build()));
57+
testCases.add(new EndpointProviderTestCase(() -> {
58+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
59+
return PROVIDER.resolveEndpoint(builder.build()).join();
60+
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://012345678901.myservice.aws")).build()).build()));
61+
testCases.add(new EndpointProviderTestCase(() -> {
62+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
63+
return PROVIDER.resolveEndpoint(builder.build()).join();
64+
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://012345678901.myservice.aws")).build()).build()));
65+
testCases.add(new EndpointProviderTestCase(() -> {
66+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
67+
return PROVIDER.resolveEndpoint(builder.build()).join();
68+
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://012345678901.myservice.aws")).build()).build()));
69+
testCases.add(new EndpointProviderTestCase(() -> {
70+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
71+
return PROVIDER.resolveEndpoint(builder.build()).join();
72+
}, Expect.builder().error("Should have been skipped!").build()));
73+
testCases.add(new EndpointProviderTestCase(() -> {
74+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
75+
return PROVIDER.resolveEndpoint(builder.build()).join();
76+
}, Expect.builder().error("Missing info").build()));
77+
testCases.add(new EndpointProviderTestCase(() -> {
78+
QueryEndpointParams.Builder builder = QueryEndpointParams.builder();
79+
return PROVIDER.resolveEndpoint(builder.build()).join();
80+
}, Expect.builder().error("Missing info").build()));
81+
return testCases;
82+
}
83+
}

0 commit comments

Comments
 (0)