From 6a97f9b2be144bf0d929b4f1e2c58de9771e117b Mon Sep 17 00:00:00 2001 From: Alex Garikana Date: Thu, 13 Jun 2024 10:17:34 -0700 Subject: [PATCH 1/2] refactor test to remove dependency on kendra sdk --- pom.xml | 5 - .../proxy/aws/AWSServiceSerdeTest.java | 93 ++++++++++++++----- 2 files changed, 69 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index 7b20ea8b..d55cc75d 100644 --- a/pom.xml +++ b/pom.xml @@ -190,11 +190,6 @@ s3 test - - software.amazon.awssdk - kendra - test - diff --git a/src/test/java/software/amazon/cloudformation/proxy/aws/AWSServiceSerdeTest.java b/src/test/java/software/amazon/cloudformation/proxy/aws/AWSServiceSerdeTest.java index c9bee392..01136fc5 100644 --- a/src/test/java/software/amazon/cloudformation/proxy/aws/AWSServiceSerdeTest.java +++ b/src/test/java/software/amazon/cloudformation/proxy/aws/AWSServiceSerdeTest.java @@ -48,9 +48,6 @@ import software.amazon.awssdk.services.cloudwatchevents.model.PutTargetsResultEntry; import software.amazon.awssdk.services.cloudwatchevents.model.Tag; import software.amazon.awssdk.services.cloudwatchevents.model.Target; -import software.amazon.awssdk.services.kendra.model.DataSourceConfiguration; -import software.amazon.awssdk.services.kendra.model.TemplateConfiguration; -import software.amazon.awssdk.services.kendra.model.UpdateDataSourceRequest; import software.amazon.awssdk.utils.builder.SdkBuilder; import software.amazon.cloudformation.resource.Serializer; @@ -437,30 +434,78 @@ public void typeMismatchError() { assertThat(exception.getMessage()).contains("Type mismatch, expecting " + MarshallingType.MAP + " got List type"); } + @lombok.EqualsAndHashCode + @lombok.ToString + @lombok.Getter + private static class PojoContainingDocument implements SdkPojo { + + private final Document document; + + private static final SdkField DOCUMENT_VALUE_FIELD = SdkField.builder(MarshallingType.DOCUMENT) + .getter(documentGetter(PojoContainingDocument::getDocument)) + .setter(documentSetter(PojoContainingDocument.Builder::documentValue)) + .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("DocumentValue").build()).build(); + private static final List> SDK_FIELDS = Collections.singletonList(DOCUMENT_VALUE_FIELD); + + @Override + public List> sdkFields() { + return SDK_FIELDS; + } + + public static PojoContainingDocument.Builder builder() { + return new PojoContainingDocument.Builder(); + } + + private PojoContainingDocument(Builder builder) { + this.document = builder.documentValue; + } + + public static class Builder implements SdkBuilder, SdkPojo { + + private Document documentValue; + + public PojoContainingDocument.Builder documentValue(Document documentValue) { + this.documentValue = documentValue; + return this; + } + + Builder() { + } + + @Override + public PojoContainingDocument build() { + return new PojoContainingDocument(this); + } + + @Override + public List> sdkFields() { + return SDK_FIELDS; + } + } + + // static wrappers of getDocument & putDocument + private static Function documentGetter(Function g) { + return obj -> g.apply((PojoContainingDocument) obj); + } + + private static BiConsumer documentSetter(BiConsumer s) { + return (obj, val) -> s.accept((PojoContainingDocument.Builder) obj, val); + } + } + @Test - public void documentFieldSerde() throws Exception { - Document template = Document.mapBuilder().putString("type", "S3") - .putDocument("connectionConfiguration", + public void testDocumentFieldSerde() throws Exception { + Document template = Document.mapBuilder().putString("type", "Foo") + .putDocument("fooConfigurationDocument1", Document.mapBuilder() - .putDocument("repositoryEndpointMetadata", Document.mapBuilder().putString("BucketName", "mybucket").build()) + .putDocument("fooConfigurationDocumentNestedData", Document.mapBuilder().putString("name", "value").build()) .build()) - .putDocument("repositoryConfigurations", - Document.mapBuilder() - .putDocument("document", - Document.mapBuilder().putDocument("fieldMappings", Document.listBuilder() - .addDocument(Document.mapBuilder().putString("indexFieldName", "foo") - .putString("indexFieldType", "STRING").putString("dataSourceFieldName", "foo").build()) - .build()).build()) - .build()) - .putBoolean("booleanValue", false).putNumber("numberValue", 1).putNull("nullValue").build(); - UpdateDataSourceRequest request = UpdateDataSourceRequest.builder() - .configuration(DataSourceConfiguration.builder() - .templateConfiguration(TemplateConfiguration.builder().template(template).build()).build()) - .id("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").indexId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").build(); - - String json = serializer.serialize(request); - UpdateDataSourceRequest deserialized = serializer.deserialize(json, new TypeReference() { + .putDocument("fooConfigurationDocument2", Document.mapBuilder().putNumber("numberField1", 0.1).build()) + .putBoolean("booleanField1", false).putNumber("numberField2", 10).build(); + PojoContainingDocument pojoContainingDocument = PojoContainingDocument.builder().documentValue(template).build(); + String json = serializer.serialize(pojoContainingDocument); + PojoContainingDocument deserialized = serializer.deserialize(json, new TypeReference() { }); - assertThat(deserialized).isEqualTo(request); + assertThat(deserialized).isEqualTo(pojoContainingDocument); } } From 01e39596a20a72e497491e3058da3808b246ae36 Mon Sep 17 00:00:00 2001 From: Alex Garikana Date: Thu, 13 Jun 2024 10:18:28 -0700 Subject: [PATCH 2/2] refactor failing tests --- .../java/software/amazon/cloudformation/HookWrapperTest.java | 1 - src/test/java/software/amazon/cloudformation/WrapperTest.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/test/java/software/amazon/cloudformation/HookWrapperTest.java b/src/test/java/software/amazon/cloudformation/HookWrapperTest.java index e42bd399..18a4aa0a 100644 --- a/src/test/java/software/amazon/cloudformation/HookWrapperTest.java +++ b/src/test/java/software/amazon/cloudformation/HookWrapperTest.java @@ -307,7 +307,6 @@ public void invokeHandler_CompleteSynchronously_returnsSuccess(final String requ @Test public void invokeHandler_DependenciesInitialised_CompleteSynchronously_returnsSuccess() throws IOException { lenient().when(cipher.decryptCredentials(any())).thenReturn(new Credentials("123", "123", "123")); - final HookWrapperOverride wrapper = new HookWrapperOverride(platformEventsLogger, cipher); // if the handler responds Complete, this is treated as a successful synchronous // completion diff --git a/src/test/java/software/amazon/cloudformation/WrapperTest.java b/src/test/java/software/amazon/cloudformation/WrapperTest.java index 94ac089c..58d7b270 100755 --- a/src/test/java/software/amazon/cloudformation/WrapperTest.java +++ b/src/test/java/software/amazon/cloudformation/WrapperTest.java @@ -344,7 +344,6 @@ public void invokeHandler_CompleteSynchronously_returnsSuccess(final String requ @Test public void invokeHandler_DependenciesInitialised_CompleteSynchronously_returnsSuccess() throws IOException { - final WrapperOverride wrapper = new WrapperOverride(platformEventsLogger); final TestModel model = new TestModel(); // if the handler responds Complete, this is treated as a successful synchronous