From 1df62b3f9ed5a4e767b9d4522989603f802924d5 Mon Sep 17 00:00:00 2001 From: Philipp Page Date: Fri, 31 Oct 2025 11:33:06 +0100 Subject: [PATCH] fix(serialization): Fix Joda time serialization for AWS events. --- powertools-serialization/pom.xml | 4 + .../powertools/utilities/JsonConfig.java | 5 +- .../utilities/EventDeserializerTest.java | 198 ++++++++++++++---- .../jmespath/Base64FunctionTest.java | 19 +- .../jmespath/Base64GZipFunctionTest.java | 30 +-- .../utilities/jmespath/JsonFunctionTest.java | 13 +- 6 files changed, 204 insertions(+), 65 deletions(-) diff --git a/powertools-serialization/pom.xml b/powertools-serialization/pom.xml index 89fb2056a..1ed2ee259 100644 --- a/powertools-serialization/pom.xml +++ b/powertools-serialization/pom.xml @@ -47,6 +47,10 @@ com.fasterxml.jackson.core jackson-databind + + com.fasterxml.jackson.datatype + jackson-datatype-joda + diff --git a/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/JsonConfig.java b/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/JsonConfig.java index c6a986564..ac10412fa 100644 --- a/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/JsonConfig.java +++ b/powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/JsonConfig.java @@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.joda.JodaModule; import io.burt.jmespath.JmesPath; import io.burt.jmespath.RuntimeConfiguration; @@ -41,11 +42,13 @@ public final class JsonConfig { // Don't throw an exception when json has extra fields you are not serializing on. .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) // Ignore null values when writing json. - .serializationInclusion(JsonInclude.Include.NON_NULL) + .defaultPropertyInclusion( + JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.USE_DEFAULTS)) // Write times as a String instead of a Long so its human-readable. .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) // Sort fields in alphabetical order .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) + .addModule(new JodaModule()) .build(); private static final ThreadLocal om = ThreadLocal.withInitial(objectMapperSupplier); diff --git a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java index 2914bd286..14fc32231 100644 --- a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java +++ b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java @@ -18,6 +18,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static software.amazon.lambda.powertools.utilities.EventDeserializer.extractDataFrom; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; + import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; import com.amazonaws.services.lambda.runtime.events.ActiveMQEvent; @@ -34,41 +41,37 @@ import com.amazonaws.services.lambda.runtime.events.SQSEvent; import com.amazonaws.services.lambda.runtime.events.ScheduledEvent; import com.amazonaws.services.lambda.runtime.tests.annotations.Event; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; +import com.fasterxml.jackson.databind.JsonNode; + import software.amazon.lambda.powertools.utilities.model.Order; import software.amazon.lambda.powertools.utilities.model.Product; -public class EventDeserializerTest { +class EventDeserializerTest { @Test - public void testDeserializeStringAsString_shouldReturnString() { + void testDeserializeStringAsString_shouldReturnString() { String stringEvent = "Hello World"; String result = extractDataFrom(stringEvent).as(String.class); assertThat(result).isEqualTo(stringEvent); } @Test - public void testDeserializeStringAsObject_shouldReturnObject() { + void testDeserializeStringAsObject_shouldReturnObject() { String productStr = "{\"id\":1234, \"name\":\"product\", \"price\":42}"; Product product = extractDataFrom(productStr).as(Product.class); assertProduct(product); } @Test - public void testDeserializeStringArrayAsList_shouldReturnList() { - String productStr = - "[{\"id\":1234, \"name\":\"product\", \"price\":42}, {\"id\":2345, \"name\":\"product2\", \"price\":43}]"; + void testDeserializeStringArrayAsList_shouldReturnList() { + String productStr = "[{\"id\":1234, \"name\":\"product\", \"price\":42}, {\"id\":2345, \"name\":\"product2\", \"price\":43}]"; List products = extractDataFrom(productStr).asListOf(Product.class); assertThat(products).hasSize(2); assertProduct(products.get(0)); } @Test - public void testDeserializeStringAsList_shouldThrowException() { + void testDeserializeStringAsList_shouldThrowException() { String productStr = "{\"id\":1234, \"name\":\"product\", \"price\":42}"; assertThatThrownBy(() -> extractDataFrom(productStr).asListOf(Product.class)) .isInstanceOf(EventDeserializationException.class) @@ -76,7 +79,7 @@ public void testDeserializeStringAsList_shouldThrowException() { } @Test - public void testDeserializeMapAsObject_shouldReturnObject() { + void testDeserializeMapAsObject_shouldReturnObject() { Map map = new HashMap<>(); map.put("id", 1234); map.put("name", "product"); @@ -87,21 +90,21 @@ public void testDeserializeMapAsObject_shouldReturnObject() { @ParameterizedTest @Event(value = "apigw_event.json", type = APIGatewayProxyRequestEvent.class) - public void testDeserializeAPIGWEventBodyAsObject_shouldReturnObject(APIGatewayProxyRequestEvent event) { + void testDeserializeAPIGWEventBodyAsObject_shouldReturnObject(APIGatewayProxyRequestEvent event) { Product product = extractDataFrom(event).as(Product.class); assertProduct(product); } @ParameterizedTest @Event(value = "sns_event.json", type = SNSEvent.class) - public void testDeserializeSNSEventMessageAsObject_shouldReturnObject(SNSEvent event) { + void testDeserializeSNSEventMessageAsObject_shouldReturnObject(SNSEvent event) { Product product = extractDataFrom(event).as(Product.class); assertProduct(product); } @ParameterizedTest @Event(value = "sqs_event.json", type = SQSEvent.class) - public void testDeserializeSQSEventMessageAsList_shouldReturnList(SQSEvent event) { + void testDeserializeSQSEventMessageAsList_shouldReturnList(SQSEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(2); assertProduct(products.get(0)); @@ -109,7 +112,7 @@ public void testDeserializeSQSEventMessageAsList_shouldReturnList(SQSEvent event @ParameterizedTest @Event(value = "kinesis_event.json", type = KinesisEvent.class) - public void testDeserializeKinesisEventMessageAsList_shouldReturnList(KinesisEvent event) { + void testDeserializeKinesisEventMessageAsList_shouldReturnList(KinesisEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(2); assertProduct(products.get(0)); @@ -117,7 +120,7 @@ public void testDeserializeKinesisEventMessageAsList_shouldReturnList(KinesisEve @ParameterizedTest @Event(value = "kafka_event.json", type = KafkaEvent.class) - public void testDeserializeKafkaEventMessageAsList_shouldReturnList(KafkaEvent event) { + void testDeserializeKafkaEventMessageAsList_shouldReturnList(KafkaEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(2); assertProduct(products.get(0)); @@ -125,7 +128,7 @@ public void testDeserializeKafkaEventMessageAsList_shouldReturnList(KafkaEvent e @ParameterizedTest @Event(value = "sqs_event.json", type = SQSEvent.class) - public void testDeserializeSQSEventMessageAsObject_shouldThrowException(SQSEvent event) { + void testDeserializeSQSEventMessageAsObject_shouldThrowException(SQSEvent event) { assertThatThrownBy(() -> extractDataFrom(event).as(Product.class)) .isInstanceOf(EventDeserializationException.class) .hasMessageContaining("consider using 'asListOf' instead"); @@ -133,7 +136,7 @@ public void testDeserializeSQSEventMessageAsObject_shouldThrowException(SQSEvent @ParameterizedTest @Event(value = "apigw_event.json", type = APIGatewayProxyRequestEvent.class) - public void testDeserializeAPIGatewayEventAsList_shouldThrowException(APIGatewayProxyRequestEvent event) { + void testDeserializeAPIGatewayEventAsList_shouldThrowException(APIGatewayProxyRequestEvent event) { assertThatThrownBy(() -> extractDataFrom(event).asListOf(Product.class)) .isInstanceOf(EventDeserializationException.class) .hasMessageContaining("consider using 'as' instead") @@ -142,14 +145,14 @@ public void testDeserializeAPIGatewayEventAsList_shouldThrowException(APIGateway @ParameterizedTest @Event(value = "custom_event_map.json", type = HashMap.class) - public void testDeserializeAPIGatewayMapEventAsList_shouldThrowException(Map event) { + void testDeserializeAPIGatewayMapEventAsList_shouldThrowException(Map event) { assertThatThrownBy(() -> extractDataFrom(event).asListOf(Order.class)) .isInstanceOf(EventDeserializationException.class) .hasMessage("The content of this event is not a list, consider using 'as' instead"); } @Test - public void testDeserializeEmptyEventAsList_shouldThrowException() { + void testDeserializeEmptyEventAsList_shouldThrowException() { assertThatThrownBy(() -> extractDataFrom(null).asListOf(Product.class)) .isInstanceOf(IllegalStateException.class) .hasMessage("Event content is null: the event may be malformed (missing fields)"); @@ -157,14 +160,14 @@ public void testDeserializeEmptyEventAsList_shouldThrowException() { @ParameterizedTest @Event(value = "apigw_event_no_body.json", type = APIGatewayProxyRequestEvent.class) - public void testDeserializeAPIGatewayNoBody_shouldThrowException(APIGatewayProxyRequestEvent event) { + void testDeserializeAPIGatewayNoBody_shouldThrowException(APIGatewayProxyRequestEvent event) { assertThatThrownBy(() -> extractDataFrom(event).as(Product.class)) .isInstanceOf(IllegalStateException.class) .hasMessage("Event content is null: the event may be malformed (missing fields)"); } @Test - public void testDeserializeAPIGatewayNoBodyAsList_shouldThrowException() { + void testDeserializeAPIGatewayNoBodyAsList_shouldThrowException() { assertThatThrownBy(() -> extractDataFrom(new Object()).asListOf(Product.class)) .isInstanceOf(EventDeserializationException.class) .hasMessage("The content of this event is not a list, consider using 'as' instead"); @@ -172,19 +175,18 @@ public void testDeserializeAPIGatewayNoBodyAsList_shouldThrowException() { @ParameterizedTest @Event(value = "sqs_event_no_body.json", type = SQSEvent.class) - public void testDeserializeSQSEventNoBody_shouldThrowException(SQSEvent event) { + void testDeserializeSQSEventNoBody_shouldThrowException(SQSEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products.get(0)).isNull(); } @Test - public void testDeserializeProductAsProduct_shouldReturnProduct() { + void testDeserializeProductAsProduct_shouldReturnProduct() { Product myProduct = new Product(1234, "product", 42); Product product = extractDataFrom(myProduct).as(Product.class); assertProduct(product); } - private void assertProduct(Product product) { assertThat(product) .isEqualTo(new Product(1234, "product", 42)) @@ -193,28 +195,28 @@ private void assertProduct(Product product) { @ParameterizedTest @Event(value = "scheduled_event.json", type = ScheduledEvent.class) - public void testDeserializeScheduledEventMessageAsObject_shouldReturnObject(ScheduledEvent event) { + void testDeserializeScheduledEventMessageAsObject_shouldReturnObject(ScheduledEvent event) { Product product = extractDataFrom(event).as(Product.class); assertProduct(product); } @ParameterizedTest @Event(value = "alb_event.json", type = ApplicationLoadBalancerRequestEvent.class) - public void testDeserializeALBEventMessageAsObjectShouldReturnObject(ApplicationLoadBalancerRequestEvent event) { + void testDeserializeALBEventMessageAsObjectShouldReturnObject(ApplicationLoadBalancerRequestEvent event) { Product product = extractDataFrom(event).as(Product.class); assertProduct(product); } @ParameterizedTest @Event(value = "cwl_event.json", type = CloudWatchLogsEvent.class) - public void testDeserializeCWLEventMessageAsObjectShouldReturnObject(CloudWatchLogsEvent event) { + void testDeserializeCWLEventMessageAsObjectShouldReturnObject(CloudWatchLogsEvent event) { Product product = extractDataFrom(event).as(Product.class); assertProduct(product); } @ParameterizedTest @Event(value = "kf_event.json", type = KinesisFirehoseEvent.class) - public void testDeserializeKFEventMessageAsListShouldReturnList(KinesisFirehoseEvent event) { + void testDeserializeKFEventMessageAsListShouldReturnList(KinesisFirehoseEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(1); assertProduct(products.get(0)); @@ -222,7 +224,7 @@ public void testDeserializeKFEventMessageAsListShouldReturnList(KinesisFirehoseE @ParameterizedTest @Event(value = "amq_event.json", type = ActiveMQEvent.class) - public void testDeserializeAMQEventMessageAsListShouldReturnList(ActiveMQEvent event) { + void testDeserializeAMQEventMessageAsListShouldReturnList(ActiveMQEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(1); assertProduct(products.get(0)); @@ -230,7 +232,7 @@ public void testDeserializeAMQEventMessageAsListShouldReturnList(ActiveMQEvent e @ParameterizedTest @Event(value = "rabbitmq_event.json", type = RabbitMQEvent.class) - public void testDeserializeRabbitMQEventMessageAsListShouldReturnList(RabbitMQEvent event) { + void testDeserializeRabbitMQEventMessageAsListShouldReturnList(RabbitMQEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(1); assertProduct(products.get(0)); @@ -238,7 +240,7 @@ public void testDeserializeRabbitMQEventMessageAsListShouldReturnList(RabbitMQEv @ParameterizedTest @Event(value = "kasip_event.json", type = KinesisAnalyticsStreamsInputPreprocessingEvent.class) - public void testDeserializeKasipEventMessageAsListShouldReturnList( + void testDeserializeKasipEventMessageAsListShouldReturnList( KinesisAnalyticsStreamsInputPreprocessingEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(1); @@ -247,7 +249,7 @@ public void testDeserializeKasipEventMessageAsListShouldReturnList( @ParameterizedTest @Event(value = "kafip_event.json", type = KinesisAnalyticsFirehoseInputPreprocessingEvent.class) - public void testDeserializeKafipEventMessageAsListShouldReturnList( + void testDeserializeKafipEventMessageAsListShouldReturnList( KinesisAnalyticsFirehoseInputPreprocessingEvent event) { List products = extractDataFrom(event).asListOf(Product.class); assertThat(products).hasSize(1); @@ -256,16 +258,138 @@ public void testDeserializeKafipEventMessageAsListShouldReturnList( @ParameterizedTest @Event(value = "apigwv2_event.json", type = APIGatewayV2HTTPEvent.class) - public void testDeserializeApiGWV2EventMessageAsObjectShouldReturnObject(APIGatewayV2HTTPEvent event) { + void testDeserializeApiGWV2EventMessageAsObjectShouldReturnObject(APIGatewayV2HTTPEvent event) { Product product = extractDataFrom(event).as(Product.class); assertProduct(product); } @ParameterizedTest @Event(value = "cfcr_event.json", type = CloudFormationCustomResourceEvent.class) - public void testDeserializeCfcrEventMessageAsObjectShouldReturnObject(CloudFormationCustomResourceEvent event) { + void testDeserializeCfcrEventMessageAsObjectShouldReturnObject(CloudFormationCustomResourceEvent event) { Product product = extractDataFrom(event).as(Product.class); assertProduct(product); } + @ParameterizedTest + @Event(value = "scheduled_event.json", type = ScheduledEvent.class) + void testSerializeScheduledEvent_shouldReturnValidJson(ScheduledEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("detail")).isTrue(); + } + + @ParameterizedTest + @Event(value = "apigw_event.json", type = APIGatewayProxyRequestEvent.class) + void testSerializeAPIGatewayEvent_shouldReturnValidJson(APIGatewayProxyRequestEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("body")).isTrue(); + } + + @ParameterizedTest + @Event(value = "sqs_event.json", type = SQSEvent.class) + void testSerializeSQSEvent_shouldReturnValidJson(SQSEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("records")).isTrue(); + } + + @ParameterizedTest + @Event(value = "sns_event.json", type = SNSEvent.class) + void testSerializeSNSEvent_shouldReturnValidJson(SNSEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("records")).isTrue(); + } + + @ParameterizedTest + @Event(value = "kinesis_event.json", type = KinesisEvent.class) + void testSerializeKinesisEvent_shouldReturnValidJson(KinesisEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("records")).isTrue(); + } + + @ParameterizedTest + @Event(value = "kafka_event.json", type = KafkaEvent.class) + void testSerializeKafkaEvent_shouldReturnValidJson(KafkaEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("records")).isTrue(); + } + + @ParameterizedTest + @Event(value = "alb_event.json", type = ApplicationLoadBalancerRequestEvent.class) + void testSerializeALBEvent_shouldReturnValidJson(ApplicationLoadBalancerRequestEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("body")).isTrue(); + } + + @ParameterizedTest + @Event(value = "cwl_event.json", type = CloudWatchLogsEvent.class) + void testSerializeCWLEvent_shouldReturnValidJson(CloudWatchLogsEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("awsLogs")).isTrue(); + } + + @ParameterizedTest + @Event(value = "kf_event.json", type = KinesisFirehoseEvent.class) + void testSerializeKFEvent_shouldReturnValidJson(KinesisFirehoseEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("records")).isTrue(); + } + + @ParameterizedTest + @Event(value = "amq_event.json", type = ActiveMQEvent.class) + void testSerializeAMQEvent_shouldReturnValidJson(ActiveMQEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("messages")).isTrue(); + } + + @ParameterizedTest + @Event(value = "rabbitmq_event.json", type = RabbitMQEvent.class) + void testSerializeRabbitMQEvent_shouldReturnValidJson(RabbitMQEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("rmqMessagesByQueue")).isTrue(); + } + + @ParameterizedTest + @Event(value = "kasip_event.json", type = KinesisAnalyticsStreamsInputPreprocessingEvent.class) + void testSerializeKasipEvent_shouldReturnValidJson(KinesisAnalyticsStreamsInputPreprocessingEvent event) + throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("records")).isTrue(); + } + + @ParameterizedTest + @Event(value = "kafip_event.json", type = KinesisAnalyticsFirehoseInputPreprocessingEvent.class) + void testSerializeKafipEvent_shouldReturnValidJson(KinesisAnalyticsFirehoseInputPreprocessingEvent event) + throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("records")).isTrue(); + } + + @ParameterizedTest + @Event(value = "apigwv2_event.json", type = APIGatewayV2HTTPEvent.class) + void testSerializeApiGWV2Event_shouldReturnValidJson(APIGatewayV2HTTPEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("body")).isTrue(); + } + + @ParameterizedTest + @Event(value = "cfcr_event.json", type = CloudFormationCustomResourceEvent.class) + void testSerializeCfcrEvent_shouldReturnValidJson(CloudFormationCustomResourceEvent event) throws Exception { + String json = JsonConfig.get().getObjectMapper().valueToTree(event).toString(); + JsonNode parsed = JsonConfig.get().getObjectMapper().readTree(json); + assertThat(parsed.has("resourceProperties")).isTrue(); + } + } diff --git a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64FunctionTest.java b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64FunctionTest.java index d86af6671..478d3477c 100644 --- a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64FunctionTest.java +++ b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64FunctionTest.java @@ -16,21 +16,24 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; + +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeType; + import io.burt.jmespath.Expression; -import java.io.IOException; -import org.junit.jupiter.api.Test; import software.amazon.lambda.powertools.utilities.JsonConfig; -public class Base64FunctionTest { +class Base64FunctionTest { @Test - public void testPowertoolsBase64() throws IOException { - JsonNode event = - JsonConfig.get().getObjectMapper().readTree(this.getClass().getResourceAsStream("/custom_event.json")); - Expression expression = - JsonConfig.get().getJmesPath().compile("basket.powertools_base64(hiddenProduct)"); + void testPowertoolsBase64() throws IOException { + JsonNode event = JsonConfig.get().getObjectMapper() + .readTree(this.getClass().getResourceAsStream("/custom_event.json")); + Expression expression = JsonConfig.get().getJmesPath() + .compile("basket.powertools_base64(hiddenProduct)"); JsonNode result = expression.search(event); assertThat(result.getNodeType()).isEqualTo(JsonNodeType.STRING); assertThat(result.asText()).isEqualTo("{\n" + diff --git a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64GZipFunctionTest.java b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64GZipFunctionTest.java index eeb605076..6f9f9a592 100644 --- a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64GZipFunctionTest.java +++ b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/Base64GZipFunctionTest.java @@ -16,18 +16,21 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; + +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeType; + import io.burt.jmespath.Expression; import io.burt.jmespath.JmesPathType; -import java.io.IOException; -import org.junit.jupiter.api.Test; import software.amazon.lambda.powertools.utilities.JsonConfig; -public class Base64GZipFunctionTest { +class Base64GZipFunctionTest { @Test - public void testConstructor() { + void testConstructor() { Base64GZipFunction base64GZipFunction = new Base64GZipFunction(); assertThat(base64GZipFunction.name()).isEqualTo("powertools_base64_gzip"); assertThat(base64GZipFunction.argumentConstraints().expectedType().toLowerCase()).isEqualTo( @@ -38,18 +41,18 @@ public void testConstructor() { } @Test - public void testPowertoolsGzip() throws IOException { + void testPowertoolsGzip() throws IOException { JsonNode event = JsonConfig.get().getObjectMapper() .readTree(this.getClass().getResourceAsStream("/custom_event_gzip.json")); - Expression expression = - JsonConfig.get().getJmesPath().compile("basket.powertools_base64_gzip(hiddenProduct)"); + Expression expression = JsonConfig.get().getJmesPath() + .compile("basket.powertools_base64_gzip(hiddenProduct)"); JsonNode result = expression.search(event); assertThat(result.getNodeType()).isEqualTo(JsonNodeType.STRING); assertThat(result.asText()).isEqualTo("{ \"id\": 43242, \"name\": \"FooBar XY\", \"price\": 258}"); } @Test - public void testPowertoolsGzipEmptyJsonAttribute() throws IOException { + void testPowertoolsGzipEmptyJsonAttribute() throws IOException { JsonNode event = JsonConfig.get().getObjectMapper() .readTree(this.getClass().getResourceAsStream("/custom_event_gzip.json")); Expression expression = JsonConfig.get().getJmesPath().compile("basket.powertools_base64_gzip('')"); @@ -58,7 +61,7 @@ public void testPowertoolsGzipEmptyJsonAttribute() throws IOException { } @Test - public void testPowertoolsGzipWrongArgumentType() throws IOException { + void testPowertoolsGzipWrongArgumentType() throws IOException { JsonNode event = JsonConfig.get().getObjectMapper() .readTree(this.getClass().getResourceAsStream("/custom_event_gzip.json")); Expression expression = JsonConfig.get().getJmesPath().compile("basket.powertools_base64_gzip(null)"); @@ -68,21 +71,20 @@ public void testPowertoolsGzipWrongArgumentType() throws IOException { } @Test - public void testBase64GzipDecompressNull() { + void testBase64GzipDecompressNull() { String result = Base64GZipFunction.decompress(null); assertThat(result).isNull(); } @Test - public void testPowertoolsGzipNotCompressedJsonAttribute() throws IOException { + void testPowertoolsGzipNotCompressedJsonAttribute() throws IOException { JsonNode event = JsonConfig.get().getObjectMapper() .readTree(this.getClass().getResourceAsStream("/custom_event_gzip.json")); - Expression expression = - JsonConfig.get().getJmesPath().compile("basket.powertools_base64_gzip(encodedString)"); + Expression expression = JsonConfig.get().getJmesPath() + .compile("basket.powertools_base64_gzip(encodedString)"); JsonNode result = expression.search(event); assertThat(result.getNodeType()).isEqualTo(JsonNodeType.STRING); assertThat(result.asText()).isEqualTo("test"); } - } diff --git a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/JsonFunctionTest.java b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/JsonFunctionTest.java index 0bfb635fa..028dba9ea 100644 --- a/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/JsonFunctionTest.java +++ b/powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/jmespath/JsonFunctionTest.java @@ -16,17 +16,20 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; + +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeType; + import io.burt.jmespath.Expression; -import java.io.IOException; -import org.junit.jupiter.api.Test; import software.amazon.lambda.powertools.utilities.JsonConfig; -public class JsonFunctionTest { +class JsonFunctionTest { @Test - public void testJsonFunction() throws IOException { + void testJsonFunction() throws IOException { JsonNode event = JsonConfig.get().getObjectMapper() .readTree(this.getClass().getResourceAsStream("/custom_event_json.json")); Expression expression = JsonConfig.get().getJmesPath().compile("powertools_json(body)"); @@ -38,7 +41,7 @@ public void testJsonFunction() throws IOException { } @Test - public void testJsonFunctionChild() throws IOException { + void testJsonFunctionChild() throws IOException { JsonNode event = JsonConfig.get().getObjectMapper() .readTree(this.getClass().getResourceAsStream("/custom_event_json.json")); Expression expression = JsonConfig.get().getJmesPath().compile("powertools_json(body).list[0].item");