Skip to content

Commit 6a183b8

Browse files
dnltskderXear
authored andcommitted
verify that additional root attribute is persisted on dynamodb table
1 parent facc230 commit 6a183b8

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

src/test/java/com/dasburo/spring/cache/dynamo/DynamoCacheTest.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515
package com.dasburo.spring.cache.dynamo;
1616

17+
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
18+
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
19+
import com.amazonaws.services.dynamodbv2.model.GetItemResult;
1720
import com.dasburo.spring.cache.dynamo.helper.Address;
1821
import com.dasburo.spring.cache.dynamo.rootattribute.RootAttributeConfig;
1922
import com.dasburo.spring.cache.dynamo.serializer.Jackson2JsonSerializer;
@@ -28,6 +31,7 @@
2831
import org.springframework.test.context.junit4.SpringRunner;
2932

3033
import java.time.Duration;
34+
import java.util.HashMap;
3135

3236
import static com.amazonaws.services.dynamodbv2.model.ScalarAttributeType.S;
3337
import static java.util.Collections.singletonList;
@@ -54,6 +58,9 @@ public class DynamoCacheTest {
5458
@Autowired
5559
private DynamoCacheWriter writer;
5660

61+
@Autowired
62+
private AmazonDynamoDB ddbClient;
63+
5764
private DynamoCache cache;
5865

5966
@Before
@@ -300,20 +307,49 @@ public void getWithCallableShouldNotResolveValueIfPresent() {
300307
}
301308

302309
@Test
303-
public void putWithRootAttributeConfigCanBeLoadedAgain() {
304-
final String key = "key";
305-
310+
public void putWithRootAttributeConfigDoesNotInfluenceTheCoreFunctionality() {
311+
//given
312+
final String itemKey = "key";
313+
final RootAttributeConfig streetRootAttribute = new RootAttributeConfig("street", S);
306314
Address address = new Address("someStreet", 1);
315+
307316
DynamoCacheConfiguration config = DynamoCacheConfiguration.defaultCacheConfig();
308317
config.setSerializer(new Jackson2JsonSerializer<>(Address.class));
309-
config.setRootAttributes(singletonList(new RootAttributeConfig("street", S)));
318+
config.setRootAttributes(singletonList(streetRootAttribute));
310319

311320
Cache addressCache = new DynamoCache(CACHE_NAME, writer, config);
312321

313-
addressCache.put(key, address);
322+
//when
323+
addressCache.put(itemKey, address);
314324

315-
Assert.assertNotNull(addressCache.get(key));
316-
Assert.assertEquals(addressCache.get(key).get(), address);
325+
//then
326+
Assert.assertNotNull(addressCache.get(itemKey));
327+
Assert.assertEquals(addressCache.get(itemKey).get(), address);
317328
}
318329

330+
@Test
331+
public void putWithRootAttributePersistsAdditionalRootAttributeOnDynamoDbTable() {
332+
//given
333+
final String itemKey = "key";
334+
final RootAttributeConfig streetRootAttribute = new RootAttributeConfig("street", S);
335+
Address address = new Address("someStreet", 1);
336+
337+
DynamoCacheConfiguration config = DynamoCacheConfiguration.defaultCacheConfig();
338+
config.setSerializer(new Jackson2JsonSerializer<>(Address.class));
339+
config.setRootAttributes(singletonList(streetRootAttribute));
340+
341+
Cache addressCache = new DynamoCache(CACHE_NAME, writer, config);
342+
343+
//when
344+
addressCache.put(itemKey, address);
345+
346+
//then
347+
HashMap<String, AttributeValue> ddbKey = new HashMap<>();
348+
ddbKey.put(DefaultDynamoCacheWriter.ATTRIBUTE_KEY, new AttributeValue(itemKey));
349+
350+
GetItemResult ddbItem = ddbClient.getItem(CACHE_NAME, ddbKey);
351+
AttributeValue storedRootAttribute = ddbItem.getItem().get(streetRootAttribute.getName());
352+
353+
Assert.assertEquals(storedRootAttribute.getS(), address.getStreet());
354+
}
319355
}

0 commit comments

Comments
 (0)