Search in sources :

Example 36 with Item

use of com.amazonaws.services.dynamodbv2.document.Item in project jcabi-dynamo by jcabi.

the class RegionITCase method worksWithAmazon.

/**
 * Region.Simple can work with AWS.
 * @throws Exception If some problem inside
 */
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void worksWithAmazon() throws Exception {
    final String name = RandomStringUtils.randomAlphabetic(Tv.EIGHT);
    final RegionMock mock = new RegionMock();
    final Table tbl = mock.get(name).table(name);
    final String attr = RandomStringUtils.randomAlphabetic(Tv.EIGHT);
    final String value = RandomStringUtils.randomAlphanumeric(Tv.TEN);
    final String hash = RandomStringUtils.randomAlphanumeric(Tv.TEN);
    for (int idx = 0; idx < Tv.FIVE; ++idx) {
        tbl.put(new Attributes().with(mock.hash(), hash).with(mock.range(), idx).with(attr, value));
    }
    MatcherAssert.assertThat(tbl.frame().where(mock.hash(), Conditions.equalTo(hash)).through(new QueryValve().withLimit(1)), Matchers.hasSize(Tv.FIVE));
    final Frame frame = tbl.frame().where(attr, Conditions.equalTo(value)).through(new ScanValve().withLimit(Tv.TEN).withAttributeToGet(attr));
    MatcherAssert.assertThat(frame, Matchers.hasSize(Tv.FIVE));
    final Iterator<Item> items = frame.iterator();
    final Item item = items.next();
    final int range = Integer.parseInt(item.get(mock.range()).getN());
    MatcherAssert.assertThat(item.get(attr).getS(), Matchers.equalTo(value));
    item.put(attr, new AttributeValueUpdate(new AttributeValue("empty"), AttributeAction.PUT));
    MatcherAssert.assertThat(tbl.frame().where(mock.hash(), hash).where(mock.range(), Conditions.equalTo(range)).through(new ScanValve()).iterator().next().get(attr).getS(), Matchers.not(Matchers.equalTo(value)));
    items.remove();
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) AttributeValueUpdate(com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate) Test(org.junit.Test)

Example 37 with Item

use of com.amazonaws.services.dynamodbv2.document.Item in project jcabi-dynamo by jcabi.

the class MkRegionTest method storesAndReadsSingleAttribute.

/**
 * MkRegion can store and read items.
 * @throws Exception If some problem inside
 */
@Test
public void storesAndReadsSingleAttribute() throws Exception {
    final String table = "ideas";
    final String key = "number";
    final String attr = "total";
    final Region region = new MkRegion(new H2Data().with(table, new String[] { key }, attr));
    final Table tbl = region.table(table);
    tbl.put(new Attributes().with(key, "32443").with(attr, "0"));
    final Item item = tbl.frame().iterator().next();
    item.put(attr, new AttributeValueUpdate().withValue(new AttributeValue().withN("2")).withAction(AttributeAction.PUT));
    MatcherAssert.assertThat(item.get(attr).getN(), Matchers.equalTo("2"));
}
Also used : Item(com.jcabi.dynamo.Item) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) Table(com.jcabi.dynamo.Table) AttributeValueUpdate(com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate) Attributes(com.jcabi.dynamo.Attributes) Region(com.jcabi.dynamo.Region) Test(org.junit.Test)

Example 38 with Item

use of com.amazonaws.services.dynamodbv2.document.Item in project spring-integration-aws by spring-projects.

the class DynamoDbMetaDataStore method get.

@Override
public String get(String key) {
    Assert.hasText(key, "'key' must not be empty.");
    awaitForActive();
    Item item = this.table.getItem(KEY, key);
    return getValueIfAny(item);
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item)

Example 39 with Item

use of com.amazonaws.services.dynamodbv2.document.Item in project spring-integration-aws by spring-projects.

the class DynamoDbMetaDataStore method remove.

@Override
public String remove(String key) {
    Assert.hasText(key, "'key' must not be empty.");
    awaitForActive();
    Item item = this.table.deleteItem(new DeleteItemSpec().withPrimaryKey(KEY, key).withReturnValues(ReturnValue.ALL_OLD)).getItem();
    return getValueIfAny(item);
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)

Example 40 with Item

use of com.amazonaws.services.dynamodbv2.document.Item in project thunder by RohanNagar.

the class UsersDaoTest method testSuccessfulEmailUpdate.

@Test
public void testSuccessfulEmailUpdate() {
    when(table.getItem(anyString(), anyString())).thenReturn(item);
    PilotUser result = usersDao.update("existingEmail", user);
    assertEquals(user, result);
    verify(table, times(1)).getItem(anyString(), anyString());
    verify(table, times(1)).deleteItem(any(DeleteItemSpec.class));
    verify(table, times(1)).putItem(any(Item.class), any(Expected.class));
}
Also used : DeleteItemSpec(com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec) Item(com.amazonaws.services.dynamodbv2.document.Item) Expected(com.amazonaws.services.dynamodbv2.document.Expected) PilotUser(com.sanction.thunder.models.PilotUser) Test(org.junit.Test)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)20 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)17 AmazonClientException (com.amazonaws.AmazonClientException)13 AmazonServiceException (com.amazonaws.AmazonServiceException)13 HashMap (java.util.HashMap)13 Test (org.junit.Test)12 Item (com.amazonaws.services.dynamodbv2.document.Item)11 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)5 Expected (com.amazonaws.services.dynamodbv2.document.Expected)5 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)5 DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)4 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)4 ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)4 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)4 List (java.util.List)4 ToString (lombok.ToString)4 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)3 BatchGetItemOutcome (com.amazonaws.services.dynamodbv2.document.BatchGetItemOutcome)3