Search in sources :

Example 31 with AttributeValue

use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project syndesis-qe by syndesisio.

the class DynamoDbUtils method verifyRecordIsPresent.

public boolean verifyRecordIsPresent(Map<String, String> recordValue) {
    boolean tableContainsItem = false;
    ScanRequest scanRequest = ScanRequest.builder().tableName(tableName).build();
    ScanResponse result = dynamoDb.scan(scanRequest);
    for (Map<String, AttributeValue> item : result.items()) {
        if (item.isEmpty()) {
            fail("There is no record in the table");
        }
        int i = item.keySet().size() - 1;
        if (!tableContainsItem) {
            for (String key : item.keySet()) {
                if (item.get(key).s().equals(recordValue.get(key))) {
                    if (i > 0) {
                        i--;
                    } else {
                        tableContainsItem = true;
                        break;
                    }
                } else {
                    break;
                }
            }
        }
    }
    return tableContainsItem;
}
Also used : ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ScanResponse(software.amazon.awssdk.services.dynamodb.model.ScanResponse)

Aggregations

AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)31 HashMap (java.util.HashMap)14 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)13 Test (org.junit.Test)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Map (java.util.Map)6 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)5 ResourceNotFoundException (software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException)5 ScanRequest (software.amazon.awssdk.services.dynamodb.model.ScanRequest)5 Collectors (java.util.stream.Collectors)4 PutItemRequest (software.amazon.awssdk.services.dynamodb.model.PutItemRequest)4 List (java.util.List)3 Slf4j (lombok.extern.slf4j.Slf4j)3 lombok.val (lombok.val)3 AttributeDefinition (software.amazon.awssdk.services.dynamodb.model.AttributeDefinition)3 KeySchemaElement (software.amazon.awssdk.services.dynamodb.model.KeySchemaElement)3 ScanResponse (software.amazon.awssdk.services.dynamodb.model.ScanResponse)3 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2