Skip to content

Commit 0801f38

Browse files
authored
Add Endpoints 2.0 suppport for EventBridge (#2200)
- Add support in code generator for genaring client endpoint tests whose requests require instantiating model classes. - Skip some tests that don't work for end-to-end client tests because of missing operationInputs - Remove unneeded MultiRegionEndpointInterceptor
1 parent 48b6f21 commit 0801f38

File tree

10 files changed

+125
-293
lines changed

10 files changed

+125
-293
lines changed

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package software.amazon.awssdk.codegen.poet.rules;
1717

1818
import com.fasterxml.jackson.core.TreeNode;
19+
import com.fasterxml.jackson.jr.stree.JrsArray;
20+
import com.fasterxml.jackson.jr.stree.JrsObject;
21+
import com.fasterxml.jackson.jr.stree.JrsValue;
1922
import com.squareup.javapoet.AnnotationSpec;
2023
import com.squareup.javapoet.ClassName;
2124
import com.squareup.javapoet.CodeBlock;
@@ -387,7 +390,8 @@ private CodeBlock requestCreation(OperationModel opModel, Map<String, TreeNode>
387390
if (opParams != null) {
388391
opParams.forEach((n, v) -> {
389392
MemberModel memberModel = opModel.getInputShape().getMemberByName(n);
390-
b.add(".$N($L)", memberModel.getFluentSetterMethodName(), endpointRulesSpecUtils.treeNodeToLiteral(v));
393+
CodeBlock memberValue = createMemberValue(memberModel, v);
394+
b.add(".$N($L)", memberModel.getFluentSetterMethodName(), memberValue);
391395
});
392396
}
393397

@@ -660,4 +664,58 @@ private MethodSpec teardownMethod() {
660664
}
661665
return b.build();
662666
}
667+
668+
private CodeBlock createMemberValue(MemberModel memberModel, TreeNode valueNode) {
669+
if (memberModel.isSimple()) {
670+
return endpointRulesSpecUtils.treeNodeToLiteral(valueNode);
671+
}
672+
673+
CodeBlock.Builder b = CodeBlock.builder();
674+
675+
if (memberModel.isList()) {
676+
Iterator<JrsValue> elementValuesIter = ((JrsArray) valueNode).elements();
677+
678+
MemberModel listMemberModel = memberModel.getListModel().getListMemberModel();
679+
680+
b.add("$T.asList(", Arrays.class);
681+
while (elementValuesIter.hasNext()) {
682+
JrsValue v = elementValuesIter.next();
683+
b.add(createMemberValue(listMemberModel, v));
684+
if (elementValuesIter.hasNext()) {
685+
b.add(",");
686+
}
687+
}
688+
b.add(")");
689+
return b.build();
690+
}
691+
692+
if (memberModel.isMap()) {
693+
// Not necessary at the moment
694+
throw new RuntimeException("Don't know how to create map member.");
695+
}
696+
697+
return createModelClass(model.getShapes().get(memberModel.getC2jShape()), valueNode);
698+
}
699+
700+
private CodeBlock createModelClass(ShapeModel shapeModel, TreeNode valueNode) {
701+
ClassName modelClassName = poetExtension.getModelClass(shapeModel.getC2jName());
702+
703+
CodeBlock.Builder b = CodeBlock.builder();
704+
b.add("$T.builder()", modelClassName);
705+
706+
JrsObject obj = (JrsObject) valueNode;
707+
708+
Iterator<String> fieldNamesIter = obj.fieldNames();
709+
while (fieldNamesIter.hasNext()) {
710+
String fieldName = fieldNamesIter.next();
711+
MemberModel member = shapeModel.getMemberByName(fieldName);
712+
JrsValue value = obj.get(fieldName);
713+
714+
b.add(".$N($L)", member.getFluentSetterMethodName(), createMemberValue(member, value));
715+
}
716+
717+
b.add(".build()");
718+
719+
return b.build();
720+
}
663721
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/query/endpoint-tests.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@
6969
},
7070
"params": {
7171
}
72+
},
73+
{
74+
"documentation": "Has complex operation input",
75+
"expect": {
76+
"error": "Missing info"
77+
},
78+
"params": {
79+
},
80+
"operationInputs": [
81+
{
82+
"operationName": "OperationWithContextParam",
83+
"operationParams": {
84+
"NestedMember": {
85+
"ChecksumMode": "foo"
86+
}
87+
}
88+
}
89+
]
7290
}
7391
],
7492
"version": "1.0"

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/query/service-2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
"contextParam": {
157157
"name": "operationContextParam"
158158
}
159+
},
160+
"NestedMember": {
161+
"shape": "ChecksumStructure"
159162
}
160163
}
161164
},

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/rules/endpoint-rules-test-class.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import software.amazon.awssdk.services.query.QueryClient;
2020
import software.amazon.awssdk.services.query.QueryClientBuilder;
2121
import software.amazon.awssdk.services.query.model.APostOperationRequest;
22+
import software.amazon.awssdk.services.query.model.ChecksumStructure;
2223
import software.amazon.awssdk.services.query.model.OperationWithContextParamRequest;
2324

2425
@Generated("software.amazon.awssdk:codegen")
@@ -82,14 +83,22 @@ private static List<SyncTestCase> syncTestCases() {
8283
.stringMember("this is a test").build();
8384
builder.build().operationWithContextParam(request);
8485
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://myservice.aws")).build()).build(),
85-
"Does not work"), new SyncTestCase("For region us-iso-west-1 with FIPS enabled and DualStack enabled",
86-
() -> {
87-
QueryClientBuilder builder = QueryClient.builder();
88-
builder.credentialsProvider(BaseRuleSetClientTest.CREDENTIALS_PROVIDER);
89-
builder.httpClient(getSyncHttpClient());
90-
APostOperationRequest request = APostOperationRequest.builder().build();
91-
builder.build().aPostOperation(request);
92-
}, Expect.builder().error("Should have been skipped!").build(), "Client builder does the validation"));
86+
"Does not work"),
87+
new SyncTestCase("For region us-iso-west-1 with FIPS enabled and DualStack enabled", () -> {
88+
QueryClientBuilder builder = QueryClient.builder();
89+
builder.credentialsProvider(BaseRuleSetClientTest.CREDENTIALS_PROVIDER);
90+
builder.httpClient(getSyncHttpClient());
91+
APostOperationRequest request = APostOperationRequest.builder().build();
92+
builder.build().aPostOperation(request);
93+
}, Expect.builder().error("Should have been skipped!").build(), "Client builder does the validation"),
94+
new SyncTestCase("Has complex operation input", () -> {
95+
QueryClientBuilder builder = QueryClient.builder();
96+
builder.credentialsProvider(BaseRuleSetClientTest.CREDENTIALS_PROVIDER);
97+
builder.httpClient(getSyncHttpClient());
98+
OperationWithContextParamRequest request = OperationWithContextParamRequest.builder()
99+
.nestedMember(ChecksumStructure.builder().checksumMode("foo").build()).build();
100+
builder.build().operationWithContextParam(request);
101+
}, Expect.builder().error("Missing info").build()));
93102
}
94103

95104
private static List<AsyncTestCase> asyncTestCases() {
@@ -130,13 +139,21 @@ private static List<AsyncTestCase> asyncTestCases() {
130139
.stringMember("this is a test").build();
131140
return builder.build().operationWithContextParam(request);
132141
}, Expect.builder().endpoint(Endpoint.builder().url(URI.create("https://myservice.aws")).build()).build(),
133-
"Does not work"), new AsyncTestCase("For region us-iso-west-1 with FIPS enabled and DualStack enabled",
134-
() -> {
135-
QueryAsyncClientBuilder builder = QueryAsyncClient.builder();
136-
builder.credentialsProvider(BaseRuleSetClientTest.CREDENTIALS_PROVIDER);
137-
builder.httpClient(getAsyncHttpClient());
138-
APostOperationRequest request = APostOperationRequest.builder().build();
139-
return builder.build().aPostOperation(request);
140-
}, Expect.builder().error("Should have been skipped!").build(), "Client builder does the validation"));
142+
"Does not work"),
143+
new AsyncTestCase("For region us-iso-west-1 with FIPS enabled and DualStack enabled", () -> {
144+
QueryAsyncClientBuilder builder = QueryAsyncClient.builder();
145+
builder.credentialsProvider(BaseRuleSetClientTest.CREDENTIALS_PROVIDER);
146+
builder.httpClient(getAsyncHttpClient());
147+
APostOperationRequest request = APostOperationRequest.builder().build();
148+
return builder.build().aPostOperation(request);
149+
}, Expect.builder().error("Should have been skipped!").build(), "Client builder does the validation"),
150+
new AsyncTestCase("Has complex operation input", () -> {
151+
QueryAsyncClientBuilder builder = QueryAsyncClient.builder();
152+
builder.credentialsProvider(BaseRuleSetClientTest.CREDENTIALS_PROVIDER);
153+
builder.httpClient(getAsyncHttpClient());
154+
OperationWithContextParamRequest request = OperationWithContextParamRequest.builder()
155+
.nestedMember(ChecksumStructure.builder().checksumMode("foo").build()).build();
156+
return builder.build().operationWithContextParam(request);
157+
}, Expect.builder().error("Missing info").build()));
141158
}
142159
}

services/eventbridge/src/main/java/software/amazon/awssdk/services/eventbridge/internal/MultiRegionEndpointInterceptor.java

Lines changed: 0 additions & 136 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"skipEndpointTests": {
3+
"Valid EndpointId with dualstack disabled and fips enabled": "Need operationInputs for EndpointId param",
4+
"Valid EndpointId with dualstack enabled and fips enabled": "Need operationInputs for EndpointId param",
5+
"Invalid EndpointId": "Need operationInputs for EndpointId param",
6+
"Invalid EndpointId (empty)": "Need operationInputs for EndpointId param",
7+
"Valid endpointId with fips disabled and dualstack true": "Need operationInputs for EndpointId param",
8+
"Valid endpointId with custom sdk endpoint": "Need operationInputs for EndpointId param"
9+
}
10+
}

services/eventbridge/src/main/resources/codegen-resources/service-2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3628,7 +3628,8 @@
36283628
},
36293629
"EndpointId":{
36303630
"shape":"EndpointId",
3631-
"documentation":"<p>The URL subdomain of the endpoint. For example, if the URL for Endpoint is abcde.veo.endpoints.event.amazonaws.com, then the EndpointId is <code>abcde.veo</code>.</p> <important> <p>When using Java, you must include <code>auth-crt</code> on the class path.</p> </important>"
3631+
"documentation":"<p>The URL subdomain of the endpoint. For example, if the URL for Endpoint is abcde.veo.endpoints.event.amazonaws.com, then the EndpointId is <code>abcde.veo</code>.</p> <important> <p>When using Java, you must include <code>auth-crt</code> on the class path.</p> </important>",
3632+
"contextParam":{"name":"EndpointId"}
36323633
}
36333634
}
36343635
},

services/eventbridge/src/main/resources/software/amazon/awssdk/services/eventbridge/execution.interceptors

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)