From c12e92e00128f9d02b1f1e7945e226cf3ffc841c Mon Sep 17 00:00:00 2001 From: Rene Enriquez Date: Fri, 14 Sep 2018 08:37:58 -0500 Subject: [PATCH 1/2] Updating README file - Removing getters and setters and adding missing constructor - Improving the tests - Adding an additional method to find byFirstName to improve the tests --- README.md | 103 ++++++++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 2f62765c..0d22e8b9 100644 --- a/README.md +++ b/README.md @@ -82,37 +82,27 @@ Create a DynamoDB entity for this table: @DynamoDBTable(tableName = "User") public class User { - private String id; - private String firstName; - private String lastName; - - @DynamoDBHashKey - @DynamoDBAutoGeneratedKey - public String getId() { - return id; - } - - @DynamoDBAttribute - public String getFirstName() { - return firstName; - } - - @DynamoDBAttribute - public String getLastName() { - return lastName; - } - - public void setId(String id) { - this.id = id; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } + @DynamoDBHashKey + @DynamoDBAutoGeneratedKey + private String id; + + @DynamoDBAttribute + private String firstName; + + @DynamoDBAttribute + private String lastName; + + public User(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public User() { + super(); + } + + // Getters and setters - public void setLastName(String lastName) { - this.lastName = lastName; - } } ``` @@ -123,7 +113,9 @@ package com.acme.repositories; @EnableScan public interface UserRepository extends CrudRepository { - List findByLastName(String lastName); + + List findByLastName(String lastName); + List findByFirstName(String firstName); } ``` @@ -133,7 +125,9 @@ or for paging and sorting... package com.acme.repositories; public interface UserRepository extends PagingAndSortingRepository { - Page findByLastName(String lastName,Pageable pageable); + + Page findByLastName(String lastName, Pageable pageable); + Page findByFirstName(String firstName, Pageable pageable); @EnableScan @EnableScanCount @@ -145,45 +139,40 @@ And finally write a test client ```java @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { - PropertyPlaceholderAutoConfiguration.class, DynamoDBConfig.class}) - public class UserRepositoryIntegrationTest { - +@SpringBootTest +public class UserRepositoryIntegrationTest { + @Autowired - UserRepository repository; - + private UserRepository repository; + @Test public void sampleTestCase() { User dave = new User("Dave", "Matthews"); repository.save(dave); - + User carter = new User("Carter", "Beauford"); repository.save(carter); - - List result = repository.findByLastName("Matthews"); - Assert.assertThat(result.size(), is(1)); - Assert.assertThat(result, hasItem(dave)); + + List matthewsFound = repository.findByLastName("Matthews"); + Assert.assertFalse(matthewsFound.isEmpty()); + + List cartersFound = repository.findByFirstName("Carter"); + Assert.assertFalse(cartersFound.isEmpty()); + } - + private static final long CAPACITY = 5L; - + @Autowired private AmazonDynamoDB amazonDynamoDB; - + @Before public void init() throws Exception { - // Delete User table in case it exists - amazonDynamoDB.listTables().getTableNames().stream(). - filter(tableName -> tableName.equals(User.TABLE_NAME)).forEach(tableName -> { - amazonDynamoDB.deleteTable(tableName); - }); - - //Create User table - amazonDynamoDB.createTable(new DynamoDBMapper(amazonDynamoDB) - .generateCreateTableRequest(User.class) - .withProvisionedThroughput(new ProvisionedThroughput(CAPACITY, CAPACITY))); + TableUtils.createTableIfNotExists(amazonDynamoDB, new DynamoDBMapper(amazonDynamoDB) + .generateCreateTableRequest(User.class) + .withProvisionedThroughput(new ProvisionedThroughput(CAPACITY, CAPACITY))); } - + } ``` From 151a592beeaf39244a250beec784911c7c47c9c5 Mon Sep 17 00:00:00 2001 From: Sebastian J Date: Thu, 11 Oct 2018 21:51:42 -0400 Subject: [PATCH 2/2] Adding contribution --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 2ddafaa2..3ea25f2b 100755 --- a/pom.xml +++ b/pom.xml @@ -790,6 +790,10 @@ Alex Simkin https://github.com/SimY4 + + Rene Enriquez + enriquezrene +