Class 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. Use getEndpoint() 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.
      • Methods inherited from class org.junit.rules.ExternalResource

        apply
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 class org.junit.rules.ExternalResource
      • after

        protected void after()
        Overrides:
        after in class org.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