Skip to content

Commit dbda812

Browse files
committed
Test for ScheduledV2Event loader and update for LambdaEventSerializers
1 parent 41341c6 commit dbda812

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

aws-lambda-java-events/src/main/java/com/amazonaws/services/lambda/runtime/events/ScheduledV2Event.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
/*
2-
* Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5-
* the License. A copy of the License is located at
6-
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11-
* and limitations under the License.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
124
*/
135

146
package com.amazonaws.services.lambda.runtime.events;

aws-lambda-java-serialization/src/main/java/com/amazonaws/services/lambda/runtime/serialization/events/LambdaEventSerializers.java

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public class LambdaEventSerializers {
142142
KinesisTimeWindowEventMixin.class),
143143
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ScheduledEvent",
144144
ScheduledEventMixin.class),
145+
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.ScheduledV2Event",
146+
ScheduledEventMixin.class),
145147
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SecretsManagerRotationEvent",
146148
SecretsManagerRotationEventMixin.class),
147149
new SimpleEntry<>("com.amazonaws.services.lambda.runtime.events.SNSEvent",

aws-lambda-java-tests/src/main/java/com/amazonaws/services/lambda/runtime/tests/EventLoader.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public static ScheduledEvent loadScheduledEvent(String filename) {
101101
return loadEvent(filename, ScheduledEvent.class);
102102
}
103103

104+
public static ScheduledV2Event loadScheduledV2Event(String filename) {
105+
return loadEvent(filename, ScheduledV2Event.class);
106+
}
107+
104108
public static SNSEvent loadSNSEvent(String filename) {
105109
return loadEvent(filename, SNSEvent.class);
106110
}
@@ -127,7 +131,7 @@ public static <T> T loadEvent(String filename, Class<T> targetClass) {
127131
}
128132
if (stream == null) {
129133
try {
130-
stream = new FileInputStream(new File(filename));
134+
stream = new FileInputStream(filename);
131135
} catch (FileNotFoundException e) {
132136
throw new EventLoadingException("Cannot load " + filename, e);
133137
}

aws-lambda-java-tests/src/test/java/com/amazonaws/services/lambda/runtime/tests/EventLoaderTest.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
22
package com.amazonaws.services.lambda.runtime.tests;
33

4+
import com.amazonaws.services.lambda.runtime.events.*;
45
import com.amazonaws.services.lambda.runtime.events.models.dynamodb.AttributeValue;
56
import com.amazonaws.services.lambda.runtime.events.models.dynamodb.Record;
67
import com.amazonaws.services.lambda.runtime.events.models.dynamodb.StreamRecord;
@@ -14,9 +15,6 @@
1415

1516
import static java.time.Instant.ofEpochSecond;
1617
import static org.assertj.core.api.Assertions.*;
17-
import static org.assertj.core.api.Assertions.from;
18-
19-
import com.amazonaws.services.lambda.runtime.events.*;
2018

2119
public class EventLoaderTest {
2220

@@ -363,4 +361,17 @@ public void testLoadRabbitMQEvent() {
363361
assertThat(header1.get("bytes")).contains(118, 97, 108, 117, 101, 49);
364362
assertThat((Integer) headers.get("numberInHeader")).isEqualTo(10);
365363
}
364+
365+
@Test
366+
public void testLoadScheduledV2Event() {
367+
ScheduledV2Event event = EventLoader.loadScheduledV2Event("scheduler_event.json");
368+
369+
System.out.println("Event: " + event.toString());
370+
371+
assertThat(event).isNotNull();
372+
assertThat(event.getDetailType()).isEqualTo("Scheduled Event");
373+
assertThat(event.getSource()).isEqualTo("aws.scheduler");
374+
assertThat(event.getTime()).isEqualTo(DateTime.parse("2024-05-07T15:58:34Z"));
375+
assertThat(event.getDetail()).isEqualTo("{}");
376+
}
366377
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "0",
3+
"id": "4e6638b7-b892-4482-9762-8c58d4e71ecc",
4+
"detail-type": "Scheduled Event",
5+
"source": "aws.scheduler",
6+
"account": "123456789012",
7+
"time": "2024-05-07T15:58:34Z",
8+
"region": "eu-central-1",
9+
"resources": [
10+
"arn:aws:scheduler:eu-central-1:123456789012:schedule/default/demoschedule"
11+
],
12+
"detail": "{}"
13+
}

0 commit comments

Comments
 (0)