Search in sources :

Example 1 with ExpectedAttributeValue

use of com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue in project camel by apache.

the class DeleteItemCommandTest method execute.

@Test
public void execute() {
    Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("1", new AttributeValue("Key_1"));
    exchange.getIn().setHeader(DdbConstants.KEY, key);
    Map<String, ExpectedAttributeValue> updateCondition = new HashMap<String, ExpectedAttributeValue>();
    updateCondition.put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
    exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, updateCondition);
    exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");
    command.execute();
    assertEquals("DOMAIN1", ddbClient.deleteItemRequest.getTableName());
    assertEquals(key, ddbClient.deleteItemRequest.getKey());
    assertEquals(updateCondition, ddbClient.deleteItemRequest.getExpected());
    assertEquals("ALL_OLD", ddbClient.deleteItemRequest.getReturnValues());
    assertEquals(new AttributeValue("attrValue"), exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get("attrName"));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) HashMap(java.util.HashMap) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) Test(org.junit.Test)

Example 2 with ExpectedAttributeValue

use of com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue in project jcabi-dynamo by jcabi.

the class AttributesTest method buildsExpectedKeys.

/**
 * Attributes can build expected keys.
 * @throws Exception If some problem inside
 */
@Test
public void buildsExpectedKeys() throws Exception {
    final String attr = "attr-13";
    final String value = "some value \u20ac";
    MatcherAssert.assertThat(new Attributes().with(attr, value).asKeys(), Matchers.hasEntry(attr, new ExpectedAttributeValue(new AttributeValue(value))));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) Test(org.junit.Test)

Example 3 with ExpectedAttributeValue

use of com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue in project camel by apache.

the class PutItemCommandTest method execute.

@Test
public void execute() {
    Map<String, AttributeValue> attributeMap = new HashMap<String, AttributeValue>();
    AttributeValue attributeValue = new AttributeValue("test value");
    attributeMap.put("name", attributeValue);
    exchange.getIn().setHeader(DdbConstants.ITEM, attributeMap);
    Map<String, ExpectedAttributeValue> expectedAttributeValueMap = new HashMap<String, ExpectedAttributeValue>();
    expectedAttributeValueMap.put("name", new ExpectedAttributeValue(attributeValue));
    exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, expectedAttributeValueMap);
    command.execute();
    assertEquals("DOMAIN1", ddbClient.putItemRequest.getTableName());
    assertEquals(attributeMap, ddbClient.putItemRequest.getItem());
    assertEquals(expectedAttributeValueMap, ddbClient.putItemRequest.getExpected());
    assertEquals(new AttributeValue("attrValue"), exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get("attrName"));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) HashMap(java.util.HashMap) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) Test(org.junit.Test)

Example 4 with ExpectedAttributeValue

use of com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue in project camel by apache.

the class UpdateItemCommandTest method execute.

@Test
public void execute() {
    Map<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("1", new AttributeValue("Key_1"));
    exchange.getIn().setHeader(DdbConstants.KEY, key);
    Map<String, AttributeValueUpdate> attributeMap = new HashMap<String, AttributeValueUpdate>();
    AttributeValueUpdate attributeValue = new AttributeValueUpdate(new AttributeValue("new value"), AttributeAction.ADD);
    attributeMap.put("name", attributeValue);
    exchange.getIn().setHeader(DdbConstants.UPDATE_VALUES, attributeMap);
    Map<String, ExpectedAttributeValue> expectedAttributeValueMap = new HashMap<String, ExpectedAttributeValue>();
    expectedAttributeValueMap.put("name", new ExpectedAttributeValue(new AttributeValue("expected value")));
    exchange.getIn().setHeader(DdbConstants.UPDATE_CONDITION, expectedAttributeValueMap);
    exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");
    command.execute();
    assertEquals("DOMAIN1", ddbClient.updateItemRequest.getTableName());
    assertEquals(attributeMap, ddbClient.updateItemRequest.getAttributeUpdates());
    assertEquals(key, ddbClient.updateItemRequest.getKey());
    assertEquals(expectedAttributeValueMap, ddbClient.updateItemRequest.getExpected());
    assertEquals("ALL_OLD", ddbClient.updateItemRequest.getReturnValues());
    assertEquals(new AttributeValue("attrValue"), exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class).get("attrName"));
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) AttributeValueUpdate(com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate) HashMap(java.util.HashMap) ExpectedAttributeValue(com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue) Test(org.junit.Test)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 ExpectedAttributeValue (com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)1