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();
}
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"));
}
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);
}
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);
}
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));
}
Aggregations