Class S3MockRule
- java.lang.Object
-
- org.junit.rules.ExternalResource
-
- org.sdase.commons.server.s3.testing.S3MockRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public class S3MockRule extends org.junit.rules.ExternalResource
JUnit Test rule for running a AWS S3-compatible object storage alongside the (integration) tests. UsegetEndpoint()
to retrieve the endpoint URL to connect to.Example usage:
@ClassRule public static final S3MockRule S3_MOCK = S3MockRule.builder().build();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
S3MockRule.Builder
-
Constructor Summary
Constructors Constructor Description S3MockRule(java.util.List<java.lang.String> buckets, java.util.List<MockObject> mockObjects)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
after()
protected void
before()
static S3MockRule.Builder
builder()
com.amazonaws.services.s3.AmazonS3
getClient()
Creates a client to manipulate the object storage during tests.java.lang.String
getEndpoint()
Returns the URL to the S3 Mock endpoint.int
getPort()
Returns the port where to S3 Mock is listening on.void
resetAll()
Clears all buckets and objects from the store.
-
-
-
Constructor Detail
-
S3MockRule
public S3MockRule(java.util.List<java.lang.String> buckets, java.util.List<MockObject> mockObjects)
-
-
Method Detail
-
before
protected void before()
- Overrides:
before
in classorg.junit.rules.ExternalResource
-
after
protected void after()
- Overrides:
after
in classorg.junit.rules.ExternalResource
-
getEndpoint
public java.lang.String getEndpoint()
Returns the URL to the S3 Mock endpoint.- Returns:
- A full URL containing scheme, host and port.
-
getPort
public int getPort()
Returns the port where to S3 Mock is listening on.- Returns:
- The random port.
-
resetAll
public void resetAll()
Clears all buckets and objects from the store. Afterwards restores all buckets and object specified during creation.
-
getClient
public com.amazonaws.services.s3.AmazonS3 getClient()
Creates a client to manipulate the object storage during tests.- Returns:
- get the client from the AWS SDK
-
builder
public static S3MockRule.Builder builder()
-
-