Skip to content

Commit 64424ca

Browse files
auto commit
1 parent 42b503e commit 64424ca

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/TestUtils.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package software.amazon.cryptography.examples.migration;
22

3+
import java.util.HashMap;
4+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
5+
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
6+
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
37
import java.util.UUID;
48

59
public class TestUtils {
@@ -14,4 +18,40 @@ public class TestUtils {
1418

1519
public static final String PARTITION_KEY =
1620
"PlaintextMigrationExample" + UUID.randomUUID();
21+
22+
/**
23+
* Deletes an item from a DynamoDB table.
24+
*
25+
* @param tableName The name of the DynamoDB table
26+
* @param partitionKeyName The name of partition key
27+
* @param sortKeyName The name of sort key
28+
* @param partitionKeyValue The value of the partition key
29+
* @param sortKeyValue The value of the sort key (can be null if table doesn't have a sort key)
30+
*/
31+
public static void cleanUpDDBItem(
32+
final String tableName,
33+
final String partitionKeyName,
34+
final String sortKeyName,
35+
final String partitionKeyValue,
36+
final String sortKeyValue
37+
) {
38+
final DynamoDbClient ddb = DynamoDbClient.builder().build();
39+
final HashMap<String, AttributeValue> keyToDelete = new HashMap<>();
40+
keyToDelete.put(
41+
partitionKeyName,
42+
AttributeValue.builder().s(partitionKeyValue).build()
43+
);
44+
if (sortKeyValue != null) {
45+
keyToDelete.put(
46+
sortKeyName,
47+
AttributeValue.builder().n(sortKeyValue).build()
48+
);
49+
}
50+
final DeleteItemRequest deleteRequest = DeleteItemRequest
51+
.builder()
52+
.tableName(tableName)
53+
.key(keyToDelete)
54+
.build();
55+
ddb.deleteItem(deleteRequest);
56+
}
1757
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/awsdbe/TestMigrationExampleStep1.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package software.amazon.cryptography.examples.migration.awsdbe;
22

3+
import java.util.Arrays;
4+
import java.util.List;
35
import org.testng.annotations.Test;
46
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep1;
57
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep2;
@@ -62,5 +64,9 @@ public void TestMigrationStep1() {
6264
3,
6365
TestUtils.PARTITION_KEY
6466
);
67+
List<String> sortkeys = Arrays.asList("0", "1", "2", "3");
68+
for (String sortkey : sortkeys) {
69+
TestUtils.cleanUpDDBItem(TestUtils.TEST_DDB_TABLE_NAME, "partition_key", "sort_key", TestUtils.PARTITION_KEY, sortkey);
70+
}
6571
}
6672
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/awsdbe/TestMigrationExampleStep2.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package software.amazon.cryptography.examples.migration.awsdbe;
22

3+
import java.util.Arrays;
4+
import java.util.List;
35
import org.testng.annotations.Test;
46
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep1;
57
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep2;
@@ -62,5 +64,9 @@ public void TestMigrationStep2() {
6264
3,
6365
TestUtils.PARTITION_KEY
6466
);
67+
List<String> sortkeys = Arrays.asList("0", "1", "2", "3");
68+
for (String sortkey : sortkeys) {
69+
TestUtils.cleanUpDDBItem(TestUtils.TEST_DDB_TABLE_NAME, "partition_key", "sort_key", TestUtils.PARTITION_KEY, sortkey);
70+
}
6571
}
6672
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/awsdbe/TestMigrationExampleStep3.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package software.amazon.cryptography.examples.migration.awsdbe;
22

33
import static org.testng.Assert.assertThrows;
4-
4+
import java.util.Arrays;
5+
import java.util.List;
56
import org.testng.annotations.Test;
67
import software.amazon.awssdk.core.exception.SdkClientException;
78
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep1;
@@ -75,5 +76,9 @@ public void TestMigrationStep0() {
7576
2,
7677
TestUtils.PARTITION_KEY
7778
);
79+
List<String> sortkeys = Arrays.asList("0", "1", "2", "3");
80+
for (String sortkey : sortkeys) {
81+
TestUtils.cleanUpDDBItem(TestUtils.TEST_DDB_TABLE_NAME, "partition_key", "sort_key", TestUtils.PARTITION_KEY, sortkey);
82+
}
7883
}
7984
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/awsdbe/encrypttable/TestEncryptExistingTable.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,10 @@ public void TestEncryptExistingTable() {
204204
TestUtils.TEST_KMS_KEY_ID,
205205
TestUtils.TEST_DDB_TABLE_NAME
206206
);
207+
208+
List<String> sortkeys = Arrays.asList("0", "1", "2");
209+
for (String sortkey : sortkeys) {
210+
TestUtils.cleanUpDDBItem(TestUtils.TEST_DDB_TABLE_NAME, "partition_key", "sort_key", TestUtils.PARTITION_KEY, sortkey);
211+
}
207212
}
208213
}

Examples/runtimes/java/Migration/PlaintextToAWSDBE/src/test/java/software/amazon/cryptography/examples/migration/plaintext/TestMigrationExampleStep0.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package software.amazon.cryptography.examples.migration.plaintext;
22

33
import static org.testng.Assert.assertThrows;
4-
4+
import java.util.Arrays;
5+
import java.util.List;
56
import org.testng.annotations.Test;
67
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep1;
78
import software.amazon.cryptography.examples.awsdbe.MigrationExampleStep2;
@@ -71,5 +72,9 @@ public void TestMigrationStep0() {
7172
);
7273
}
7374
);
75+
List<String> sortkeys = Arrays.asList("0", "1", "2", "3");
76+
for (String sortkey : sortkeys) {
77+
TestUtils.cleanUpDDBItem(TestUtils.TEST_DDB_TABLE_NAME, "partition_key", "sort_key", TestUtils.PARTITION_KEY, sortkey);
78+
}
7479
}
7580
}

0 commit comments

Comments
 (0)