2020import static org .hamcrest .Matchers .nullValue ;
2121import static software .amazon .awssdk .enhanced .dynamodb .internal .AttributeValues .stringValue ;
2222
23+ import org .assertj .core .api .Assertions ;
2324import org .hamcrest .MatcherAssert ;
2425import org .junit .After ;
2526import org .junit .Before ;
3334import software .amazon .awssdk .enhanced .dynamodb .functionaltests .models .SimpleImmutable ;
3435import software .amazon .awssdk .enhanced .dynamodb .model .DeleteItemEnhancedRequest ;
3536import software .amazon .awssdk .enhanced .dynamodb .model .DeleteItemEnhancedResponse ;
37+ import software .amazon .awssdk .enhanced .dynamodb .model .DescribeTableEnhancedResponse ;
3638import software .amazon .awssdk .enhanced .dynamodb .model .GetItemEnhancedResponse ;
3739import software .amazon .awssdk .enhanced .dynamodb .model .PutItemEnhancedRequest ;
3840import software .amazon .awssdk .enhanced .dynamodb .model .PutItemEnhancedResponse ;
4244import software .amazon .awssdk .services .dynamodb .model .DeleteTableRequest ;
4345import software .amazon .awssdk .services .dynamodb .model .ResourceNotFoundException ;
4446import software .amazon .awssdk .services .dynamodb .model .ReturnValue ;
47+ import software .amazon .awssdk .services .dynamodb .model .TableDescription ;
4548
4649public class AnnotatedImmutableTableSchemaTest extends LocalDynamoDbSyncTestBase {
4750
@@ -72,16 +75,25 @@ public void deleteTable() {
7275 }
7376 }
7477
78+ @ Test
79+ public void describeTable_succeeds () {
80+ DescribeTableEnhancedResponse describeTableEnhancedResponse = mappedTable .describeTable ();
81+ Assertions .assertThat (describeTableEnhancedResponse .table ()).isNotNull ();
82+ Assertions .assertThat (describeTableEnhancedResponse .table ().tableName ()).isEqualTo (getConcreteTableName (TABLE_NAME ));
83+ }
84+
7585 @ Test
7686 public void createTableWithDefaults_thenDeleteTable_succeeds () {
7787 String tableName = TABLE_NAME + "-1" ;
7888
7989 DynamoDbTable <SimpleImmutable > mappedTable = enhancedClient .table (getConcreteTableName (tableName ), TABLE_SCHEMA );
8090 mappedTable .createTable ();
8191
82- String actualTableName = mappedTable .describeTable ().table ().tableName ();
83- Long actualReadCapacityUnits = mappedTable .describeTable ().table ().provisionedThroughput ().readCapacityUnits ();
84- Long actualWriteCapacityUnits = mappedTable .describeTable ().table ().provisionedThroughput ().writeCapacityUnits ();
92+ TableDescription tableDescription = mappedTable .describeTable ().table ();
93+
94+ String actualTableName = tableDescription .tableName ();
95+ Long actualReadCapacityUnits = tableDescription .provisionedThroughput ().readCapacityUnits ();
96+ Long actualWriteCapacityUnits = tableDescription .provisionedThroughput ().writeCapacityUnits ();
8597
8698 MatcherAssert .assertThat (actualTableName , is (getConcreteTableName (tableName )));
8799 MatcherAssert .assertThat (actualReadCapacityUnits , is (0L ));
@@ -103,13 +115,23 @@ public void createTableWithProvisionedThroughput_succeeds() {
103115 DynamoDbTable <SimpleImmutable > mappedTable = enhancedClient .table (getConcreteTableName (tableName ), TABLE_SCHEMA );
104116 mappedTable .createTable (r -> r .provisionedThroughput (getDefaultProvisionedThroughput ()));
105117
106- String actualTableName = mappedTable .describeTable ().table ().tableName ();
107- Long actualReadCapacityUnits = mappedTable .describeTable ().table ().provisionedThroughput ().readCapacityUnits ();
108- Long actualWriteCapacityUnits = mappedTable .describeTable ().table ().provisionedThroughput ().writeCapacityUnits ();
118+ TableDescription tableDescription = mappedTable .describeTable ().table ();
119+
120+ String actualTableName = tableDescription .tableName ();
121+ Long actualReadCapacityUnits = tableDescription .provisionedThroughput ().readCapacityUnits ();
122+ Long actualWriteCapacityUnits = tableDescription .provisionedThroughput ().writeCapacityUnits ();
109123
110124 MatcherAssert .assertThat (actualTableName , is (getConcreteTableName (tableName )));
111125 MatcherAssert .assertThat (actualReadCapacityUnits , is (getDefaultProvisionedThroughput ().readCapacityUnits ()));
112126 MatcherAssert .assertThat (actualWriteCapacityUnits , is (getDefaultProvisionedThroughput ().writeCapacityUnits ()));
127+
128+ getDynamoDbClient ().deleteTable (DeleteTableRequest .builder ()
129+ .tableName (getConcreteTableName (tableName ))
130+ .build ());
131+
132+ assertThatThrownBy (mappedTable ::describeTable )
133+ .isInstanceOf (ResourceNotFoundException .class )
134+ .hasMessageContaining ("Cannot do operations on a non-existent table" );
113135 }
114136
115137 @ Test
0 commit comments