1+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ import com .example .eventbridgeschedule .scenario .CloudFormationHelper ;
5+ import com .example .eventbridgeschedule .scenario .EventbridgeSchedulerActions ;
6+ import org .junit .jupiter .api .BeforeAll ;
7+ import org .junit .jupiter .api .MethodOrderer ;
8+ import org .junit .jupiter .api .Order ;
9+ import org .junit .jupiter .api .Tag ;
10+ import org .junit .jupiter .api .Test ;
11+ import org .junit .jupiter .api .TestInstance ;
12+ import org .junit .jupiter .api .TestMethodOrder ;
13+ import software .amazon .awssdk .services .scheduler .model .SchedulerException ;
14+
15+ import java .time .LocalDateTime ;
16+ import java .time .format .DateTimeFormatter ;
17+ import java .util .Map ;
18+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
19+
20+ @ TestInstance (TestInstance .Lifecycle .PER_METHOD )
21+ @ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
22+ public class SchedulerTest {
23+
24+ private static final String STACK_NAME = "workflow-stack-name23" ;
25+
26+ private static String emailAddress =
"[email protected] " ;
27+
28+ private static String scheduleGroupName = "myScheduleGroup" ;
29+ private static String roleArn = "" ;
30+ private static String snsTopicArn = "" ;
31+
32+ private static String oneTimeScheduleName = "testOneTime" ;
33+
34+ private static String recurringScheduleName = "recurringSchedule" ;
35+
36+ private static final EventbridgeSchedulerActions eventbridgeActions = new EventbridgeSchedulerActions ();
37+
38+ @ BeforeAll
39+ public static void setUp () {
40+ CloudFormationHelper .deployCloudFormationStack (STACK_NAME , emailAddress );
41+ Map <String , String > stackOutputs = CloudFormationHelper .getStackOutputs (STACK_NAME );
42+ roleArn = stackOutputs .get ("RoleARN" );
43+ snsTopicArn = stackOutputs .get ("SNStopicARN" );
44+ }
45+
46+ @ Test
47+ @ Tag ("IntegrationTest" )
48+ @ Order (1 )
49+ public void testCreateScheduleGroup () {
50+ assertDoesNotThrow (() -> {
51+ eventbridgeActions .createScheduleGroup (scheduleGroupName ).join ();
52+ });
53+ }
54+
55+ @ Test
56+ @ Tag ("IntegrationTest" )
57+ @ Order (2 )
58+ public void testOneTimeSchedule () {
59+ assertDoesNotThrow (() -> {
60+ LocalDateTime scheduledTime = LocalDateTime .now ();
61+ DateTimeFormatter formatter = DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss" );
62+
63+ String scheduleExpression = "at(" + scheduledTime .format (formatter ) + ")" ;
64+ eventbridgeActions .createScheduleAsync (
65+ oneTimeScheduleName ,
66+ scheduleExpression ,
67+ scheduleGroupName ,
68+ snsTopicArn ,
69+ roleArn ,
70+ "One time scheduled event test from schedule" ,
71+ true ,
72+ true ).join ();
73+ });
74+ }
75+
76+ @ Test
77+ @ Tag ("IntegrationTest" )
78+ @ Order (3 )
79+ public void testReoccuringSchedule () {
80+ assertDoesNotThrow (() -> {
81+ int scheduleRateInMinutes = 10 ;
82+ String scheduleExpression = "rate(" + scheduleRateInMinutes + " minutes)" ;
83+ return eventbridgeActions .createScheduleAsync (
84+ recurringScheduleName ,
85+ scheduleExpression ,
86+ scheduleGroupName ,
87+ snsTopicArn ,
88+ roleArn ,
89+ "Recurrent event test from schedule " + recurringScheduleName ,
90+ true ,
91+ true ).join ();
92+ });
93+ }
94+
95+ @ Test
96+ @ Tag ("IntegrationTest" )
97+ @ Order (4 )
98+ public void testDeleteScheduleGroup () {
99+ assertDoesNotThrow (() -> {
100+ eventbridgeActions .deleteScheduleGroupAsync (scheduleGroupName ).join ();
101+
102+ });
103+ }
104+
105+ @ Test
106+ @ Tag ("IntegrationTest" )
107+ @ Order (5 )
108+ public void testDelOneTimeSchedule () {
109+ assertDoesNotThrow (() -> {
110+ eventbridgeActions .deleteScheduleAsync (oneTimeScheduleName , scheduleGroupName ).join ();
111+ eventbridgeActions .deleteScheduleAsync (recurringScheduleName , scheduleGroupName ).join ();
112+ });
113+ }
114+
115+ @ Test
116+ @ Tag ("IntegrationTest" )
117+ @ Order (4 )
118+ public void testDelStack () {
119+ assertDoesNotThrow (() -> {
120+ CloudFormationHelper .destroyCloudFormationStack (STACK_NAME );
121+ });
122+ }
123+ }
0 commit comments