use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.
the class AttributeValueCoderTest method shouldPassForNumberType.
@Test
public void shouldPassForNumberType() throws IOException {
AttributeValue expected = new AttributeValue();
expected.setN("123");
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);
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.
the class AttributeValueCoderTest method shouldPassForOneListOfNumber.
@Test
public void shouldPassForOneListOfNumber() throws IOException {
AttributeValue expected = new AttributeValue();
expected.setNS(ImmutableList.of("123", "456"));
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);
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.
the class AttributeValueCoderTest method shouldPassForOneListOfByteArray.
@Test
public void shouldPassForOneListOfByteArray() throws IOException {
AttributeValue expected = new AttributeValue();
expected.setBS(ImmutableList.of(ByteBuffer.wrap("mylistbyte1".getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap("mylistbyte2".getBytes(StandardCharsets.UTF_8))));
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);
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project beam by apache.
the class AttributeValueCoderTest method shouldPassForByteArray.
@Test
public void shouldPassForByteArray() throws IOException {
AttributeValue expected = new AttributeValue();
expected.setB(ByteBuffer.wrap("hello".getBytes(StandardCharsets.UTF_8)));
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);
}
use of com.amazonaws.services.dynamodbv2.document.Expected in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testUpdateX509Record.
@Test
public void testUpdateX509Record() {
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
Date now = new Date();
X509CertRecord certRecord = getRecordNonNullableColumns(now);
certRecord.setLastNotifiedTime(now);
certRecord.setLastNotifiedServer("last-notified-server");
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
certRecord.setSvcDataUpdateTime(now);
UpdateItemSpec item = new UpdateItemSpec().withPrimaryKey("primaryKey", "athenz.provider:cn:1234").withAttributeUpdate(new AttributeUpdate("instanceId").put(certRecord.getInstanceId()), new AttributeUpdate("provider").put(certRecord.getProvider()), new AttributeUpdate("service").put(certRecord.getService()), new AttributeUpdate("currentSerial").put(certRecord.getCurrentSerial()), new AttributeUpdate("currentIP").put(certRecord.getCurrentIP()), new AttributeUpdate("currentTime").put(certRecord.getCurrentTime().getTime()), new AttributeUpdate("currentDate").put(DynamoDBUtils.getIso8601FromDate(certRecord.getCurrentTime())), new AttributeUpdate("prevSerial").put(certRecord.getPrevSerial()), new AttributeUpdate("prevIP").put(certRecord.getPrevIP()), new AttributeUpdate("prevTime").put(certRecord.getPrevTime().getTime()), new AttributeUpdate("clientCert").put(certRecord.getClientCert()), new AttributeUpdate("ttl").put(certRecord.getCurrentTime().getTime() / 1000L + 3660 * 720), new AttributeUpdate("svcDataUpdateTime").put(certRecord.getSvcDataUpdateTime().getTime()), new AttributeUpdate("expiryTime").put(certRecord.getExpiryTime().getTime()), new AttributeUpdate("hostName").put(certRecord.getHostName()));
Mockito.doReturn(updateOutcome).when(table).updateItem(item);
boolean requestSuccess = dbConn.updateX509CertRecord(certRecord);
assertTrue(requestSuccess);
ArgumentCaptor<UpdateItemSpec> itemCaptor = ArgumentCaptor.forClass(UpdateItemSpec.class);
Mockito.verify(table, times(1)).updateItem(itemCaptor.capture());
List<UpdateItemSpec> allValues = itemCaptor.getAllValues();
assertEquals(1, allValues.size());
UpdateItemSpec capturedItem = allValues.get(0);
assertEquals(capturedItem.getKeyComponents().toArray()[0].toString(), item.getKeyComponents().toArray()[0].toString());
List<AttributeUpdate> capturedAttributes = capturedItem.getAttributeUpdate();
List<AttributeUpdate> expectedAttributes = item.getAttributeUpdate();
for (int i = 0; i < expectedAttributes.size(); ++i) {
System.out.println("expected attr: " + expectedAttributes.get(i).getAttributeName() + ", value: " + expectedAttributes.get(i).getValue());
assertEquals(capturedAttributes.get(i).getAttributeName(), expectedAttributes.get(i).getAttributeName());
assertEquals(capturedAttributes.get(i).getValue(), expectedAttributes.get(i).getValue());
}
dbConn.close();
}
Aggregations