Skip to content

Commit

Permalink
Create StepFunctionsTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon authored Jan 29, 2021
1 parent 3dc7593 commit 7303a29
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions javav2/example_code/stepfunctions/src/test/java/StepFunctionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

import com.example.stepfunctions.*;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sfn.SfnClient;
import java.io.*;
import java.util.*;

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

private static SfnClient sfnClient;
private static String stateMachineArn = ""; // gets dynamically set in a test
private static String exeArn = ""; // gets dynamically set in a test
private static String jsonFile = "";
private static String jsonFileSM = "";
private static String roleARN = "";
private static String stateMachineName = "";

@BeforeAll
public static void setUp() throws IOException {

Region region = Region.US_EAST_1;
sfnClient = SfnClient.builder()
.region(region)
.build();

try (InputStream input = StepFunctionsTest.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
jsonFile = prop.getProperty("jsonFile");
jsonFileSM = prop.getProperty("jsonFileSM");
roleARN = prop.getProperty("roleARN");
stateMachineName = prop.getProperty("stateMachineName");



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

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

@Test
@Order(2)
public void CreateStateMachine() {
stateMachineArn = CreateStateMachine.createMachine(sfnClient, roleARN, stateMachineName, jsonFileSM);
assertTrue(!stateMachineArn.isEmpty());
System.out.println("Test 2 passed");
}

@Test
@Order(3)
public void StartExecution() {
exeArn = StartExecution.startWorkflow(sfnClient, stateMachineArn, jsonFile);
assertTrue(!stateMachineArn.isEmpty());
System.out.println("Test 3 passed");
}

@Test
@Order(4)
public void ListStateMachines() {
ListStateMachines.listMachines(sfnClient);
System.out.println("Test 4 passed");
}

@Test
@Order(5)
public void ListActivities() {
ListActivities.getActivites(sfnClient);
System.out.println("Test 5 passed");

}


@Test
@Order(6)
public void GetExecutionHistory() {
GetExecutionHistory.getExeHistory(sfnClient,exeArn );
System.out.println("Test 6 passed");
}

@Test
@Order(7)
public void DeleteStateMachine() {

DeleteStateMachine.deleteMachine(sfnClient, stateMachineArn);
System.out.println("Test 7 passed");
}

}

0 comments on commit 7303a29

Please sign in to comment.