Skip to content

Commit 34fcdfd

Browse files
tech(idempotency): Replace DynamoDB Local with Mockito mocks in unit tests (#1932) (#2489)
* tech(idempotency): Replace DynamoDB Local with Mockito mocks in unit tests (#1932) Replaced external DynamoDB Local dependency with self-contained Mockito mocks in powertools-idempotency-dynamodb module unit tests. Changes: - Rewrote DynamoDBPersistenceStoreTest with 12 Mockito-based tests - Removed DynamoDB Local dependency and Maven plugins from pom.xml - Deleted DynamoDBConfig test harness (no longer needed) - Deleted IdempotencyTest and IdempotencyFunction (redundant with e2e tests) - Added Mockito dependencies to pom.xml All tests pass (13/13). No production code changes. E2E tests remain unchanged. Related to #1932 * Fix SonarCloud restricted identifier warnings - Rename variable 'record' to 'dataRecord' (9 occurrences) - Resolves Java keyword conflict in test file * Use mockito-subclass for GraalVM native tests - Add mockito-subclass dependency in native profile - Remove skipNativeTests flag - Follows pattern from powertools-metrics module - All 61 tests pass in idempotency parent module * Strengthen test assertions for condition expression and returnValuesOnConditionCheckFailure - Add full condition expression validation in putRecord_shouldSendCorrectPutItemRequest - Add returnValuesOnConditionCheckFailure='ALL_OLD' assertion - Protects bugfix from #1285 and behavior from #1821 - Per code review feedback from @phipag
1 parent 931a1b0 commit 34fcdfd

5 files changed

Lines changed: 278 additions & 541 deletions

File tree

powertools-idempotency/powertools-idempotency-dynamodb/pom.xml

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@
7777
<artifactId>junit-jupiter-engine</artifactId>
7878
<scope>test</scope>
7979
</dependency>
80+
<dependency>
81+
<groupId>org.mockito</groupId>
82+
<artifactId>mockito-core</artifactId>
83+
<scope>test</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.mockito</groupId>
87+
<artifactId>mockito-junit-jupiter</artifactId>
88+
<scope>test</scope>
89+
</dependency>
8090
<dependency>
8191
<groupId>org.slf4j</groupId>
8292
<artifactId>slf4j-simple</artifactId>
@@ -89,15 +99,6 @@
8999
<type>test-jar</type>
90100
<scope>test</scope>
91101
</dependency>
92-
<!-- DynamoDB Local for testing -->
93-
<dependency>
94-
<groupId>com.amazonaws</groupId>
95-
<artifactId>DynamoDBLocal</artifactId>
96-
<!-- >2.2.0 is not compatible with Java 11 anymore -->
97-
<!-- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocalHistory.html -->
98-
<version>2.2.0</version>
99-
<scope>test</scope>
100-
</dependency>
101102
<dependency>
102103
<groupId>software.amazon.awssdk</groupId>
103104
<artifactId>s3</artifactId>
@@ -118,6 +119,11 @@
118119
<artifactId>aws-xray-recorder-sdk-aws-sdk-v2-instrumentor</artifactId>
119120
<scope>test</scope>
120121
</dependency>
122+
<dependency>
123+
<groupId>org.mockito</groupId>
124+
<artifactId>mockito-subclass</artifactId>
125+
<scope>test</scope>
126+
</dependency>
121127
</dependencies>
122128
<build>
123129
<plugins>
@@ -149,57 +155,6 @@
149155

150156
<build>
151157
<plugins>
152-
<!-- Copy DynamoDB Local JAR -->
153-
<plugin>
154-
<groupId>org.apache.maven.plugins</groupId>
155-
<artifactId>maven-dependency-plugin</artifactId>
156-
<executions>
157-
<execution>
158-
<id>copy-dynamodb-local</id>
159-
<phase>generate-test-resources</phase>
160-
<goals>
161-
<goal>copy-dependencies</goal>
162-
</goals>
163-
<configuration>
164-
<includeScope>test</includeScope>
165-
<excludeTransitive>false</excludeTransitive>
166-
<!-- MDEP-187: Avoids Maven phase circular dependency by not trying to copy unpacked reactor
167-
artifacts (powertools-idempotency-core) -->
168-
<excludeGroupIds>software.amazon.lambda</excludeGroupIds>
169-
<outputDirectory>${project.build.directory}/dynamodb-local</outputDirectory>
170-
</configuration>
171-
</execution>
172-
</executions>
173-
</plugin>
174-
<!-- Start DynamoDB Local before tests -->
175-
<plugin>
176-
<groupId>org.codehaus.mojo</groupId>
177-
<artifactId>exec-maven-plugin</artifactId>
178-
<executions>
179-
<execution>
180-
<id>start-dynamodb-local</id>
181-
<phase>process-test-classes</phase>
182-
<goals>
183-
<goal>exec</goal>
184-
</goals>
185-
<configuration>
186-
<executable>java</executable>
187-
<workingDirectory>${project.build.directory}/dynamodb-local</workingDirectory>
188-
<arguments>
189-
<argument>-Djava.library.path=${project.build.directory}/dynamodb-local</argument>
190-
<argument>-cp</argument>
191-
<argument>${project.build.directory}/dynamodb-local/*</argument>
192-
<argument>com.amazonaws.services.dynamodbv2.local.main.ServerRunner</argument>
193-
<argument>-inMemory</argument>
194-
<argument>-port</argument>
195-
<argument>8000</argument>
196-
</arguments>
197-
<async>true</async>
198-
<asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
199-
</configuration>
200-
</execution>
201-
</executions>
202-
</plugin>
203158
<plugin>
204159
<groupId>org.apache.maven.plugins</groupId>
205160
<artifactId>maven-jar-plugin</artifactId>
@@ -212,16 +167,6 @@
212167
</archive>
213168
</configuration>
214169
</plugin>
215-
<!-- Configure Surefire to expose external DynamoDB Local address -->
216-
<plugin>
217-
<groupId>org.apache.maven.plugins</groupId>
218-
<artifactId>maven-surefire-plugin</artifactId>
219-
<configuration>
220-
<systemPropertyVariables>
221-
<dynamodb.endpoint>http://localhost:8000</dynamodb.endpoint>
222-
</systemPropertyVariables>
223-
</configuration>
224-
</plugin>
225170
<plugin>
226171
<groupId>dev.aspectj</groupId>
227172
<artifactId>aspectj-maven-plugin</artifactId>

powertools-idempotency/powertools-idempotency-dynamodb/src/test/java/software/amazon/lambda/powertools/idempotency/persistence/dynamodb/DynamoDBConfig.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)