Skip to content
Prev Previous commit
Next Next commit
Test for ScheduledV2Event loader and update for LambdaEventSerializers
  • Loading branch information
peniakoff committed May 7, 2024
commit dbda812058fac0bab937f85b8dec868a851ff597
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the header to

/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -127,7 +131,7 @@ public static <T> T loadEvent(String filename, Class<T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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() {
Comment thread
msailes marked this conversation as resolved.
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("{}");
}
}
13 changes: 13 additions & 0 deletions aws-lambda-java-tests/src/test/resources/scheduler_event.json
Original file line number Diff line number Diff line change
@@ -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": "{}"
}