5
5
import com .example .ec2 .scenario .EC2Scenario ;
6
6
import com .google .gson .Gson ;
7
7
import org .junit .jupiter .api .*;
8
+ import org .slf4j .Logger ;
9
+ import org .slf4j .LoggerFactory ;
8
10
import software .amazon .awssdk .auth .credentials .EnvironmentVariableCredentialsProvider ;
9
11
import java .util .List ;
10
12
import java .util .concurrent .CompletableFuture ;
26
28
@ TestInstance (TestInstance .Lifecycle .PER_METHOD )
27
29
@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
28
30
public class EC2Test {
31
+ private static final Logger logger = LoggerFactory .getLogger (EC2Test .class );
29
32
private static String keyName = "" ;
30
33
private static String groupName = "" ;
31
34
private static String groupDesc = "" ;
@@ -59,7 +62,7 @@ public static void setUp() {
59
62
@ Test
60
63
@ Tag ("IntegrationTest" )
61
64
@ Order (1 )
62
- public void createKeyPair () {
65
+ public void testCreateKeyPair () {
63
66
try {
64
67
CompletableFuture <CreateKeyPairResponse > future = ec2Actions .createKeyPairAsync (keyNameSc , fileNameSc );
65
68
CreateKeyPairResponse response = future .join ();
@@ -70,21 +73,21 @@ public void createKeyPair() {
70
73
// Assert specific properties of the response
71
74
Assertions .assertNotNull (response .keyFingerprint (), "The key fingerprint should not be null" );
72
75
Assertions .assertFalse (response .keyFingerprint ().isEmpty (), "The key fingerprint should not be empty" );
73
- System . out . println ( "Key Pair successfully created. Key Fingerprint: " + response . keyFingerprint ());
76
+
74
77
75
78
} catch (RuntimeException rte ) {
76
79
System .err .println ("An exception occurred: " + (rte .getCause () != null ? rte .getCause ().getMessage () : rte .getMessage ()));
77
80
Assertions .fail ("Test failed due to an unexpected exception: " + rte .getMessage ());
78
81
}
79
82
80
- System . out . println ("Test 1 passed" );
83
+ logger . info ("Test 1 passed" );
81
84
}
82
85
83
86
84
87
@ Test
85
88
@ Tag ("IntegrationTest" )
86
89
@ Order (2 )
87
- public void createInstance () {
90
+ public void testCreateInstance () {
88
91
try {
89
92
CompletableFuture <String > future = ec2Actions .createSecurityGroupAsync (groupName , groupDesc , vpcIdSc , myIpAddressSc );
90
93
groupId = future .join ();
@@ -170,14 +173,14 @@ public void createInstance() {
170
173
Assertions .fail ("Test failed due to an unexpected exception while running instance: " + rte .getMessage ());
171
174
}
172
175
173
- System . out . println ( " \n Test 2 passed" );
176
+ logger . info ( " Test 2 passed" );
174
177
}
175
178
176
179
177
180
@ Test
178
181
@ Tag ("IntegrationTest" )
179
182
@ Order (3 )
180
- public void describeKeyPair () {
183
+ public void testDescribeKeyPair () {
181
184
try {
182
185
CompletableFuture <DescribeKeyPairsResponse > future = ec2Actions .describeKeysAsync ();
183
186
DescribeKeyPairsResponse response = future .join ();
@@ -202,13 +205,13 @@ public void describeKeyPair() {
202
205
Assertions .fail ("Test failed due to an unexpected exception while describing key pairs: " + rte .getMessage ());
203
206
}
204
207
205
- System . out . println ("Test 3 passed" );
208
+ logger . info ("Test 3 passed" );
206
209
}
207
210
208
211
@ Test
209
212
@ Tag ("IntegrationTest" )
210
213
@ Order (4 )
211
- public void deleteKeyPair () {
214
+ public void testDeleteKeyPair () {
212
215
try {
213
216
CompletableFuture <DeleteKeyPairResponse > future = ec2Actions .deleteKeysAsync (keyNameSc );
214
217
DeleteKeyPairResponse response = future .join ();
@@ -222,13 +225,13 @@ public void deleteKeyPair() {
222
225
Assertions .fail ("Test failed due to an unexpected exception while deleting key pair: " + rte .getMessage ());
223
226
}
224
227
225
- System . out . println ( " \n Test 4 passed" );
228
+ logger . info ( " Test 4 passed" );
226
229
}
227
230
228
231
@ Test
229
232
@ Tag ("IntegrationTest" )
230
233
@ Order (5 )
231
- public void describeSecurityGroup () {
234
+ public void testDescribeSecurityGroup () {
232
235
try {
233
236
CompletableFuture <String > future = ec2Actions .describeSecurityGroupArnByNameAsync (groupName );
234
237
groupId = future .join ();
@@ -241,14 +244,14 @@ public void describeSecurityGroup() {
241
244
Assertions .fail ("Test failed due to an unexpected exception while describing security groups: " + rte .getMessage ());
242
245
}
243
246
244
- System . out . println ( " \n Test 5 passed" );
247
+ logger . info ( " Test 5 passed" );
245
248
}
246
249
247
250
248
251
@ Test
249
252
@ Tag ("IntegrationTest" )
250
253
@ Order (6 )
251
- public void describeInstances () {
254
+ public void testDescribeInstances () {
252
255
try {
253
256
CompletableFuture <String > future = ec2Actions .describeEC2InstancesAsync (newInstanceId );
254
257
String publicIp = future .join ();
@@ -262,13 +265,13 @@ public void describeInstances() {
262
265
System .err .println ("An exception occurred: " + (rte .getCause () != null ? rte .getCause ().getMessage () : rte .getMessage ()));
263
266
Assertions .fail ("Test failed due to an unexpected exception while describing EC2 instances: " + rte .getMessage ());
264
267
}
265
- System . out . println ( " \n Test 6 passed" );
268
+ logger . info ( " Test 6 passed" );
266
269
}
267
270
268
271
@ Test
269
272
@ Tag ("IntegrationTest" )
270
- @ Order (8 )
271
- public void terminateInstance () {
273
+ @ Order (7 )
274
+ public void testTerminateInstance () {
272
275
try {
273
276
System .out .println ("Instance ID is: " + newInstanceId );
274
277
CompletableFuture <Object > future = ec2Actions .terminateEC2Async (newInstanceId );
@@ -284,7 +287,7 @@ public void terminateInstance() {
284
287
}
285
288
286
289
// Confirm that the test passed
287
- System . out . println ( " \n Test 8 passed" );
290
+ logger . info ( " Test 7 passed" );
288
291
}
289
292
290
293
private static String getSecretValues () {
0 commit comments