SDA Commons Server S3 Testing¶
This is accomplished using local-s3, which provides an in memory object storage.
Usage¶
To use the test extension, a dependency to this module has to be added:
1 |
|
JUnit 5¶
This module provides the S3ClassExtension
,
a JUnit 5 extension that is used to automatically bootstrap an AWS S3-compatible object storage instance
for integration tests.
To create a S3 Mock instance, annotate your test class with @LocalS3
and register the S3 test extension in your test class:
1 2 3 4 5 6 7 8 9 |
|
The extension takes care to choose a free port for the endpoint. You can access the
URL using S3.getEndpoint()
.
Often one needs to pass the endpoint URL to the constructor of another extension:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
In case you need a pre-populated bucket in your tests, you might add files while building the extension.
You can call S3.resetAll()
to restore this state at any time. If you need to perform additional
operations on the object storage S3.getClient()
provides a full S3 storage client.
1 2 3 4 5 6 7 8 9 |
|