From 9aef7f21ece55732e512175a3e562698e8aa1ea5 Mon Sep 17 00:00:00 2001 From: Chris Anatalio Date: Fri, 21 Oct 2016 16:32:58 -0700 Subject: [PATCH] BAEL-223: Clean up and update dependencies --- spring-boot-data-dynamodb/pom.xml | 54 ++++++++---------- .../main/java/com/baeldung/Application.java | 13 +++++ .../spring/data/es/config/DynamoDBConfig.java | 13 ++--- .../spring/data/es/model/ProductInfo.java | 2 + .../ProductInfoRepository.java | 8 +-- .../main/java/org/baeldung/Application.java | 13 ----- .../src/main/resources/application.properties | 7 ++- .../ProductInfoRepositoryIntegrationTest.java | 55 +++++++++---------- 8 files changed, 78 insertions(+), 87 deletions(-) create mode 100644 spring-boot-data-dynamodb/src/main/java/com/baeldung/Application.java rename spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/{repository => repositories}/ProductInfoRepository.java (87%) delete mode 100644 spring-boot-data-dynamodb/src/main/java/org/baeldung/Application.java diff --git a/spring-boot-data-dynamodb/pom.xml b/spring-boot-data-dynamodb/pom.xml index 9c6c5a875f..11e1366f3e 100644 --- a/spring-boot-data-dynamodb/pom.xml +++ b/spring-boot-data-dynamodb/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung - spring-boot + spring-boot-dynamodb 0.0.1-SNAPSHOT jar Spring Boot Actuator @@ -17,27 +17,29 @@ - org.baeldung.boot.DemoApplication + com.baeldung.Application UTF-8 1.8 4.3.1.RELEASE - - - org.springframework.boot - spring-boot-starter-thymeleaf - + + + + org.springframework.data + spring-data-releasetrain + Gosling-SR1 + pom + import + + + + + org.springframework.boot spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-data-jpa - - org.springframework.boot spring-boot-starter-actuator @@ -77,28 +79,13 @@ org.springframework.boot spring-boot-starter-mail - - org.subethamail - subethasmtp - 3.1.7 - test - - + org.webjars bootstrap 3.3.4 - - org.webjars - jquery - 2.1.4 - - - org.springframework.data - spring-data-jpa - 1.10.2.RELEASE - + com.amazonaws aws-java-sdk-dynamodb @@ -108,7 +95,12 @@ com.github.derjust spring-data-dynamodb 4.3.1 - + + + org.apache.httpcomponents + httpclient + 4.5.2 + diff --git a/spring-boot-data-dynamodb/src/main/java/com/baeldung/Application.java b/spring-boot-data-dynamodb/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..f5e0e98fd4 --- /dev/null +++ b/spring-boot-data-dynamodb/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages = { "com.baeldung" }) +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/config/DynamoDBConfig.java b/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/config/DynamoDBConfig.java index f98292ea06..4bc8a128bc 100644 --- a/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/config/DynamoDBConfig.java +++ b/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/config/DynamoDBConfig.java @@ -1,18 +1,17 @@ package com.baeldung.spring.data.es.config; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; - import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; +import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; @Configuration -@ComponentScan(basePackages = { "com.baeldung.spring.data.es" }) +@EnableDynamoDBRepositories(basePackages = "com.baeldung.spring.data.es.repositories") public class DynamoDBConfig { @Value("${amazon.dynamodb.endpoint}") diff --git a/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/model/ProductInfo.java b/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/model/ProductInfo.java index 4c97d14045..3e75c9e6f2 100644 --- a/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/model/ProductInfo.java +++ b/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/model/ProductInfo.java @@ -3,7 +3,9 @@ package com.baeldung.spring.data.es.model; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; +import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; +@DynamoDBTable(tableName = "ProductInfo") public class ProductInfo { private String id; private String msrp; diff --git a/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/repository/ProductInfoRepository.java b/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/repositories/ProductInfoRepository.java similarity index 87% rename from spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/repository/ProductInfoRepository.java rename to spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/repositories/ProductInfoRepository.java index a30ff1c4aa..c5eee49634 100644 --- a/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/repository/ProductInfoRepository.java +++ b/spring-boot-data-dynamodb/src/main/java/com/baeldung/spring/data/es/repositories/ProductInfoRepository.java @@ -1,14 +1,12 @@ -package com.baeldung.spring.data.es.repository; - -import java.util.List; +package com.baeldung.spring.data.es.repositories; +import com.baeldung.spring.data.es.model.ProductInfo; import org.socialsignin.spring.data.dynamodb.repository.EnableScan; import org.springframework.data.repository.CrudRepository; -import com.baeldung.spring.data.es.model.ProductInfo; +import java.util.List; @EnableScan public interface ProductInfoRepository extends CrudRepository { - List findById(String id); } diff --git a/spring-boot-data-dynamodb/src/main/java/org/baeldung/Application.java b/spring-boot-data-dynamodb/src/main/java/org/baeldung/Application.java deleted file mode 100644 index aae0c427a9..0000000000 --- a/spring-boot-data-dynamodb/src/main/java/org/baeldung/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.context.ApplicationContext; - -@org.springframework.boot.autoconfigure.SpringBootApplication -public class Application { - private static ApplicationContext applicationContext; - - public static void main(String[] args) { - applicationContext = SpringApplication.run(Application.class, args); - } -} diff --git a/spring-boot-data-dynamodb/src/main/resources/application.properties b/spring-boot-data-dynamodb/src/main/resources/application.properties index fb5c8e2da0..e6911bc9e7 100644 --- a/spring-boot-data-dynamodb/src/main/resources/application.properties +++ b/spring-boot-data-dynamodb/src/main/resources/application.properties @@ -24,4 +24,9 @@ security.user.name=admin1 security.user.password=secret1 management.security.role=SUPERUSER -logging.level.org.springframework=INFO \ No newline at end of file +logging.level.org.springframework=INFO + +#AWS Keys +amazon.dynamodb.endpoint=http://localhost:8000/ +amazon.aws.accesskey=test1 +amazon.aws.secretkey=test1 \ No newline at end of file diff --git a/spring-boot-data-dynamodb/src/test/java/com/baeldung/spring/data/es/repository/ProductInfoRepositoryIntegrationTest.java b/spring-boot-data-dynamodb/src/test/java/com/baeldung/spring/data/es/repository/ProductInfoRepositoryIntegrationTest.java index 2421505acd..73ce60e79a 100644 --- a/spring-boot-data-dynamodb/src/test/java/com/baeldung/spring/data/es/repository/ProductInfoRepositoryIntegrationTest.java +++ b/spring-boot-data-dynamodb/src/test/java/com/baeldung/spring/data/es/repository/ProductInfoRepositoryIntegrationTest.java @@ -1,15 +1,22 @@ package com.baeldung.spring.data.es.repository; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.baeldung.Application; +import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; +import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; +import com.amazonaws.services.dynamodbv2.document.Table; +import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; +import com.amazonaws.services.dynamodbv2.model.CreateTableResult; +import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; +import com.amazonaws.services.dynamodbv2.model.ResourceInUseException; +import com.baeldung.Application; +import com.baeldung.spring.data.es.config.DynamoDBConfig; +import com.baeldung.spring.data.es.model.ProductInfo; +import com.baeldung.spring.data.es.repositories.ProductInfoRepository; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.ActiveProfiles; @@ -17,17 +24,12 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; -import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; -import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; -import com.amazonaws.services.dynamodbv2.document.DynamoDB; -import com.amazonaws.services.dynamodbv2.document.Table; -import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; -import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; -import com.amazonaws.services.dynamodbv2.model.ResourceInUseException; -import com.baeldung.spring.data.es.model.ProductInfo; +import java.util.List; + +import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@SpringApplicationConfiguration(classes = {Application.class, DynamoDBConfig.class, PropertyPlaceholderAutoConfiguration.class}) @WebAppConfiguration @IntegrationTest @ActiveProfiles("local") @@ -36,48 +38,41 @@ public class ProductInfoRepositoryIntegrationTest { private DynamoDBMapper dynamoDBMapper; - @Autowired - private DynamoDB dynamoDB; - @Autowired private AmazonDynamoDB amazonDynamoDB; @Autowired - ProductInfoRepository ProductInfoRepository; + ProductInfoRepository repository; private static final String EXPECTED_COST = "20"; private static final String EXPECTED_PRICE = "50"; - @BeforeClass - @Ignore - public static void setUp() throws Exception { + @Before + public void setup() throws Exception { try { dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB); - CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class); // 1 + CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class); - tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); // 2 + tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); - Table table = dynamoDB.createTable(tableRequest); // 3 - - table.waitForActive(); // 4 + amazonDynamoDB.createTable(tableRequest); } catch (ResourceInUseException e) { // Do nothing, table already created } // TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfoion table - dynamoDBMapper.batchDelete((List) ProductInfoRepository.findAll()); + dynamoDBMapper.batchDelete((List) repository.findAll()); } - @Ignore @Test public void givenItemWithExpectedCost_whenRunFindAll_thenItemIsFound() { ProductInfo productInfo = new ProductInfo(EXPECTED_COST, EXPECTED_PRICE); - ProductInfoRepository.save(productInfo); + repository.save(productInfo); - List result = (List) ProductInfoRepository.findAll(); + List result = (List) repository.findAll(); assertTrue("Not empty", result.size() > 0); assertTrue("Contains item with expected cost", result.get(0).getCost().equals(EXPECTED_COST)); }