From 41341c6af46cd0c9c56fa2225353cb84b4954ebc Mon Sep 17 00:00:00 2001 From: Tomasz Miller Date: Mon, 6 May 2024 15:13:17 +0200 Subject: [PATCH 1/6] New ScheduledV2Event implementation and fix for APIGatewayV2CustomAuthorizerEventTest when running on the non-US locale machine --- aws-lambda-java-events/README.md | 1 + .../runtime/events/ScheduledV2Event.java | 366 ++++++++++++++++++ ...APIGatewayV2CustomAuthorizerEventTest.java | 7 + 3 files changed, 374 insertions(+) create mode 100644 aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java diff --git a/aws-lambda-java-events/README.md b/aws-lambda-java-events/README.md index 6519bceb..6c32ffa5 100644 --- a/aws-lambda-java-events/README.md +++ b/aws-lambda-java-events/README.md @@ -49,6 +49,7 @@ * `S3BatchResponse` * `S3Event` * `ScheduledEvent` +* `ScheduledV2Event` * `SecretsManagerRotationEvent` * `SimpleIAMPolicyResponse` * `SNSEvent` diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java new file mode 100644 index 00000000..149d155d --- /dev/null +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java @@ -0,0 +1,366 @@ +/* + * Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package com.amazonaws.services.lambda.runtime.events; + +import org.joda.time.DateTime; + +import java.io.Serializable; +import java.util.List; + +/** + * represents a scheduled V2 event + */ +public class ScheduledV2Event implements Serializable, Cloneable { + + private static final long serialVersionUID = -463442139623175611L; + + private String version; + + private String account; + + private String region; + + private String detail; + + private String detailType; + + private String source; + + private String id; + + private DateTime time; + + private List resources; + + /** + * default constructor + */ + public ScheduledV2Event() { + } + + /** + * @return the version number + */ + public String getVersion() { + return version; + } + + /** + * @param version the version number + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * @param version version number + * @return ScheduledV2Event + */ + public ScheduledV2Event withVersion(String version) { + setVersion(version); + return this; + } + + /** + * @return the account id + */ + public String getAccount() { + return account; + } + + /** + * @param account the account id + */ + public void setAccount(String account) { + this.account = account; + } + + /** + * @param account account id + * @return ScheduledV2Event + */ + public ScheduledV2Event withAccount(String account) { + setAccount(account); + return this; + } + + /** + * @return the aws region + */ + public String getRegion() { + return region; + } + + /** + * @param region the aws region + */ + public void setRegion(String region) { + this.region = region; + } + + /** + * @param region aws region + * @return ScheduledV2Event + */ + public ScheduledV2Event withRegion(String region) { + setRegion(region); + return this; + } + + /** + * @return The details of the events (usually left blank) + */ + public String getDetail() { + return detail; + } + + /** + * @param detail The details of the events (usually left blank) + */ + public void setDetail(String detail) { + this.detail = detail; + } + + /** + * @param detail details of the events (usually left blank) + * @return ScheduledV2Event + */ + public ScheduledV2Event withDetail(String detail) { + setDetail(detail); + return this; + } + + /** + * @return The details type - see cloud watch events for more info + */ + public String getDetailType() { + return detailType; + } + + /** + * @param detailType The details type - see cloud watch events for more info + */ + public void setDetailType(String detailType) { + this.detailType = detailType; + } + + /** + * @param detailType The details type - see cloud watch events for more info + * @return ScheduledV2Event + */ + public ScheduledV2Event withDetailType(String detailType) { + setDetailType(detailType); + return this; + } + + /** + * @return the source of the event + */ + public String getSource() { + return source; + } + + /** + * @param source the source of the event + */ + public void setSource(String source) { + this.source = source; + } + + /** + * @param source source of the event + * @return ScheduledV2Event + */ + public ScheduledV2Event withSource(String source) { + setSource(source); + return this; + } + + /** + * @return the timestamp for when the event is scheduled + */ + public DateTime getTime() { + return this.time; + } + + /** + * @param time the timestamp for when the event is scheduled + */ + public void setTime(DateTime time) { + this.time = time; + } + + /** + * @param time the timestamp for when the event is scheduled + * @return ScheduledV2Event + */ + public ScheduledV2Event withTime(DateTime time) { + setTime(time); + return this; + } + + /** + * @return the id of the event + */ + public String getId() { + return id; + } + + /** + * @param id the id of the event + */ + public void setId(String id) { + this.id = id; + } + + /** + * @param id id of event + * @return ScheduledV2Event + */ + public ScheduledV2Event withId(String id) { + setId(id); + return this; + } + + /** + * @return the resources used by event + */ + public List getResources() { + return this.resources; + } + + /** + * @param resources the resources used by event + */ + public void setResources(List resources) { + this.resources = resources; + } + + /** + * @param resources list of resource names + * @return Scheduled V2 event object + */ + public ScheduledV2Event withResources(List resources) { + setResources(resources); + return this; + } + + /** + * Returns a string representation of this object; useful for testing and debugging. + * + * @return A string representation of this object. + * @see Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + if (getVersion() != null) + sb.append("version: ").append(getVersion()).append(","); + if (getAccount() != null) + sb.append("account: ").append(getAccount()).append(","); + if (getRegion() != null) + sb.append("region: ").append(getRegion()).append(","); + if (getDetail() != null) + sb.append("detail: ").append(getDetail()).append(","); + if (getDetailType() != null) + sb.append("detailType: ").append(getDetailType()).append(","); + if (getSource() != null) + sb.append("source: ").append(getSource()).append(","); + if (getId() != null) + sb.append("id: ").append(getId()).append(","); + if (getTime() != null) + sb.append("time: ").append(getTime().toString()).append(","); + if (getResources() != null) + sb.append("resources: ").append(getResources()); + sb.append("}"); + return sb.toString(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + + if (obj instanceof ScheduledV2Event == false) + return false; + ScheduledV2Event other = (ScheduledV2Event) obj; + if (other.getVersion() == null ^ this.getVersion() == null) + return false; + if (other.getVersion() != null && other.getVersion().equals(this.getVersion()) == false) + return false; + if (other.getAccount() == null ^ this.getAccount() == null) + return false; + if (other.getAccount() != null && other.getAccount().equals(this.getAccount()) == false) + return false; + if (other.getRegion() == null ^ this.getRegion() == null) + return false; + if (other.getRegion() != null && other.getRegion().equals(this.getRegion()) == false) + return false; + if (other.getDetail() == null ^ this.getDetail() == null) + return false; + if (other.getDetail() != null && other.getDetail().equals(this.getDetail()) == false) + return false; + if (other.getDetailType() == null ^ this.getDetailType() == null) + return false; + if (other.getDetailType() != null && other.getDetailType().equals(this.getDetailType()) == false) + return false; + if (other.getSource() == null ^ this.getSource() == null) + return false; + if (other.getSource() != null && other.getSource().equals(this.getSource()) == false) + return false; + if (other.getId() == null ^ this.getId() == null) + return false; + if (other.getId() != null && other.getId().equals(this.getId()) == false) + return false; + if (other.getTime() == null ^ this.getTime() == null) + return false; + if (other.getTime() != null && other.getTime().equals(this.getTime()) == false) + return false; + if (other.getResources() == null ^ this.getResources() == null) + return false; + if (other.getResources() != null && other.getResources().equals(this.getResources()) == false) + return false; + return true; + } + + @Override + public int hashCode() { + final int prime = 31; + int hashCode = 1; + + hashCode = prime * hashCode + ((getVersion() == null) ? 0 : getVersion().hashCode()); + hashCode = prime * hashCode + ((getAccount() == null) ? 0 : getAccount().hashCode()); + hashCode = prime * hashCode + ((getRegion() == null) ? 0 : getRegion().hashCode()); + hashCode = prime * hashCode + ((getDetail() == null) ? 0 : getDetail().hashCode()); + hashCode = prime * hashCode + ((getDetailType() == null) ? 0 : getDetailType().hashCode()); + hashCode = prime * hashCode + ((getSource() == null) ? 0 : getSource().hashCode()); + hashCode = prime * hashCode + ((getId() == null) ? 0 : getId().hashCode()); + hashCode = prime * hashCode + ((getTime() == null) ? 0 : getTime().hashCode()); + hashCode = prime * hashCode + ((getResources() == null) ? 0 : getResources().hashCode()); + return hashCode; + } + + @Override + public ScheduledV2Event clone() { + try { + return (ScheduledV2Event) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone()", e); + } + } + +} diff --git a/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java index 8f1662cd..52735b67 100644 --- a/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java +++ b/aws-lambda-java-events/src/test/java/com/amazonaws/services/lambda/runtime/events/APIGatewayV2CustomAuthorizerEventTest.java @@ -1,8 +1,10 @@ package com.amazonaws.services.lambda.runtime.events; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.time.Instant; +import java.util.Locale; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -12,6 +14,11 @@ public class APIGatewayV2CustomAuthorizerEventTest { private static final long TIME_EPOCH = 1601306426515L; private static final String TIME = "28/Sep/2020:15:14:43 +0000"; + @BeforeAll + static void beforeAll() { + Locale.setDefault(new Locale("en", "US")); + } + @Test public void testEpochLongAsAnInstant() { APIGatewayV2CustomAuthorizerEvent customAuthorizerEvent = APIGatewayV2CustomAuthorizerEvent.builder() From dbda812058fac0bab937f85b8dec868a851ff597 Mon Sep 17 00:00:00 2001 From: Tomasz Miller Date: Tue, 7 May 2024 15:41:25 +0200 Subject: [PATCH 2/6] Test for ScheduledV2Event loader and update for LambdaEventSerializers --- .../lambda/runtime/events/ScheduledV2Event.java | 12 ++---------- .../events/LambdaEventSerializers.java | 2 ++ .../lambda/runtime/tests/EventLoader.java | 6 +++++- .../lambda/runtime/tests/EventLoaderTest.java | 17 ++++++++++++++--- .../src/test/resources/scheduler_event.json | 13 +++++++++++++ 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 aws-lambda-java-tests/src/test/resources/scheduler_event.json diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java index 149d155d..3e299636 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java @@ -1,14 +1,6 @@ /* - * Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with - * the License. A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions - * and limitations under the License. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 */ package com.amazonaws.services.lambda.runtime.events; diff --git a/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializers.java b/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializers.java index 4173211e..c60259c6 100644 --- a/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializers.java +++ b/aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializers.java @@ -142,6 +142,8 @@ public class LambdaEventSerializers { KinesisTimeWindowEventMixin.class), new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ScheduledEvent", ScheduledEventMixin.class), + new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ScheduledV2Event", + ScheduledEventMixin.class), new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SecretsManagerRotationEvent", SecretsManagerRotationEventMixin.class), new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SNSEvent", diff --git a/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java b/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java index 7228fb90..3a653a0d 100644 --- a/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java +++ b/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java @@ -101,6 +101,10 @@ public static ScheduledEvent loadScheduledEvent(String filename) { return loadEvent(filename, ScheduledEvent.class); } + public static ScheduledV2Event loadScheduledV2Event(String filename) { + return loadEvent(filename, ScheduledV2Event.class); + } + public static SNSEvent loadSNSEvent(String filename) { return loadEvent(filename, SNSEvent.class); } @@ -127,7 +131,7 @@ public static T loadEvent(String filename, Class targetClass) { } if (stream == null) { try { - stream = new FileInputStream(new File(filename)); + stream = new FileInputStream(filename); } catch (FileNotFoundException e) { throw new EventLoadingException("Cannot load " + filename, e); } diff --git a/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java b/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java index 3177b9cc..4ed3564c 100644 --- a/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java +++ b/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java @@ -1,6 +1,7 @@ /* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ package com.amazonaws.services.lambda.runtime.tests; +import com.amazonaws.services.lambda.runtime.events.*; import com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue; import com.amazonaws.services.lambda.runtime.events.models.dynamodb.Record; import com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord; @@ -14,9 +15,6 @@ import static java.time.Instant.ofEpochSecond; import static org.assertj.core.api.Assertions.*; -import static org.assertj.core.api.Assertions.from; - -import com.amazonaws.services.lambda.runtime.events.*; public class EventLoaderTest { @@ -363,4 +361,17 @@ public void testLoadRabbitMQEvent() { assertThat(header1.get("bytes")).contains(118, 97, 108, 117, 101, 49); assertThat((Integer) headers.get("numberInHeader")).isEqualTo(10); } + + @Test + public void testLoadScheduledV2Event() { + ScheduledV2Event event = EventLoader.loadScheduledV2Event("scheduler_event.json"); + + System.out.println("Event: " + event.toString()); + + assertThat(event).isNotNull(); + assertThat(event.getDetailType()).isEqualTo("Scheduled Event"); + assertThat(event.getSource()).isEqualTo("aws.scheduler"); + assertThat(event.getTime()).isEqualTo(DateTime.parse("2024-05-07T15:58:34Z")); + assertThat(event.getDetail()).isEqualTo("{}"); + } } diff --git a/aws-lambda-java-tests/src/test/resources/scheduler_event.json b/aws-lambda-java-tests/src/test/resources/scheduler_event.json new file mode 100644 index 00000000..b56f3fb3 --- /dev/null +++ b/aws-lambda-java-tests/src/test/resources/scheduler_event.json @@ -0,0 +1,13 @@ +{ + "version": "0", + "id": "4e6638b7-b892-4482-9762-8c58d4e71ecc", + "detail-type": "Scheduled Event", + "source": "aws.scheduler", + "account": "123456789012", + "time": "2024-05-07T15:58:34Z", + "region": "eu-central-1", + "resources": [ + "arn:aws:scheduler:eu-central-1:123456789012:schedule/default/demoschedule" + ], + "detail": "{}" +} \ No newline at end of file From 1aad3e47aef9f8ca749e60aaa08d535a5d3a3de1 Mon Sep 17 00:00:00 2001 From: Tomasz Miller Date: Tue, 7 May 2024 15:47:19 +0200 Subject: [PATCH 3/6] Unnecessary printing in the EventLoaderTest.java removed --- .../services/lambda/runtime/tests/EventLoaderTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java b/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java index 4ed3564c..52e97bf0 100644 --- a/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java +++ b/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java @@ -366,8 +366,6 @@ public void testLoadRabbitMQEvent() { public void testLoadScheduledV2Event() { ScheduledV2Event event = EventLoader.loadScheduledV2Event("scheduler_event.json"); - System.out.println("Event: " + event.toString()); - assertThat(event).isNotNull(); assertThat(event.getDetailType()).isEqualTo("Scheduled Event"); assertThat(event.getSource()).isEqualTo("aws.scheduler"); From 442ca305af2de6c3ec1917cdba4c01ee3fbd1fcd Mon Sep 17 00:00:00 2001 From: Tomasz Miller Date: Tue, 9 Jul 2024 23:13:44 +0200 Subject: [PATCH 4/6] Code review related update --- .../runtime/events/ScheduledV2Event.java | 226 +----------------- .../lambda/runtime/tests/EventLoaderTest.java | 10 +- 2 files changed, 18 insertions(+), 218 deletions(-) diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java index 3e299636..fde71c0e 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java @@ -5,14 +5,23 @@ package com.amazonaws.services.lambda.runtime.events; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; import org.joda.time.DateTime; import java.io.Serializable; import java.util.List; /** - * represents a scheduled V2 event + * Represents a Scheduled V2 event sent to Lambda + * ScheduleV2 */ +@Data +@Builder(setterPrefix = "with") +@NoArgsConstructor +@AllArgsConstructor public class ScheduledV2Event implements Serializable, Cloneable { private static final long serialVersionUID = -463442139623175611L; @@ -35,219 +44,6 @@ public class ScheduledV2Event implements Serializable, Cloneable { private List resources; - /** - * default constructor - */ - public ScheduledV2Event() { - } - - /** - * @return the version number - */ - public String getVersion() { - return version; - } - - /** - * @param version the version number - */ - public void setVersion(String version) { - this.version = version; - } - - /** - * @param version version number - * @return ScheduledV2Event - */ - public ScheduledV2Event withVersion(String version) { - setVersion(version); - return this; - } - - /** - * @return the account id - */ - public String getAccount() { - return account; - } - - /** - * @param account the account id - */ - public void setAccount(String account) { - this.account = account; - } - - /** - * @param account account id - * @return ScheduledV2Event - */ - public ScheduledV2Event withAccount(String account) { - setAccount(account); - return this; - } - - /** - * @return the aws region - */ - public String getRegion() { - return region; - } - - /** - * @param region the aws region - */ - public void setRegion(String region) { - this.region = region; - } - - /** - * @param region aws region - * @return ScheduledV2Event - */ - public ScheduledV2Event withRegion(String region) { - setRegion(region); - return this; - } - - /** - * @return The details of the events (usually left blank) - */ - public String getDetail() { - return detail; - } - - /** - * @param detail The details of the events (usually left blank) - */ - public void setDetail(String detail) { - this.detail = detail; - } - - /** - * @param detail details of the events (usually left blank) - * @return ScheduledV2Event - */ - public ScheduledV2Event withDetail(String detail) { - setDetail(detail); - return this; - } - - /** - * @return The details type - see cloud watch events for more info - */ - public String getDetailType() { - return detailType; - } - - /** - * @param detailType The details type - see cloud watch events for more info - */ - public void setDetailType(String detailType) { - this.detailType = detailType; - } - - /** - * @param detailType The details type - see cloud watch events for more info - * @return ScheduledV2Event - */ - public ScheduledV2Event withDetailType(String detailType) { - setDetailType(detailType); - return this; - } - - /** - * @return the source of the event - */ - public String getSource() { - return source; - } - - /** - * @param source the source of the event - */ - public void setSource(String source) { - this.source = source; - } - - /** - * @param source source of the event - * @return ScheduledV2Event - */ - public ScheduledV2Event withSource(String source) { - setSource(source); - return this; - } - - /** - * @return the timestamp for when the event is scheduled - */ - public DateTime getTime() { - return this.time; - } - - /** - * @param time the timestamp for when the event is scheduled - */ - public void setTime(DateTime time) { - this.time = time; - } - - /** - * @param time the timestamp for when the event is scheduled - * @return ScheduledV2Event - */ - public ScheduledV2Event withTime(DateTime time) { - setTime(time); - return this; - } - - /** - * @return the id of the event - */ - public String getId() { - return id; - } - - /** - * @param id the id of the event - */ - public void setId(String id) { - this.id = id; - } - - /** - * @param id id of event - * @return ScheduledV2Event - */ - public ScheduledV2Event withId(String id) { - setId(id); - return this; - } - - /** - * @return the resources used by event - */ - public List getResources() { - return this.resources; - } - - /** - * @param resources the resources used by event - */ - public void setResources(List resources) { - this.resources = resources; - } - - /** - * @param resources list of resource names - * @return Scheduled V2 event object - */ - public ScheduledV2Event withResources(List resources) { - setResources(resources); - return this; - } - /** * Returns a string representation of this object; useful for testing and debugging. * @@ -287,7 +83,7 @@ public boolean equals(Object obj) { if (obj == null) return false; - if (obj instanceof ScheduledV2Event == false) + if (!(obj instanceof ScheduledV2Event)) return false; ScheduledV2Event other = (ScheduledV2Event) obj; if (other.getVersion() == null ^ this.getVersion() == null) diff --git a/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java b/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java index 52e97bf0..16c2aa60 100644 --- a/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java +++ b/aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java @@ -9,9 +9,7 @@ import org.junit.jupiter.api.Test; import java.time.Instant; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import static java.time.Instant.ofEpochSecond; import static org.assertj.core.api.Assertions.*; @@ -367,9 +365,15 @@ public void testLoadScheduledV2Event() { ScheduledV2Event event = EventLoader.loadScheduledV2Event("scheduler_event.json"); assertThat(event).isNotNull(); + assertThat(event.getVersion()).isEqualTo("0"); + assertThat(event.getId()).isEqualTo("4e6638b7-b892-4482-9762-8c58d4e71ecc"); assertThat(event.getDetailType()).isEqualTo("Scheduled Event"); assertThat(event.getSource()).isEqualTo("aws.scheduler"); + assertThat(event.getAccount()).isEqualTo("123456789012"); assertThat(event.getTime()).isEqualTo(DateTime.parse("2024-05-07T15:58:34Z")); + assertThat(event.getRegion()).isEqualTo("eu-central-1"); + assertThat(event.getResources()).isNotEmpty(); + assertThat(event.getResources()).isEqualTo(Collections.singletonList("arn:aws:scheduler:eu-central-1:123456789012:schedule/default/demoschedule")); assertThat(event.getDetail()).isEqualTo("{}"); } } From d97352360049a1edb6ca5c5c817a32b7ac9332e4 Mon Sep 17 00:00:00 2001 From: Tomasz Miller Date: Wed, 10 Jul 2024 09:23:19 +0200 Subject: [PATCH 5/6] Unnecessary methods deleted --- .../runtime/events/ScheduledV2Event.java | 107 ------------------ 1 file changed, 107 deletions(-) diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java index fde71c0e..94a5fb65 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java @@ -44,111 +44,4 @@ public class ScheduledV2Event implements Serializable, Cloneable { private List resources; - /** - * Returns a string representation of this object; useful for testing and debugging. - * - * @return A string representation of this object. - * @see Object#toString() - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("{"); - if (getVersion() != null) - sb.append("version: ").append(getVersion()).append(","); - if (getAccount() != null) - sb.append("account: ").append(getAccount()).append(","); - if (getRegion() != null) - sb.append("region: ").append(getRegion()).append(","); - if (getDetail() != null) - sb.append("detail: ").append(getDetail()).append(","); - if (getDetailType() != null) - sb.append("detailType: ").append(getDetailType()).append(","); - if (getSource() != null) - sb.append("source: ").append(getSource()).append(","); - if (getId() != null) - sb.append("id: ").append(getId()).append(","); - if (getTime() != null) - sb.append("time: ").append(getTime().toString()).append(","); - if (getResources() != null) - sb.append("resources: ").append(getResources()); - sb.append("}"); - return sb.toString(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - - if (!(obj instanceof ScheduledV2Event)) - return false; - ScheduledV2Event other = (ScheduledV2Event) obj; - if (other.getVersion() == null ^ this.getVersion() == null) - return false; - if (other.getVersion() != null && other.getVersion().equals(this.getVersion()) == false) - return false; - if (other.getAccount() == null ^ this.getAccount() == null) - return false; - if (other.getAccount() != null && other.getAccount().equals(this.getAccount()) == false) - return false; - if (other.getRegion() == null ^ this.getRegion() == null) - return false; - if (other.getRegion() != null && other.getRegion().equals(this.getRegion()) == false) - return false; - if (other.getDetail() == null ^ this.getDetail() == null) - return false; - if (other.getDetail() != null && other.getDetail().equals(this.getDetail()) == false) - return false; - if (other.getDetailType() == null ^ this.getDetailType() == null) - return false; - if (other.getDetailType() != null && other.getDetailType().equals(this.getDetailType()) == false) - return false; - if (other.getSource() == null ^ this.getSource() == null) - return false; - if (other.getSource() != null && other.getSource().equals(this.getSource()) == false) - return false; - if (other.getId() == null ^ this.getId() == null) - return false; - if (other.getId() != null && other.getId().equals(this.getId()) == false) - return false; - if (other.getTime() == null ^ this.getTime() == null) - return false; - if (other.getTime() != null && other.getTime().equals(this.getTime()) == false) - return false; - if (other.getResources() == null ^ this.getResources() == null) - return false; - if (other.getResources() != null && other.getResources().equals(this.getResources()) == false) - return false; - return true; - } - - @Override - public int hashCode() { - final int prime = 31; - int hashCode = 1; - - hashCode = prime * hashCode + ((getVersion() == null) ? 0 : getVersion().hashCode()); - hashCode = prime * hashCode + ((getAccount() == null) ? 0 : getAccount().hashCode()); - hashCode = prime * hashCode + ((getRegion() == null) ? 0 : getRegion().hashCode()); - hashCode = prime * hashCode + ((getDetail() == null) ? 0 : getDetail().hashCode()); - hashCode = prime * hashCode + ((getDetailType() == null) ? 0 : getDetailType().hashCode()); - hashCode = prime * hashCode + ((getSource() == null) ? 0 : getSource().hashCode()); - hashCode = prime * hashCode + ((getId() == null) ? 0 : getId().hashCode()); - hashCode = prime * hashCode + ((getTime() == null) ? 0 : getTime().hashCode()); - hashCode = prime * hashCode + ((getResources() == null) ? 0 : getResources().hashCode()); - return hashCode; - } - - @Override - public ScheduledV2Event clone() { - try { - return (ScheduledV2Event) super.clone(); - } catch (CloneNotSupportedException e) { - throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone()", e); - } - } - } From 014992640d57d9ffe768dc3c7d9dc267ac0ff769 Mon Sep 17 00:00:00 2001 From: Tomasz Miller Date: Wed, 10 Jul 2024 10:04:58 +0200 Subject: [PATCH 6/6] Update for documentation link and import --- .../services/lambda/runtime/events/ScheduledV2Event.java | 2 +- .../amazonaws/services/lambda/runtime/tests/EventLoader.java | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java index 94a5fb65..c5442457 100644 --- a/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java +++ b/aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java @@ -16,7 +16,7 @@ /** * Represents a Scheduled V2 event sent to Lambda - * ScheduleV2 + * Using Lambda with Amazon EventBridge Scheduler */ @Data @Builder(setterPrefix = "with") diff --git a/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java b/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java index 0dcc2a6f..ce28e84d 100644 --- a/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java +++ b/aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java @@ -5,10 +5,7 @@ import com.amazonaws.services.lambda.runtime.serialization.PojoSerializer; import com.amazonaws.services.lambda.runtime.serialization.events.LambdaEventSerializers; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; /** * Load events from json files and serialize them in Events