Skip to content

Commit

Permalink
Java V2 Update Java tests (#5067)
Browse files Browse the repository at this point in the history
* updated Java tests

* updated Java tests

* updated Java tests
  • Loading branch information
scmacdon authored Jul 11, 2023
1 parent 6476a9e commit 2f345b0
Show file tree
Hide file tree
Showing 18 changed files with 1,021 additions and 698 deletions.
22 changes: 16 additions & 6 deletions javav2/example_code/connect/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>ConnectJ2</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
Expand All @@ -19,14 +17,17 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<groups>IntegrationTest</groups>
</configuration>
</plugin>
</plugins>
</build>
Expand All @@ -48,6 +49,15 @@
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
101 changes: 87 additions & 14 deletions javav2/example_code/connect/src/test/java/ConnectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,29 @@
import com.example.connect.ListPhoneNumbers;
import com.example.connect.ListUsers;
import com.example.connect.SearchQueues;
import com.google.gson.Gson;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.connect.ConnectClient;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;

/**
* To run these integration tests, you must set the required values
* in the config.properties file or AWS Secrets Manager.
*/
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class ConnectTest {
Expand All @@ -41,9 +50,21 @@ public class ConnectTest {
public static void setUp() {
connectClient = ConnectClient.builder()
.region(Region.US_EAST_1)
.credentialsProvider(ProfileCredentialsProvider.create())
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build();

// Get the values to run these tests from AWS Secrets Manager.
Gson gson = new Gson();
String json = getSecretValues();
SecretValues values = gson.fromJson(json, SecretValues.class);
instanceAlias = values.getInstanceAlias();
contactId = values.getContactId();
existingInstanceId = values.getExistingInstanceId();
targetArn = values.getTargetArn();

// Uncomment this code block if you prefer using a config.properties file to retrieve AWS values required for these tests.
/*
try (InputStream input = ConnectTest.class.getClassLoader().getResourceAsStream("config.properties")) {
Properties prop = new Properties();
if (input == null) {
Expand All @@ -61,9 +82,11 @@ public static void setUp() {
} catch (IOException ex) {
ex.printStackTrace();
}
*/
}

@Test
@Tag("IntegrationTest")
@Order(1)
public void createInstance() {
instanceId = CreateInstance.createConnectInstance(connectClient, instanceAlias);
Expand All @@ -72,65 +95,115 @@ public void createInstance() {
}

@Test
@Tag("IntegrationTest")
@Order(2)
public void describeInstance() throws InterruptedException {
DescribeInstance.describeSpecificInstance(connectClient, instanceId);
assertDoesNotThrow(() ->DescribeInstance.describeSpecificInstance(connectClient, instanceId));
System.out.println("Test 2 passed");
}

@Test
@Tag("IntegrationTest")
@Order(3)
public void listInstances() {
ListInstances.listAllInstances(connectClient);
assertDoesNotThrow(() ->ListInstances.listAllInstances(connectClient));
System.out.println("Test 3 passed");
}

@Test
@Tag("IntegrationTest")
@Order(4)
public void deleteInstance() {
DeleteInstance.deleteSpecificInstance(connectClient, instanceId);
assertDoesNotThrow(() ->DeleteInstance.deleteSpecificInstance(connectClient, instanceId));
System.out.println("Test 4 passed");
}

@Test
@Order(5)
public void describeContact() {
DescribeContact.describeSpecificContact(connectClient, existingInstanceId, contactId);
assertDoesNotThrow(() ->DescribeContact.describeSpecificContact(connectClient, existingInstanceId, contactId));
System.out.println("Test 5 passed");
}

@Test
@Tag("IntegrationTest")
@Order(6)
public void describeInstanceAttribute() {
DescribeInstanceAttribute.describeAttribute(connectClient, existingInstanceId);
assertDoesNotThrow(() ->DescribeInstanceAttribute.describeAttribute(connectClient, existingInstanceId));
System.out.println("Test 6 passed");
}

@Test
@Tag("IntegrationTest")
@Order(7)
public void getContactAttributes() {
GetContactAttributes.getContactAttrs(connectClient, existingInstanceId, contactId);
assertDoesNotThrow(() -> GetContactAttributes.getContactAttrs(connectClient, existingInstanceId, contactId));
System.out.println("Test 7 passed");
}

@Test
@Tag("IntegrationTest")
@Order(8)
public void listPhoneNumbers() {
ListPhoneNumbers.getPhoneNumbers(connectClient, targetArn);
assertDoesNotThrow(() ->ListPhoneNumbers.getPhoneNumbers(connectClient, targetArn));
System.out.println("Test 8 passed");
}

@Test
@Tag("IntegrationTest")
@Order(9)
public void listUsers() {
ListUsers.getUsers(connectClient, existingInstanceId);
assertDoesNotThrow(() ->ListUsers.getUsers(connectClient, existingInstanceId));
System.out.println("Test 9 passed");
}

@Test
@Tag("IntegrationTest")
@Order(10)
public void searchQueues() {
SearchQueues.searchQueue(connectClient, existingInstanceId);
assertDoesNotThrow(() ->SearchQueues.searchQueue(connectClient, existingInstanceId));
System.out.println("Test 10 passed");
}

private static String getSecretValues() {
SecretsManagerClient secretClient = SecretsManagerClient.builder()
.region(Region.US_EAST_1)
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.build();
String secretName = "test/connect";

GetSecretValueRequest valueRequest = GetSecretValueRequest.builder()
.secretId(secretName)
.build();

GetSecretValueResponse valueResponse = secretClient.getSecretValue(valueRequest);
return valueResponse.secretString();
}

@Nested
@DisplayName("A class used to get test values from test/connect (an AWS Secrets Manager secret)")
class SecretValues {
private String instanceAlias;
private String contactId;
private String existingInstanceId;

private String targetArn;

public String getInstanceAlias() {
return instanceAlias;
}

public String getContactId() {
return contactId;
}

public String getExistingInstanceId() {
return existingInstanceId;
}

public String getTargetArn() {
return targetArn;
}
}
}

35 changes: 13 additions & 22 deletions javav2/example_code/dynamodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<groups>IntegrationTest</groups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</plugins>
</build>
<dependencyManagement>
<dependencies>
Expand All @@ -69,6 +51,15 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb-enhanced</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
Loading

0 comments on commit 2f345b0

Please sign in to comment.