|
45 | 45 | import com.amazonaws.services.lambda.runtime.events.S3Event;
|
46 | 46 | import com.amazonaws.services.lambda.runtime.events.SNSEvent;
|
47 | 47 | import com.amazonaws.services.lambda.runtime.events.SQSEvent;
|
| 48 | +import com.amazonaws.services.lambda.runtime.events.ScheduledEvent; |
48 | 49 | import com.fasterxml.jackson.databind.ObjectMapper;
|
49 | 50 | import org.junit.jupiter.api.BeforeEach;
|
50 | 51 | import org.junit.jupiter.api.Test;
|
@@ -107,6 +108,36 @@ public class FunctionInvokerTests {
|
107 | 108 | + " \"timestamp\": 1712716805129\n"
|
108 | 109 | + " }\n"
|
109 | 110 | + "}";
|
| 111 | + |
| 112 | + String scheduleEvent = "{\n" |
| 113 | + + " \"version\": \"0\",\n" |
| 114 | + + " \"id\": \"17793124-05d4-b198-2fde-7ededc63b103\",\n" |
| 115 | + + " \"detail-type\": \"Object Created\",\n" |
| 116 | + + " \"source\": \"aws.s3\",\n" |
| 117 | + + " \"account\": \"111122223333\",\n" |
| 118 | + + " \"time\": \"2021-11-12T00:00:00Z\",\n" |
| 119 | + + " \"region\": \"ca-central-1\",\n" |
| 120 | + + " \"resources\": [\n" |
| 121 | + + " \"arn:aws:s3:::amzn-s3-demo-bucket1\"\n" |
| 122 | + + " ],\n" |
| 123 | + + " \"detail\": {\n" |
| 124 | + + " \"version\": \"0\",\n" |
| 125 | + + " \"bucket\": {\n" |
| 126 | + + " \"name\": \"amzn-s3-demo-bucket1\"\n" |
| 127 | + + " },\n" |
| 128 | + + " \"object\": {\n" |
| 129 | + + " \"key\": \"example-key\",\n" |
| 130 | + + " \"size\": 5,\n" |
| 131 | + + " \"etag\": \"b1946ac92492d2347c6235b4d2611184\",\n" |
| 132 | + + " \"version-id\": \"IYV3p45BT0ac8hjHg1houSdS1a.Mro8e\",\n" |
| 133 | + + " \"sequencer\": \"617f08299329d189\"\n" |
| 134 | + + " },\n" |
| 135 | + + " \"request-id\": \"N4N7GDK58NMKJ12R\",\n" |
| 136 | + + " \"requester\": \"123456789012\",\n" |
| 137 | + + " \"source-ip-address\": \"1.2.3.4\",\n" |
| 138 | + + " \"reason\": \"PutObject\"\n" |
| 139 | + + " }\n" |
| 140 | + + "} "; |
110 | 141 |
|
111 | 142 | String dynamoDbEvent = "{\n"
|
112 | 143 | + " \"Records\": [\n"
|
@@ -735,6 +766,20 @@ public void before() throws Exception {
|
735 | 766 | System.clearProperty("spring.cloud.function.definition");
|
736 | 767 | //this.getEnvironment().clear();
|
737 | 768 | }
|
| 769 | + |
| 770 | + @Test |
| 771 | + public void testScheduledEvent() throws Exception { |
| 772 | + System.setProperty("MAIN_CLASS", ScheduledEventConfiguration.class.getName()); |
| 773 | + System.setProperty("spring.cloud.function.definition", "event"); |
| 774 | + FunctionInvoker invoker = new FunctionInvoker(); |
| 775 | + |
| 776 | + InputStream targetStream = new ByteArrayInputStream(this.scheduleEvent.getBytes()); |
| 777 | + ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 778 | + invoker.handleRequest(targetStream, output, null); |
| 779 | + String result = new String(output.toByteArray(), StandardCharsets.UTF_8); |
| 780 | + System.out.println("Result: " + result); |
| 781 | + //assertThat(result).contains("APIGatewayCustomAuthorizerEvent(version=null, type=TOKEN"); |
| 782 | + } |
738 | 783 |
|
739 | 784 | @SuppressWarnings({ "rawtypes", "unchecked" })
|
740 | 785 | @Test
|
@@ -1969,4 +2014,17 @@ public String toString() {
|
1969 | 2014 | return this.name;
|
1970 | 2015 | }
|
1971 | 2016 | }
|
| 2017 | + |
| 2018 | + @EnableAutoConfiguration |
| 2019 | + @Configuration |
| 2020 | + public static class ScheduledEventConfiguration { |
| 2021 | + |
| 2022 | + @Bean |
| 2023 | + public Function<ScheduledEvent, ScheduledEvent> event() { |
| 2024 | + return event -> { |
| 2025 | + System.out.println("Event: " + event); |
| 2026 | + return event; |
| 2027 | + }; |
| 2028 | + } |
| 2029 | + } |
1972 | 2030 | }
|
0 commit comments