Search in sources :

Example 21 with AttributeValue

use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.

the class AttributeValueCoderTest method shouldPassForBooleanType.

@Test
public void shouldPassForBooleanType() throws IOException {
    AttributeValue expected = AttributeValue.builder().bool(false).build();
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 22 with AttributeValue

use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.

the class AttributeValueCoderTest method shouldPassForByteArray.

@Test
public void shouldPassForByteArray() throws IOException {
    AttributeValue expected = AttributeValue.builder().b(SdkBytes.fromByteArray("hello".getBytes(StandardCharsets.UTF_8))).build();
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 23 with AttributeValue

use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.

the class AttributeValueCoderTest method shouldPassForListType.

@Test
public void shouldPassForListType() throws IOException {
    List<AttributeValue> listAttr = new ArrayList<>();
    listAttr.add(AttributeValue.builder().s("innerMapValue1").build());
    listAttr.add(AttributeValue.builder().n("8976234").build());
    AttributeValue expected = AttributeValue.builder().l(listAttr).build();
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 24 with AttributeValue

use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.

the class AttributeValueCoderTest method shouldPassForListOfString.

@Test
public void shouldPassForListOfString() throws IOException {
    AttributeValue expected = AttributeValue.builder().ss(ImmutableList.of("foo", "bar")).build();
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 25 with AttributeValue

use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.

the class AttributeValueCoderTest method shouldPassForNullType.

@Test
public void shouldPassForNullType() throws IOException {
    AttributeValue expected = AttributeValue.builder().nul(true).build();
    AttributeValueCoder coder = AttributeValueCoder.of();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    coder.encode(expected, output);
    ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
    AttributeValue actual = coder.decode(in);
    Assert.assertEquals(expected, actual);
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

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