Skip to content

Commit

Permalink
#85 MkRegion more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Nov 19, 2016
1 parent 1b3c552 commit 03ae5b9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/dynamo/mock/H2Data.java
Expand Up @@ -213,7 +213,7 @@ public String apply(final String input) {
)
);
}
return matcher.group(1);
return matcher.group(1).toLowerCase(Locale.ENGLISH);
}
}
);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/jcabi/dynamo/mock/MkItem.java
Expand Up @@ -110,7 +110,8 @@ public boolean has(final String name) throws IOException {

@Override
public Map<String, AttributeValue> put(
final String name, final AttributeValueUpdate value) {
final String name, final AttributeValueUpdate value)
throws IOException {
return this.put(
new ImmutableMap.Builder<String, AttributeValueUpdate>()
.put(name, value).build()
Expand All @@ -119,12 +120,11 @@ public Map<String, AttributeValue> put(

@Override
public Map<String, AttributeValue> put(
final Map<String, AttributeValueUpdate> attrs) {
final Map<String, AttributeValueUpdate> attrs) throws IOException {
final Map<String, AttributeValue> keys =
new HashMap<String, AttributeValue>();
keys.putAll(this.attributes);
for (final String attr : attrs.keySet()) {
keys.remove(attr);
new HashMap<String, AttributeValue>(0);
for (final String attr : this.data.keys(this.table)) {
keys.put(attr, this.attributes.get(attr));
}
try {
this.data.update(
Expand Down
38 changes: 37 additions & 1 deletion src/test/java/com/jcabi/dynamo/mock/MkRegionTest.java
Expand Up @@ -29,6 +29,7 @@
*/
package com.jcabi.dynamo.mock;

import com.amazonaws.services.dynamodbv2.model.AttributeAction;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate;
import com.jcabi.dynamo.Attributes;
Expand All @@ -44,6 +45,7 @@
* @author Yegor Bugayenko (yegor@tpc2.com)
* @version $Id$
* @since 0.10
* @checkstyle MultipleStringLiteralsCheck (500 lines)
*/
public final class MkRegionTest {

Expand All @@ -56,14 +58,16 @@ public void storesAndReadsAttributes() throws Exception {
final String name = "users";
final String key = "id";
final String attr = "description";
final String nattr = "thenumber";
final Region region = new MkRegion(
new H2Data().with(name, new String[] {key}, attr)
new H2Data().with(name, new String[] {key}, attr, nattr)
);
final Table table = region.table(name);
table.put(
new Attributes()
.with(key, "32443")
.with(attr, "first value to \n\t€ save")
.with(nattr, "150")
);
final Item item = table.frame().iterator().next();
MatcherAssert.assertThat(item.has(attr), Matchers.is(true));
Expand All @@ -81,6 +85,38 @@ public void storesAndReadsAttributes() throws Exception {
item.get(attr).getS(),
Matchers.containsString("another value")
);
MatcherAssert.assertThat(
item.get(nattr).getN(),
Matchers.endsWith("50")
);
}

/**
* 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"));
}

}

0 comments on commit 03ae5b9

Please sign in to comment.