Skip to content

Commit 7fe9cc6

Browse files
Patouchewhummer
authored andcommitted
Migrate logic code out from runner to be able to integrate junit 5
1 parent abf1ff1 commit 7fe9cc6

20 files changed

Lines changed: 932 additions & 753 deletions

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ See the example test file `tests/test_integration.py` for more details.
233233

234234
## Integration with Java/JUnit
235235

236-
In order to use *LocalStack* with Java, the project ships with a simple JUnit runner. Take a look
236+
In order to use *LocalStack* with Java, the project ships with a simple JUnit runner and a JUnit 5 extension. Take a look
237237
at the example JUnit test in `ext/java`. When you run the test, all dependencies are automatically
238238
downloaded and installed to a temporary directory in your system.
239239

@@ -255,6 +255,15 @@ public class MyCloudAppTest {
255255
}
256256
```
257257

258+
Or with JUnit 5 :
259+
260+
```
261+
@ExtendWith(LocalstackExtension.class)
262+
public class MyCloudAppTest {
263+
...
264+
}
265+
```
266+
258267
Additionally, there is a version of the *LocalStack* Test Runner which runs in a docker container
259268
instead of installing *LocalStack* on the current machine. The only dependency is to have docker
260269
installed locally. The test runner will automatically pull the image and start the container for the
@@ -273,6 +282,16 @@ public class MyDockerCloudAppTest {
273282
...
274283
```
275284

285+
Or with JUnit 5 :
286+
287+
```
288+
@ExtendWith(LocalstackDockerExtension.class)
289+
@LocalstackDockerProperties(randomizePorts = true, services = { "sqs", "kinesis:77077" })
290+
public class MyDockerCloudAppTest {
291+
...
292+
}
293+
```
294+
276295
The *LocalStack* JUnit test runner is published as an artifact in Maven Central.
277296
Simply add the following dependency to your `pom.xml` file:
278297

localstack/ext/java/pom.xml

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>cloud.localstack</groupId>
66
<artifactId>localstack-utils</artifactId>
77
<packaging>jar</packaging>
8-
<version>0.1.13</version>
8+
<version>0.1.14</version>
99
<name>localstack-utils</name>
1010

1111
<description>Java utilities for the LocalStack platform.</description>
@@ -27,6 +27,8 @@
2727
</scm>
2828

2929
<properties>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3032
<maven.compiler.source>1.8</maven.compiler.source>
3133
<maven.compiler.target>1.8</maven.compiler.target>
3234
</properties>
@@ -36,6 +38,19 @@
3638
<groupId>junit</groupId>
3739
<artifactId>junit</artifactId>
3840
<version>4.12</version>
41+
<optional>true</optional>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-api</artifactId>
46+
<version>5.1.0</version>
47+
<optional>true</optional>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter-engine</artifactId>
52+
<version>5.1.0</version>
53+
<optional>true</optional>
3954
</dependency>
4055
<dependency>
4156
<groupId>org.apache.commons</groupId>
@@ -56,7 +71,8 @@
5671
<dependency>
5772
<groupId>org.projectlombok</groupId>
5873
<artifactId>lombok</artifactId>
59-
<version>1.16.12</version>
74+
<version>1.16.20</version>
75+
<scope>provided</scope>
6076
</dependency>
6177
<dependency>
6278
<groupId>com.amazonaws</groupId>
@@ -100,17 +116,23 @@
100116
<version>1.0.13</version>
101117
<scope>test</scope>
102118
</dependency>
119+
<dependency>
120+
<groupId>org.assertj</groupId>
121+
<artifactId>assertj-core</artifactId>
122+
<version>3.9.0</version>
123+
<scope>test</scope>
124+
</dependency>
103125
</dependencies>
104126

105127
<profiles>
106128
<profile>
107129
<id>fatjar</id>
108130
<dependencies>
109-
<dependency>
110-
<groupId>com.amazonaws</groupId>
111-
<artifactId>aws-java-sdk</artifactId>
112-
<version>1.11.313</version>
113-
</dependency>
131+
<dependency>
132+
<groupId>com.amazonaws</groupId>
133+
<artifactId>aws-java-sdk</artifactId>
134+
<version>1.11.313</version>
135+
</dependency>
114136
</dependencies>
115137
</profile>
116138
</profiles>
@@ -133,7 +155,7 @@
133155
<plugin>
134156
<groupId>org.apache.maven.plugins</groupId>
135157
<artifactId>maven-shade-plugin</artifactId>
136-
<version>3.0.0</version>
158+
<version>3.1.1</version>
137159
<executions>
138160
<execution>
139161
<phase>package</phase>
@@ -156,8 +178,10 @@
156178
<include>com.amazonaws:aws-lambda-java-core</include>
157179
<include>commons-*:*</include>
158180
<include>net.*:*</include>
159-
<include>org.*:*</include>
160-
<include>junit:junit</include>
181+
<include>org.apache.*:*</include>
182+
<include>org.jvnet.*:*</include>
183+
<include>org.apiguardian:*</include>
184+
<include>org.opentest4j:*</include>
161185
<include>com.fasterxml.*:*</include>
162186
<include>joda-time:*</include>
163187
<include>com.jayway.*:*</include>
@@ -232,6 +256,23 @@
232256
<autoReleaseAfterClose>true</autoReleaseAfterClose>
233257
</configuration>
234258
</plugin>
259+
<plugin>
260+
<groupId>org.apache.maven.plugins</groupId>
261+
<artifactId>maven-surefire-plugin</artifactId>
262+
<version>2.21.0</version>
263+
<dependencies>
264+
<dependency>
265+
<groupId>org.apache.maven.surefire</groupId>
266+
<artifactId>surefire-junit4</artifactId>
267+
<version>2.21.0</version>
268+
</dependency>
269+
<dependency>
270+
<groupId>org.junit.platform</groupId>
271+
<artifactId>junit-platform-surefire-provider</artifactId>
272+
<version>1.2.0</version>
273+
</dependency>
274+
</dependencies>
275+
</plugin>
235276
</plugins>
236277
</build>
237278

localstack/ext/java/src/main/java/cloud/localstack/DockerTestUtils.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.function.Supplier;
77

8+
import cloud.localstack.docker.LocalstackDocker;
89
import com.amazonaws.client.builder.AwsClientBuilder;
910
import com.amazonaws.services.cloudformation.AmazonCloudFormation;
1011
import com.amazonaws.services.cloudformation.AmazonCloudFormationClientBuilder;
@@ -31,70 +32,68 @@
3132

3233
public class DockerTestUtils {
3334

34-
3535
public static AmazonSQS getClientSQS() {
3636
return AmazonSQSClientBuilder.standard().
37-
withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointSQS)).
37+
withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointSQS)).
3838
withCredentials(getCredentialsProvider()).build();
3939
}
4040

4141
public static AmazonSNS getClientSNS() {
4242
return AmazonSNSClientBuilder.standard()
43-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointSNS))
43+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointSNS))
4444
.withCredentials(getCredentialsProvider()).build();
4545
}
4646

4747
public static AWSLambda getClientLambda() {
4848
return AWSLambdaClientBuilder.standard().
49-
withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointLambda)).
49+
withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointLambda)).
5050
withCredentials(getCredentialsProvider()).build();
5151
}
5252

5353
public static AmazonS3 getClientS3() {
5454
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard()
55-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointS3))
55+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointS3))
5656
.withCredentials(getCredentialsProvider());
5757
builder.setPathStyleAccessEnabled(true);
5858
return builder.build();
5959
}
6060

6161
public static AmazonKinesis getClientKinesis() {
6262
return AmazonKinesisClientBuilder.standard()
63-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointKinesis))
63+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointKinesis))
6464
.withCredentials(getCredentialsProvider()).build();
6565
}
6666

6767
public static AmazonDynamoDB getClientDynamoDb() {
6868
return AmazonDynamoDBClientBuilder.standard()
69-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointDynamoDB))
69+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointDynamoDB))
7070
.withCredentials(getCredentialsProvider()).build();
7171
}
7272

7373
public static AmazonCloudWatch getClientCloudWatch() {
7474
return AmazonCloudWatchClientBuilder.standard()
75-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointCloudWatch))
75+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointCloudWatch))
7676
.withCredentials(getCredentialsProvider()).build();
7777
}
7878

7979
public static AmazonKinesisFirehose getClientFirehose() {
8080
return AmazonKinesisFirehoseClientBuilder.standard()
81-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointFirehose))
81+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointFirehose))
8282
.withCredentials(getCredentialsProvider()).build();
8383
}
8484

8585
public static AmazonDynamoDBStreams getClientDynamoDbStreams() {
8686
return AmazonDynamoDBStreamsClientBuilder.standard()
87-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointDynamoDBStreams))
87+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointDynamoDBStreams))
8888
.withCredentials(getCredentialsProvider()).build();
8989
}
9090

9191
public static AmazonCloudFormation getClientCloudFormation() {
9292
return AmazonCloudFormationClientBuilder.standard()
93-
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDockerTestRunner.getLocalstackDocker()::getEndpointCloudFormation))
93+
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointCloudFormation))
9494
.withCredentials(getCredentialsProvider()).build();
9595
}
9696

97-
9897
private static AwsClientBuilder.EndpointConfiguration createEndpointConfiguration(Supplier<String> supplier) {
9998
return getEndpointConfiguration(supplier.get());
10099
}

localstack/ext/java/src/main/java/cloud/localstack/LambdaExecutor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import com.fasterxml.jackson.databind.ObjectMapper;
1414
import org.apache.commons.lang3.StringUtils;
1515
import org.joda.time.DateTime;
16-
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
1716

1817
import java.io.ByteArrayOutputStream;
1918
import java.io.OutputStream;
2019
import java.lang.reflect.InvocationTargetException;
20+
import java.lang.reflect.ParameterizedType;
2121
import java.lang.reflect.Type;
2222
import java.nio.ByteBuffer;
2323
import java.nio.charset.StandardCharsets;
@@ -119,10 +119,10 @@ private static Optional<Object> getInputObject(ObjectMapper mapper, String objec
119119
try {
120120
Optional<Type> handlerInterface = Arrays.stream(handler.getClass().getGenericInterfaces())
121121
.filter(genericInterface ->
122-
((ParameterizedTypeImpl) genericInterface).getRawType().equals(RequestHandler.class))
122+
((ParameterizedType) genericInterface).getRawType().equals(RequestHandler.class))
123123
.findFirst();
124124
if (handlerInterface.isPresent()) {
125-
Class<?> handlerInputType = Class.forName(((ParameterizedTypeImpl) handlerInterface.get())
125+
Class<?> handlerInputType = Class.forName(((ParameterizedType) handlerInterface.get())
126126
.getActualTypeArguments()[0].getTypeName());
127127
inputObject = Optional.of(mapper.readerFor(handlerInputType).readValue(objectString));
128128
}

0 commit comments

Comments
 (0)