Search in sources :

Example 21 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue 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 22 with AttributeValue

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

the class QueryCommandTest method execute.

@Test
public void execute() {
    Map<String, AttributeValue> startKey = new HashMap<String, AttributeValue>();
    startKey.put("1", new AttributeValue("startKey"));
    List<String> attributeNames = Arrays.asList("attrNameOne", "attrNameTwo");
    exchange.getIn().setHeader(DdbConstants.ATTRIBUTE_NAMES, attributeNames);
    exchange.getIn().setHeader(DdbConstants.CONSISTENT_READ, true);
    exchange.getIn().setHeader(DdbConstants.START_KEY, startKey);
    exchange.getIn().setHeader(DdbConstants.LIMIT, 10);
    exchange.getIn().setHeader(DdbConstants.SCAN_INDEX_FORWARD, true);
    Map<String, Condition> keyConditions = new HashMap<String, Condition>();
    Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withN("1985"));
    keyConditions.put("1", condition);
    exchange.getIn().setHeader(DdbConstants.KEY_CONDITIONS, keyConditions);
    command.execute();
    Map<String, AttributeValue> mapAssert = new HashMap<String, AttributeValue>();
    mapAssert.put("1", new AttributeValue("LAST_KEY"));
    ConsumedCapacity consumed = (ConsumedCapacity) exchange.getIn().getHeader(DdbConstants.CONSUMED_CAPACITY);
    assertEquals(Integer.valueOf(1), exchange.getIn().getHeader(DdbConstants.COUNT, Integer.class));
    assertEquals(Double.valueOf(1.0), consumed.getCapacityUnits());
    assertEquals(mapAssert, exchange.getIn().getHeader(DdbConstants.LAST_EVALUATED_KEY, Map.class));
    assertEquals(keyConditions, exchange.getIn().getHeader(DdbConstants.KEY_CONDITIONS, Map.class));
    Map<?, ?> items = (Map<?, ?>) exchange.getIn().getHeader(DdbConstants.ITEMS, List.class).get(0);
    assertEquals(new AttributeValue("attrValue"), items.get("attrName"));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity) Test(org.junit.Test)

Example 23 with AttributeValue

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

the class ScanCommandTest method execute.

@Test
public void execute() {
    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withN("1985"));
    scanFilter.put("year", condition);
    exchange.getIn().setHeader(DdbConstants.SCAN_FILTER, scanFilter);
    command.execute();
    Map<String, AttributeValue> mapAssert = new HashMap<String, AttributeValue>();
    mapAssert.put("1", new AttributeValue("LAST_KEY"));
    ConsumedCapacity consumed = (ConsumedCapacity) exchange.getIn().getHeader(DdbConstants.CONSUMED_CAPACITY);
    assertEquals(scanFilter, ddbClient.scanRequest.getScanFilter());
    assertEquals(Integer.valueOf(10), exchange.getIn().getHeader(DdbConstants.SCANNED_COUNT, Integer.class));
    assertEquals(Integer.valueOf(1), exchange.getIn().getHeader(DdbConstants.COUNT, Integer.class));
    assertEquals(Double.valueOf(1.0), consumed.getCapacityUnits());
    assertEquals(mapAssert, exchange.getIn().getHeader(DdbConstants.LAST_EVALUATED_KEY, Map.class));
    Map<?, ?> items = (Map<?, ?>) exchange.getIn().getHeader(DdbConstants.ITEMS, List.class).get(0);
    assertEquals(new AttributeValue("attrValue"), items.get("attrName"));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity) Test(org.junit.Test)

Example 24 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue 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)

Example 25 with AttributeValue

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

the class DdbComponentIntegrationTest method select.

@Test
public void select() {
    final Map<String, AttributeValue> attributeMap = new HashMap<String, AttributeValue>();
    AttributeValue attributeValue = new AttributeValue("test value");
    attributeMap.put("name", attributeValue);
    Exchange exchange = template.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(DdbConstants.OPERATION, DdbOperations.PutItem);
            exchange.getIn().setHeader(DdbConstants.RETURN_VALUES, "ALL_OLD");
            exchange.getIn().setHeader(DdbConstants.ITEM, attributeMap);
        }
    });
    assertNotNull(exchange.getIn().getHeader(DdbConstants.ITEMS, List.class));
}
Also used : Exchange(org.apache.camel.Exchange) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) List(java.util.List) Test(org.junit.Test)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)33 HashMap (java.util.HashMap)23 Test (org.junit.Test)8 Condition (com.amazonaws.services.dynamodbv2.model.Condition)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)4 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)4 Map (java.util.Map)4 ExpectedAttributeValue (com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue)3 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)3 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)3 DynamoDBScanExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)2 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)2 ComparisonOperator (com.amazonaws.services.dynamodbv2.model.ComparisonOperator)2 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)2 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)2 KeysAndAttributes (com.amazonaws.services.dynamodbv2.model.KeysAndAttributes)2