Skip to content

Commit e4e9f48

Browse files
authored
Merge pull request eugenp#3659 from knightdna/BAEL-681
BAEL-681
2 parents 93213af + 9376e8c commit e4e9f48

3 files changed

Lines changed: 128 additions & 7 deletions

File tree

‎persistence-modules/spring-data-dynamodb/pom.xml‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<spring-data-dynamodb.version>4.4.1</spring-data-dynamodb.version>
2424
<aws-java-sdk-dynamodb.version>1.11.64</aws-java-sdk-dynamodb.version>
2525
<bootstrap.version>3.3.7-1</bootstrap.version>
26+
<sqlite4java.version>1.0.392</sqlite4java.version>
27+
<dynamodb.version>1.11.106</dynamodb.version>
28+
<dynamodblocal.version>1.11.86</dynamodblocal.version>
29+
<dynamodblocal.repository.url>https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/release</dynamodblocal.repository.url>
2630
</properties>
2731

2832
<dependencyManagement>
@@ -103,6 +107,57 @@
103107
<artifactId>httpclient</artifactId>
104108
<version>${httpclient.version}</version>
105109
</dependency>
110+
<!-- ================================================== -->
111+
<!-- DynamoDBLocal dependencies -->
112+
<!-- ================================================== -->
113+
<dependency>
114+
<groupId>com.amazonaws</groupId>
115+
<artifactId>DynamoDBLocal</artifactId>
116+
<version>${dynamodblocal.version}</version>
117+
<scope>test</scope>
118+
</dependency>
119+
<dependency>
120+
<groupId>com.almworks.sqlite4java</groupId>
121+
<artifactId>sqlite4java</artifactId>
122+
<version>${sqlite4java.version}</version>
123+
<scope>test</scope>
124+
</dependency>
125+
<dependency>
126+
<groupId>com.almworks.sqlite4java</groupId>
127+
<artifactId>sqlite4java-win32-x86</artifactId>
128+
<version>${sqlite4java.version}</version>
129+
<type>dll</type>
130+
<scope>test</scope>
131+
</dependency>
132+
<dependency>
133+
<groupId>com.almworks.sqlite4java</groupId>
134+
<artifactId>sqlite4java-win32-x64</artifactId>
135+
<version>${sqlite4java.version}</version>
136+
<type>dll</type>
137+
<scope>test</scope>
138+
</dependency>
139+
<dependency>
140+
<groupId>com.almworks.sqlite4java</groupId>
141+
<artifactId>libsqlite4java-osx</artifactId>
142+
<version>${sqlite4java.version}</version>
143+
<type>dylib</type>
144+
<scope>test</scope>
145+
</dependency>
146+
<dependency>
147+
<groupId>com.almworks.sqlite4java</groupId>
148+
<artifactId>libsqlite4java-linux-i386</artifactId>
149+
<version>${sqlite4java.version}</version>
150+
<type>so</type>
151+
<scope>test</scope>
152+
</dependency>
153+
<dependency>
154+
<groupId>com.almworks.sqlite4java</groupId>
155+
<artifactId>libsqlite4java-linux-amd64</artifactId>
156+
<version>${sqlite4java.version}</version>
157+
<type>so</type>
158+
<scope>test</scope>
159+
</dependency>
160+
106161
</dependencies>
107162

108163
<build>
@@ -120,6 +175,25 @@
120175
<groupId>org.apache.maven.plugins</groupId>
121176
<artifactId>maven-war-plugin</artifactId>
122177
</plugin>
178+
<plugin>
179+
<groupId>org.apache.maven.plugins</groupId>
180+
<artifactId>maven-dependency-plugin</artifactId>
181+
<version>2.10</version>
182+
<executions>
183+
<execution>
184+
<id>copy-dependencies</id>
185+
<phase>test-compile</phase>
186+
<goals>
187+
<goal>copy-dependencies</goal>
188+
</goals>
189+
<configuration>
190+
<includeScope>test</includeScope>
191+
<includeTypes>so,dll,dylib</includeTypes>
192+
<outputDirectory>${project.basedir}/native-libs</outputDirectory>
193+
</configuration>
194+
</execution>
195+
</executions>
196+
</plugin>
123197

124198
</plugins>
125199

@@ -142,6 +216,11 @@
142216
<enabled>false</enabled>
143217
</snapshots>
144218
</repository>
219+
<repository>
220+
<id>dynamodb-local</id>
221+
<name>DynamoDB Local Release Repository</name>
222+
<url>${dynamodblocal.repository.url}</url>
223+
</repository>
145224
</repositories>
146225
<pluginRepositories>
147226
<pluginRepository>

‎persistence-modules/spring-data-dynamodb/src/test/java/com/baeldung/spring/data/dynamodb/repository/ProductInfoRepositoryIntegrationTest.java‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import com.baeldung.Application;
99
import com.baeldung.spring.data.dynamodb.model.ProductInfo;
1010
import com.baeldung.spring.data.dynamodb.repositories.ProductInfoRepository;
11+
import com.baeldung.spring.data.dynamodb.repository.rule.LocalDynamoDBCreationRule;
1112
import org.junit.Before;
12-
import org.junit.Ignore;
13+
import org.junit.ClassRule;
1314
import org.junit.Test;
1415
import org.junit.runner.RunWith;
1516
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +22,10 @@
2122

2223
import java.util.List;
2324

24-
import static org.junit.Assert.assertTrue;
25+
import static org.hamcrest.Matchers.greaterThan;
26+
import static org.hamcrest.core.Is.is;
27+
import static org.hamcrest.core.IsEqual.equalTo;
28+
import static org.junit.Assert.assertThat;
2529

2630
@RunWith(SpringJUnit4ClassRunner.class)
2731
@SpringBootTest(classes = Application.class)
@@ -30,6 +34,9 @@
3034
@TestPropertySource(properties = { "amazon.dynamodb.endpoint=http://localhost:8000/", "amazon.aws.accesskey=test1", "amazon.aws.secretkey=test231" })
3135
public class ProductInfoRepositoryIntegrationTest {
3236

37+
@ClassRule
38+
public static LocalDynamoDBCreationRule dynamoDB = new LocalDynamoDBCreationRule();
39+
3340
private DynamoDBMapper dynamoDBMapper;
3441

3542
@Autowired
@@ -42,7 +49,6 @@ public class ProductInfoRepositoryIntegrationTest {
4249
private static final String EXPECTED_PRICE = "50";
4350

4451
@Before
45-
@Ignore // TODO Remove Ignore annotations when running locally with Local DynamoDB instance
4652
public void setup() throws Exception {
4753

4854
try {
@@ -57,19 +63,18 @@ public void setup() throws Exception {
5763
// Do nothing, table already created
5864
}
5965

60-
// TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfoion table
66+
// TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table
6167
dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll());
6268
}
6369

6470
@Test
65-
@Ignore // TODO Remove Ignore annotations when running locally with Local DynamoDB instance
6671
public void givenItemWithExpectedCost_whenRunFindAll_thenItemIsFound() {
6772

6873
ProductInfo productInfo = new ProductInfo(EXPECTED_COST, EXPECTED_PRICE);
6974
repository.save(productInfo);
7075

7176
List<ProductInfo> result = (List<ProductInfo>) repository.findAll();
72-
assertTrue("Not empty", result.size() > 0);
73-
assertTrue("Contains item with expected cost", result.get(0).getCost().equals(EXPECTED_COST));
77+
assertThat(result.size(), is(greaterThan(0)));
78+
assertThat(result.get(0).getCost(), is(equalTo(EXPECTED_COST)));
7479
}
7580
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.spring.data.dynamodb.repository.rule;
2+
3+
import com.amazonaws.services.dynamodbv2.local.main.ServerRunner;
4+
import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer;
5+
import org.junit.rules.ExternalResource;
6+
7+
import java.util.Optional;
8+
9+
public class LocalDynamoDBCreationRule extends ExternalResource {
10+
11+
protected DynamoDBProxyServer server;
12+
13+
public LocalDynamoDBCreationRule() {
14+
System.setProperty("sqlite4java.library.path", "native-libs");
15+
}
16+
17+
@Override
18+
protected void before() throws Exception {
19+
String port = "8000";
20+
this.server = ServerRunner.createServerFromCommandLineArgs(new String[]{"-inMemory", "-port", port});
21+
server.start();
22+
}
23+
24+
@Override
25+
protected void after() {
26+
Optional.ofNullable(server).ifPresent(this::stopUnchecked);
27+
}
28+
29+
protected void stopUnchecked(DynamoDBProxyServer dynamoDbServer) {
30+
try {
31+
dynamoDbServer.stop();
32+
} catch (Exception e) {
33+
throw new RuntimeException(e);
34+
}
35+
}
36+
37+
}

0 commit comments

Comments
 (0)