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

import com.example.lambda.*;
import software.amazon.awssdk.services.lambda.LambdaClient;
import org.junit.jupiter.api.*;
import software.amazon.awssdk.regions.Region;
import java.io.*;
import java.net.URISyntaxException;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;

@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class LambdaTest {

    private static LambdaClient awsLambda;
    private static String functionName="";
    private static String completeFunctionName="";
    private static String filePath="";
    private static String role="";
    private static String handler="";

    @BeforeAll
    public static void setUp() throws IOException, URISyntaxException {

        Region region = Region.US_EAST_1;
        awsLambda = LambdaClient.builder()
                .region(region)
                .build();

        try (InputStream input = LambdaTest.class.getClassLoader().getResourceAsStream("config.properties")) {

            Properties prop = new Properties();

            if (input == null) {
                System.out.println("Sorry, unable to find config.properties");
                return;
            }

            //load a properties file from class path, inside static method
            prop.load(input);

            // Populate the data members required for all tests
            functionName = prop.getProperty("functionName");
            completeFunctionName = prop.getProperty("completeFunctionName");
            filePath = prop.getProperty("filePath");
            role = prop.getProperty("role");
            handler = prop.getProperty("handler");
            completeFunctionName = prop.getProperty("completeFunctionName");

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    @Test
    @Order(1)
    public void whenInitializingAWSService_thenNotNull() {
        assertNotNull(awsLambda);
        System.out.println("Test 1 passed");
    }

    @Test
    @Order(2)
    public void CreateFunction() {
        CreateFunction.createLambdaFunction(awsLambda, functionName, filePath, role, handler);
        System.out.println("Test 2 passed");
    }

    @Test
    @Order(3)
    public void GetAccountSettings() {
        GetAccountSettings.getSettings(awsLambda);
        System.out.println("Test 3 passed");
    }

    @Test
    @Order(4)
    public void ListLambdaFunctions() {
        ListLambdaFunctions.listFunctions(awsLambda);
        System.out.println("Test 4 passed");
    }

    @Test
    @Order(5)
    public void LambdaInvoke() {

        LambdaInvoke.invokeFunction(awsLambda, completeFunctionName);
        System.out.println("Test 5 passed");
    }

    @Test
    @Order(6)
    public void DeleteFunction() {
        DeleteFunction.deleteLambdaFunction(awsLambda, functionName);
        System.out.println("Test 5 passed");
    }

}

@@ -346,24 +346,63 @@
 ava.util.*;%0A
+import java.util.concurrent.TimeUnit;%0A%0A
 import stati
@@ -682,25 +682,17 @@
  String 
-completeF
+f
 unctionN
@@ -686,32 +686,34 @@
 ing functionName
+Sc
 =%22%22;%0A    private
@@ -812,16 +812,91 @@
 dler=%22%22;
+%0A    private static String bucketName=%22%22;%0A    private static String key=%22%22;
 %0A%0A    @B
@@ -1015,14 +1015,14 @@
 .US_
+W
 E
-A
 ST_
-1
+2
 ;%0A  
@@ -1668,85 +1668,8 @@
 %22);%0A
-            completeFunctionName = prop.getProperty(%22completeFunctionName%22);%0A
     
@@ -1829,69 +1829,157 @@
     
-completeFunctionName = prop.getProperty(%22completeFunctionName
+functionNameSc = prop.getProperty(%22functionNameSc%22);%0A            bucketName = prop.getProperty(%22bucketName%22);%0A            key = prop.getProperty(%22key
 %22);%0A
@@ -2831,18 +2831,159 @@
 nvoke() 
-%7B%0A
+throws InterruptedException %7B%0A        System.out.println(%22*** Wait for 2 MIN so the resource is available%22);%0A        TimeUnit.MINUTES.sleep(2);
 %0A       
@@ -3026,17 +3026,9 @@
 da, 
-completeF
+f
 unct
@@ -3270,10 +3270,1086 @@
 %0A    %7D%0A%0A
+    @Test%0A    @Order(7)%0A    public void LambdaScenario() throws InterruptedException %7B%0A%0A        String funArn = LambdaScenario.createLambdaFunction(awsLambda, functionNameSc, filePath, role, handler);%0A        System.out.println(%22The function ARN is %22+funArn);%0A%0A        // Get the Lambda function%0A        System.out.println(%22Getting the %22 +functionNameSc +%22 Lambda function.%22);%0A        LambdaScenario.getFunction(awsLambda, functionNameSc);%0A%0A        // List the Lambda functions%0A        System.out.println(%22Listing all functions%22);%0A        LambdaScenario.listFunctions(awsLambda);%0A%0A        System.out.println(%22*** Wait for 2 MIN so the resource is available%22);%0A        TimeUnit.MINUTES.sleep(2);%0A        LambdaScenario.invokeFunction(awsLambda, functionNameSc);%0A        LambdaScenario.updateFunctionCode(awsLambda, functionNameSc, bucketName, key);%0A        TimeUnit.MINUTES.sleep(2);%0A%0A        // Invoke again with updated function.%0A        LambdaScenario.invokeFunction(awsLambda, functionNameSc);%0A        LambdaScenario.deleteLambdaFunction(awsLambda, functionNameSc );%0A    %7D%0A
 %7D%0A

Update LambdaTest.java