Skip to content

Commit 8653bf2

Browse files
committed
Merge branch 'localstack-master' into master
* localstack-master: (27 commits) Added tests to show the exception on the SES client V2 release version v0.2.15 refactor logging config; fix Kinesis CBOR tests fix project setup and classpath for SDK v1/v2 utils fix awaiting results in tests using async clients adjust CI config to use new make targets; fix imports for SDK v1/v2 compatibility refactor classpath setup for v1/v2 SDKs; fall back to using edge port if port mapping cannot be determined from container add ability to get handler class name through "_HANDLER" environment variable like in real AWS (localstack#67) implement empty methods in `LambdaContext` (localstack#66) release version 0.2.13 increate number of scanned log lines to 100 when searching for "Ready." token (localstack#64) consider Windows EOL when listing images (localstack#65) release version 0.2.11 fix endpoint URL for getClientLambdaAsyncV2 (localstack#60) add simple tests for IAM service (localstack#62) read port config file in multiple locations for different Python versions in the container (localstack#59) Bump logback-classic from 1.0.13 to 1.2.0 (localstack#56) log which image is being pulled (localstack#58) Bump commons-io from 2.6 to 2.7 (localstack#53) add simple test for KMS (localstack#54) ...
2 parents eb24ff8 + b08c5dc commit 8653bf2

File tree

72 files changed

+1817
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1817
-383
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ hs_err_pid*
2929
.classpath
3030
.settings
3131
.project
32+
33+
.vscode

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ install:
1515

1616
script:
1717
- set -e
18-
- mvn -q -DskipTests test
19-
- docker pull localstack/localstack-light > /dev/null
20-
- docker tag localstack/localstack-light localstack/localstack
18+
- nohup docker pull localstack/localstack > /dev/null &
19+
- make compile
20+
- MVN_TEST_ARGS="-q -DskipTests" make test
2121
- make test
2222
- docker ps -a
2323

Makefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ usage: ## Show this help
66
build: ## Build the code using Maven
77
mvn -Pfatjar $(ADDITIONAL_MVN_ARGS) clean javadoc:jar source:jar package $(ADDITIONAL_MVN_TARGETS)
88

9+
compile:
10+
mvn -Pawssdkv1,awssdkv2 $(ADDITIONAL_MVN_ARGS) -DskipTests compile test-compile
11+
912
publish-maven: ## Publish artifacts to Maven Central
10-
ADDITIONAL_MVN_TARGETS=deploy ADDITIONAL_MVN_ARGS=" " make build
13+
ADDITIONAL_MVN_TARGETS=deploy ADDITIONAL_MVN_ARGS="-DskipTests -Pawssdkv1,awssdkv2" make build
1114

1215
test-v1:
13-
USE_SSL=1 SERVICES=serverless,kinesis,sns,sqs,iam,cloudwatch mvn -Pawssdkv1 \
14-
-Dtest="!cloud.localstack.awssdkv2.*Test" test
16+
USE_SSL=1 SERVICES=serverless,kinesis,sns,sqs,iam,cloudwatch mvn $(MVN_TEST_ARGS) -Pawssdkv1 \
17+
-Dtest="cloud.localstack.awssdkv1.*Test" test
1518

1619
test-v2:
17-
USE_SSL=1 SERVICES=serverless,kinesis,sns,sqs,iam,cloudwatch mvn -Pawssdkv2 \
20+
USE_SSL=1 SERVICES=serverless,kinesis,sns,sqs,iam,cloudwatch mvn $(MVN_TEST_ARGS) -Pawssdkv2 \
1821
-Dtest="cloud.localstack.awssdkv2.*Test" test
1922

2023
test: ## Run Java/JUnit tests for AWS SDK v1 and v2

README.md

+66-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
[![Build Status](https://travis-ci.org/localstack/localstack-java-utils.svg)](https://travis-ci.org/localstack/localstack-java-utils)
1+
[![Build Status](https://travis-ci.com/localstack/localstack-java-utils.svg)](https://travis-ci.com/localstack/localstack-java-utils)
2+
[![Maven Central](https://img.shields.io/maven-central/v/cloud.localstack/localstack-utils)](https://mvnrepository.com/artifact/cloud.localstack/localstack-utils)
23

34
# LocalStack Java Utils
45

@@ -19,7 +20,7 @@ extension. Take a look at the example JUnit tests in `src/test/java`.
1920
By default, the JUnit Test Runner starts LocalStack in a Docker container, for the duration of the test.
2021
The container can be configured by using the `@LocalstackDockerProperties` annotation.
2122

22-
```
23+
```java
2324
...
2425
import cloud.localstack.LocalstackTestRunner;
2526
import cloud.localstack.ServiceName;
@@ -42,7 +43,7 @@ public class MyCloudAppTest {
4243

4344
Or with JUnit 5:
4445

45-
```
46+
```java
4647
@ExtendWith(LocalstackDockerExtension.class)
4748
@LocalstackDockerProperties(...)
4849
public class MyCloudAppTest {
@@ -55,11 +56,11 @@ public class MyCloudAppTest {
5556
The LocalStack JUnit test runner is published as an artifact in Maven Central.
5657
Simply add the following dependency to your `pom.xml` file:
5758

58-
```
59+
```xml
5960
<dependency>
6061
<groupId>cloud.localstack</groupId>
6162
<artifactId>localstack-utils</artifactId>
62-
<version>0.2.7</version>
63+
<version>0.2.15</version>
6364
</dependency>
6465
```
6566

@@ -76,8 +77,10 @@ You can configure the Docker behaviour using the `@LocalstackDockerProperties` a
7677
| `portEdge` | Port number for the edge service, the main entry point for all API invocations | String | `4566` |
7778
| `portElasticSearch` | Port number for the elasticsearch service | String | `4571` |
7879
| `hostNameResolver` | Used for determining the host name of the machine running the docker containers so that the containers can be addressed. | IHostNameResolver | `localhost` |
79-
| `environmentVariableProvider` | Used for injecting environment variables into the container. | IEnvironmentVariableProvider | Empty Map |
80-
| `useSingleDockerContainer` | Whether a singleton container should be used by all test classes. | boolean | `false` |
80+
| `environmentVariableProvider` | Used for injecting environment variables into the container. | IEnvironmentVariableProvider | Empty Map |
81+
| `bindMountProvider` | Used bind mounting files and directories into the container, useful to run init scripts before using the container. | IBindMountProvider | Empty Map |
82+
| `initializationToken` | Give a regex that will be searched in the logstream of the container, start is complete only when the token is found. Use with bindMountProvider to execute init scripts. | String | Empty String |
83+
| `useSingleDockerContainer` | Whether a singleton container should be used by all test classes. | boolean | `false` |
8184

8285
For more details, please refer to the README of the main LocalStack repo: https://github.com/localstack/localstack
8386

@@ -98,19 +101,74 @@ _Note: When specifying the port in the `services` property, you cannot use `rand
98101
## Building
99102

100103
To build the latest version of the code via Maven:
101-
```
104+
105+
```sh
102106
make build
103107
```
104108

105109
## Change Log
106110

111+
* v0.2.15: Fix Kinesis CBOR tests; fix project setup and classpath for SDK v1/v2 utils; fix awaiting results in tests using async clients; refactor classpath setup for v1/v2 SDKs; fall back to using edge port if port mapping cannot be determined from container
112+
* v0.2.14: Add ability to get handler class name through `_HANDLER` environment variable like on real AWS and Lambci environment
113+
* v0.2.11: Enable specification of "platform" when configuring container
114+
* v0.2.10: Add Lambda async utils for AWS SDK v2; add support for specifying bind mounts and init scripts via `@LocalstackDockerProperties`; add PowerMock integration for easy patching of AWS SDK to use local endpoints; add support for configuring the Docker image name via `@LocalstackDockerProperties`; add tests for templated emails
115+
* v0.2.8: Allow overwriting the port binding via environment variables
107116
* v0.2.7: Extend `@LocalstackDockerProperties` to include port binding
108117
* v0.2.6: Add new path to possible docker exe locations in Windows; add various additional tests for v1 and v2 SDKs (Kinesis, SQS, SSM & SecretsManager, ...)
109118
* v0.2.5: Refactor code to accommodate edge port config for all services; add CloudWatch Logs endpoint configuration
110119
* v0.2.2: Addition of CloudWatch Logs endpoint configuration; adjust tests to use central edge service endpoint
111120
* v0.2.1: Move Java sources into separate project; mark non-Docker Java `LocalstackExtension` as deprecated; update paths for Python code lookup in Docker container
112121
* v0.2.0: Last version still maintained in LocalStack main repo
113122

123+
## PowerMock
124+
125+
You can use the PowerMock Library to call the builders default method and still get LocalStack version of the AWS clients.
126+
127+
```java
128+
...
129+
@RunWith(PowerMockRunner.class)
130+
@PowerMockRunnerDelegate(LocalstackTestRunner.class)
131+
@LocalstackDockerProperties(services = { "ses" })
132+
@PrepareForTest({ AmazonSimpleEmailServiceClientBuilder.class, AmazonSimpleEmailServiceAsyncClientBuilder.class })
133+
@PowerMockIgnore({"javax.crypto.*", "org.hamcrest.*", "javax.net.ssl.*", "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*", "javax.security.*", "org.w3c.*"})
134+
public class SESMessagingTest {
135+
....
136+
@Before
137+
public void mockSES() {
138+
AmazonSimpleEmailService mockSes = TestUtils.getClientSES();
139+
PowerMockito.mockStatic(AmazonSimpleEmailServiceClientBuilder.class);
140+
when(AmazonSimpleEmailServiceClientBuilder.defaultClient()).thenReturn(mockSes);
141+
}
142+
@Test
143+
public void testSendEmail() throws Exception {
144+
AmazonSimpleEmailService client = amazonSimpleEmailServiceClientBuilder.defaultClient();
145+
....
146+
```
147+
148+
## PowerMockLocalStack Utility
149+
150+
This utility makes easier to use PowerMock with Localstack.
151+
152+
```java
153+
...
154+
public class PowerMockLocalStackExampleTest extends PowerMockLocalStack{
155+
private static final String TOPIC = "topic";
156+
@Before
157+
public void mock() {
158+
PowerMockLocalStack.mockSNS();
159+
}
160+
161+
@Test
162+
public void testSendMessage() throws JMSException {
163+
final AmazonSNS clientSNS = AmazonSNSClientBuilder.defaultClient();
164+
...
165+
}
166+
}
167+
```
168+
169+
## Acknowledgements
170+
I thank you [Keith Humphreys](https://gitlab.com/keithh), for showing us how to empower LocalStack with PowerMock to write tests even easier.
171+
114172
## License
115173

116174
This code is released under the Apache License, Version 2.0 (see LICENSE.txt).

0 commit comments

Comments
 (0)