This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit bb623523c0f41caa70f9615a8d6372a351d5348f
Author: Gautier DI FOLCO <gdifo...@linagora.com>
AuthorDate: Fri Feb 22 18:00:51 2019 +0100

    JAMES-2669 Add Aws S3 BlobStore configuration
---
 .../aws/AwsS3ObjectStorageConfiguration.java       | 112 ------------------
 .../guice/blob-objectstorage-guice/pom.xml         |   5 +
 .../ObjectStorageBlobConfiguration.java            |  13 ++-
 .../ObjectStorageDependenciesModule.java           |   5 +-
 .../objectstorage/ObjectStorageProvider.java       |   3 +-
 .../aws/s3/AwsS3AuthConfiguration.java             | 125 +++++++++++++++++++++
 .../s3/AwsS3ConfigurationReader.java}              |  28 +++--
 .../ObjectStorageBlobConfigurationTest.java        |  13 +++
 .../objectstorage/ObjectStorageProviderTest.java   |  13 ++-
 .../aws/s3/AwsS3AuthConfigurationTest.java}        |  35 +++---
 .../aws/s3/AwsS3ConfigurationReaderTest.java       |  76 +++++++++++++
 .../objectstorage/swift/DockerSwiftTestRule.java   |   5 +-
 12 files changed, 284 insertions(+), 149 deletions(-)

diff --git 
a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfiguration.java
 
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfiguration.java
deleted file mode 100644
index 53c7e5b..0000000
--- 
a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfiguration.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.james.blob.objectstorage.aws;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-
-public class AwsS3ObjectStorageConfiguration {
-
-    public static Builder builder() {
-        return new Builder();
-    }
-
-    public static class Builder {
-
-        private String endpoint;
-        private String accessKeyId;
-        private String secretKey;
-
-        private Builder() {}
-
-        public Builder endpoint(String endpoint) {
-            this.endpoint = endpoint;
-            return this;
-        }
-
-        public Builder accessKeyId(String accessKeyId) {
-            this.accessKeyId = accessKeyId;
-            return this;
-        }
-
-        public Builder secretKey(String secretKey) {
-            this.secretKey = secretKey;
-            return this;
-        }
-
-        public AwsS3ObjectStorageConfiguration build() {
-            Preconditions.checkArgument(!Strings.isNullOrEmpty(endpoint), 
"'endpoint' is mandatory");
-            Preconditions.checkArgument(!Strings.isNullOrEmpty(accessKeyId), 
"'accessKeyId' is mandatory");
-            Preconditions.checkArgument(!Strings.isNullOrEmpty(secretKey), 
"'secretKey' is mandatory");
-            return new AwsS3ObjectStorageConfiguration(endpoint, accessKeyId, 
secretKey);
-        }
-    }
-
-    private final String endpoint;
-    private final String accessKeyId;
-    private final String secretKey;
-
-    private AwsS3ObjectStorageConfiguration(String endpoint,
-                          String accessKeyId,
-                          String secretKey) {
-        this.endpoint = endpoint;
-        this.accessKeyId = accessKeyId;
-        this.secretKey = secretKey;
-    }
-
-    public String getEndpoint() {
-        return endpoint;
-    }
-
-    public String getAccessKeyId() {
-        return accessKeyId;
-    }
-
-    public String getSecretKey() {
-        return secretKey;
-    }
-
-    @Override
-    public final boolean equals(Object o) {
-        if (o instanceof AwsS3ObjectStorageConfiguration) {
-            AwsS3ObjectStorageConfiguration that = 
(AwsS3ObjectStorageConfiguration) o;
-            return Objects.equal(endpoint, that.endpoint) &&
-                Objects.equal(accessKeyId, that.accessKeyId) &&
-                Objects.equal(secretKey, that.secretKey);
-        }
-        return false;
-    }
-
-    @Override
-    public final int hashCode() {
-        return Objects.hashCode(endpoint, accessKeyId, secretKey);
-    }
-
-    @Override
-    public final String toString() {
-        return MoreObjects.toStringHelper(this)
-            .add("endpoint", endpoint)
-            .add("accessKeyId", accessKeyId)
-            .add("secretKey", secretKey)
-            .toString();
-    }
-}
diff --git a/server/container/guice/blob-objectstorage-guice/pom.xml 
b/server/container/guice/blob-objectstorage-guice/pom.xml
index 53aba50..a44a535 100644
--- a/server/container/guice/blob-objectstorage-guice/pom.xml
+++ b/server/container/guice/blob-objectstorage-guice/pom.xml
@@ -66,6 +66,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>nl.jqno.equalsverifier</groupId>
+            <artifactId>equalsverifier</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <scope>test</scope>
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
index b36576f..e17da58 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfiguration.java
@@ -27,6 +27,7 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.blob.objectstorage.ContainerName;
 import org.apache.james.blob.objectstorage.PayloadCodec;
+import org.apache.james.modules.objectstorage.aws.s3.AwsS3ConfigurationReader;
 import org.apache.james.modules.objectstorage.swift.SwiftAuthConfiguration;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -69,12 +70,21 @@ public class ObjectStorageBlobConfiguration {
             .codec(payloadCodecFactory)
             .provider(ObjectStorageProvider.from(provider))
             .container(ContainerName.of(namespace))
-            
.authConfiguration(SwiftAuthConfiguration.defineAuthApi(configuration))
+            .authConfiguration(authConfiguration(provider, configuration))
             .aesSalt(aesSalt)
             .aesPassword(aesPassword)
             .build();
     }
 
+    private static SpecificAuthConfiguration authConfiguration(String 
provider, Configuration configuration) throws ConfigurationException {
+        switch (ObjectStorageProvider.from(provider)) {
+            case SWIFT:
+                return SwiftAuthConfiguration.defineAuthApi(configuration);
+            case AWSS3:
+                return 
AwsS3ConfigurationReader.readAwsS3Configuration(configuration);
+        }
+        throw new ConfigurationException("Unknown object storage provider: " + 
provider);
+    }
 
     public static Builder.RequirePayloadCodec builder() {
         return payloadCodec -> provider -> container -> authConfiguration -> 
new Builder.ReadyToBuild(payloadCodec, provider, container, authConfiguration);
@@ -107,6 +117,7 @@ public class ObjectStorageBlobConfiguration {
             private final ObjectStorageProvider provider;
             private final ContainerName container;
             private final SpecificAuthConfiguration specificAuthConfiguration;
+
             private Optional<String> aesSalt;
             private Optional<char[]> aesPassword;
 
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
index 3d63afd..a4acb21 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageDependenciesModule.java
@@ -71,7 +71,10 @@ public class ObjectStorageDependenciesModule extends 
AbstractModule {
     }
 
     private ObjectStorageBlobsDAOBuilder.RequireContainerName 
selectDaoBuilder(ObjectStorageBlobConfiguration configuration) {
-        return SwiftObjectStorage.builder(configuration);
+        if (configuration.getProvider() == ObjectStorageProvider.SWIFT) {
+            return SwiftObjectStorage.builder(configuration);
+        }
+        throw new IllegalArgumentException("unknown provider " + 
configuration.getProvider());
     }
 
 }
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageProvider.java
 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageProvider.java
index d89151d..a9c1cf6 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageProvider.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageProvider.java
@@ -24,7 +24,8 @@ import java.util.Arrays;
 import org.apache.commons.configuration.ConfigurationException;
 
 public enum ObjectStorageProvider {
-    SWIFT("swift");
+    SWIFT("swift"),
+    AWSS3("aws-s3");
 
     private final String name;
 
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3AuthConfiguration.java
 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3AuthConfiguration.java
new file mode 100644
index 0000000..2c9ee1c
--- /dev/null
+++ 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3AuthConfiguration.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.james.modules.objectstorage.aws.s3;
+
+import org.apache.james.modules.objectstorage.SpecificAuthConfiguration;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+public class AwsS3AuthConfiguration implements SpecificAuthConfiguration {
+
+    public static Builder.RequiredEndpoint builder() {
+        return endpoint -> accessKeyId -> secretKey -> new 
Builder.ReadyToBuild(endpoint, accessKeyId, secretKey);
+    }
+
+    public interface Builder {
+
+        @FunctionalInterface
+        interface RequiredEndpoint {
+            RequiredAccessKeyId endpoint(String endpoint);
+        }
+
+        @FunctionalInterface
+        interface RequiredAccessKeyId {
+            RequiredSecretKey accessKeyId(String accessKeyId);
+        }
+
+        @FunctionalInterface
+        interface RequiredSecretKey {
+            ReadyToBuild secretKey(String secretKey);
+        }
+
+        class ReadyToBuild {
+            private final String endpoint;
+            private final String accessKeyId;
+            private final String secretKey;
+
+            public ReadyToBuild(String endpoint, String accessKeyId, String 
secretKey) {
+                this.endpoint = endpoint;
+                this.accessKeyId = accessKeyId;
+                this.secretKey = secretKey;
+            }
+
+            public AwsS3AuthConfiguration build() {
+                Preconditions.checkNotNull(endpoint, "'endpoint' is 
mandatory");
+                Preconditions.checkArgument(!endpoint.isEmpty(), "'endpoint' 
is mandatory");
+
+                Preconditions.checkNotNull(accessKeyId, "'accessKeyId' is 
mandatory");
+                Preconditions.checkArgument(!accessKeyId.isEmpty(), 
"'accessKeyId' is mandatory");
+
+                Preconditions.checkNotNull(secretKey, "'secretKey' is 
mandatory");
+                Preconditions.checkArgument(!secretKey.isEmpty(), "'secretKey' 
is mandatory");
+
+                return new AwsS3AuthConfiguration(endpoint, accessKeyId, 
secretKey);
+            }
+        }
+    }
+
+    private final String endpoint;
+    private final String accessKeyId;
+    private final String secretKey;
+
+    private AwsS3AuthConfiguration(String endpoint,
+                                   String accessKeyId,
+                                   String secretKey) {
+        this.endpoint = endpoint;
+        this.accessKeyId = accessKeyId;
+        this.secretKey = secretKey;
+    }
+
+    public String getEndpoint() {
+        return endpoint;
+    }
+
+    public String getAccessKeyId() {
+        return accessKeyId;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof AwsS3AuthConfiguration) {
+            AwsS3AuthConfiguration that = (AwsS3AuthConfiguration) o;
+            return Objects.equal(endpoint, that.endpoint) &&
+                Objects.equal(accessKeyId, that.accessKeyId) &&
+                Objects.equal(secretKey, that.secretKey);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hashCode(endpoint, accessKeyId, secretKey);
+    }
+
+    @Override
+    public final String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("endpoint", endpoint)
+            .add("accessKeyId", accessKeyId)
+            .add("secretKey", secretKey)
+            .toString();
+    }
+}
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageProvider.java
 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3ConfigurationReader.java
similarity index 50%
copy from 
server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageProvider.java
copy to 
server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3ConfigurationReader.java
index d89151d..6f36c91 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageProvider.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3ConfigurationReader.java
@@ -17,25 +17,23 @@
  * under the License.
  */
 
-package org.apache.james.modules.objectstorage;
+package org.apache.james.modules.objectstorage.aws.s3;
 
-import java.util.Arrays;
+import org.apache.commons.configuration.Configuration;
 
-import org.apache.commons.configuration.ConfigurationException;
+public class AwsS3ConfigurationReader {
 
-public enum ObjectStorageProvider {
-    SWIFT("swift");
+    static final String OBJECTSTORAGE_ENDPOINT = "objectstorage.s3.endPoint";
+    static final String OBJECTSTORAGE_ACCESKEYID = 
"objectstorage.s3.accessKeyId";
+    static final String OBJECTSTORAGE_SECRETKEY = "objectstorage.s3.secretKey";
 
-    private final String name;
+    public static AwsS3AuthConfiguration readAwsS3Configuration(Configuration 
configuration) {
 
-    ObjectStorageProvider(String name) {
-        this.name = name;
-    }
-
-    public static ObjectStorageProvider from(String provider) throws 
ConfigurationException {
-        return Arrays.stream(values())
-            .filter(value -> value.name.equals(provider))
-            .findFirst()
-            .orElseThrow(() -> new ConfigurationException("Unknown object 
storage provider: " + provider));
+        return AwsS3AuthConfiguration.builder()
+                .endpoint(configuration.getString(OBJECTSTORAGE_ENDPOINT))
+                .accessKeyId(configuration.getString(OBJECTSTORAGE_ACCESKEYID))
+                .secretKey(configuration.getString(OBJECTSTORAGE_SECRETKEY))
+                .build();
     }
 }
+
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfigurationTest.java
 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfigurationTest.java
index 004b7bf..2396eae 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfigurationTest.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobConfigurationTest.java
@@ -157,4 +157,17 @@ class ObjectStorageBlobConfigurationTest {
         assertThatThrownBy(() -> 
ObjectStorageBlobConfiguration.from(configuration)).isInstanceOf(IllegalStateException.class);
     }
 
+    @Test
+    void shouldThrowWhenUnknownProvider() throws Exception {
+        MapConfiguration configuration = new MapConfiguration(
+            ImmutableMap.<String, Object>builder()
+                .put("objectstorage.payload.codec", 
PayloadCodecFactory.DEFAULT.name())
+                .put("objectstorage.provider", "unknown")
+                .put("objectstorage.namespace", "foo")
+                .build());
+
+        assertThatThrownBy(() -> 
ObjectStorageBlobConfiguration.from(configuration))
+            .isInstanceOf(ConfigurationException.class)
+            .hasMessage("Unknown object storage provider: unknown");
+    }
 }
\ No newline at end of file
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageProviderTest.java
 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageProviderTest.java
index 2899956..6fe0488 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageProviderTest.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageProviderTest.java
@@ -30,12 +30,19 @@ class ObjectStorageProviderTest {
     @Test
     void fromShouldThrowWhenUnkownObjectStorage() {
         assertThatThrownBy(() -> ObjectStorageProvider.from("unknown"))
-            .isInstanceOf(RuntimeException.class)
+            .isInstanceOf(ConfigurationException.class)
             .hasMessage("Unknown object storage provider: unknown");
     }
 
     @Test
-    void fromShouldReturnThenObjectStorage() throws ConfigurationException {
-        
assertThat(ObjectStorageProvider.from("swift")).isEqualTo(ObjectStorageProvider.SWIFT);
+    void fromShouldMatchSwift() throws ConfigurationException {
+        assertThat(ObjectStorageProvider.from("swift"))
+            .isEqualTo(ObjectStorageProvider.SWIFT);
+    }
+
+    @Test
+    void fromShouldMatchAwsS3() throws ConfigurationException {
+        assertThat(ObjectStorageProvider.from("aws-s3"))
+            .isEqualTo(ObjectStorageProvider.AWSS3);
     }
 }
\ No newline at end of file
diff --git 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfigurationTest.java
 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3AuthConfigurationTest.java
similarity index 71%
rename from 
server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfigurationTest.java
rename to 
server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3AuthConfigurationTest.java
index adf8f1f..445bcdd 100644
--- 
a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfigurationTest.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3AuthConfigurationTest.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.james.blob.objectstorage.aws;
+package org.apache.james.modules.objectstorage.aws.s3;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.SoftAssertions.assertSoftly;
@@ -26,25 +26,30 @@ import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class AwsS3ObjectStorageConfigurationTest {
+public class AwsS3AuthConfigurationTest {
 
     @Test
     public void credentialsShouldRespectBeanContract() {
-        
EqualsVerifier.forClass(AwsS3ObjectStorageConfiguration.class).verify();
+        EqualsVerifier.forClass(AwsS3AuthConfiguration.class).verify();
     }
 
     @Test
     public void builderShouldThrowWhenEndpointIsNull() {
-        assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder()
+        assertThatThrownBy(() -> AwsS3AuthConfiguration.builder()
+                                    .endpoint(null)
+                                    .accessKeyId("myAccessKeyId")
+                                    .secretKey("mySecretKey")
                                     .build())
-            .isInstanceOf(IllegalArgumentException.class)
+            .isInstanceOf(NullPointerException.class)
             .hasMessage("'endpoint' is mandatory");
     }
 
     @Test
     public void builderShouldThrowWhenEndpointIsEmpty() {
-        assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder()
+        assertThatThrownBy(() -> AwsS3AuthConfiguration.builder()
                                     .endpoint("")
+                                    .accessKeyId("myAccessKeyId")
+                                    .secretKey("mySecretKey")
                                     .build())
             .isInstanceOf(IllegalArgumentException.class)
             .hasMessage("'endpoint' is mandatory");
@@ -52,18 +57,21 @@ public class AwsS3ObjectStorageConfigurationTest {
 
     @Test
     public void builderShouldThrowWhenAccessKeyIdIsNull() {
-        assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder()
+        assertThatThrownBy(() -> AwsS3AuthConfiguration.builder()
                                     .endpoint("myEndpoint")
+                                    .accessKeyId(null)
+                                    .secretKey("mySecretKey")
                                     .build())
-            .isInstanceOf(IllegalArgumentException.class)
+            .isInstanceOf(NullPointerException.class)
             .hasMessage("'accessKeyId' is mandatory");
     }
 
     @Test
     public void builderShouldThrowWhenAccessKeyIdIsEmpty() {
-        assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder()
+        assertThatThrownBy(() -> AwsS3AuthConfiguration.builder()
                                     .endpoint("myEndpoint")
                                     .accessKeyId("")
+                                    .secretKey("mySecretKey")
                                     .build())
             .isInstanceOf(IllegalArgumentException.class)
             .hasMessage("'accessKeyId' is mandatory");
@@ -71,17 +79,18 @@ public class AwsS3ObjectStorageConfigurationTest {
 
     @Test
     public void builderShouldThrowWhenSecretKeyIsNull() {
-        assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder()
+        assertThatThrownBy(() -> AwsS3AuthConfiguration.builder()
                                     .endpoint("myEndpoint")
                                     .accessKeyId("myAccessKeyId")
+                                    .secretKey(null)
                                     .build())
-            .isInstanceOf(IllegalArgumentException.class)
+            .isInstanceOf(NullPointerException.class)
             .hasMessage("'secretKey' is mandatory");
     }
 
     @Test
     public void builderShouldThrowWhenSecretKeyIsEmpty() {
-        assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder()
+        assertThatThrownBy(() -> AwsS3AuthConfiguration.builder()
                                     .endpoint("myEndpoint")
                                     .accessKeyId("myAccessKeyId")
                                     .secretKey("")
@@ -95,7 +104,7 @@ public class AwsS3ObjectStorageConfigurationTest {
         String endpoint = "myEndpoint";
         String accessKeyId = "myAccessKeyId";
         String secretKey = "mySecretKey";
-        AwsS3ObjectStorageConfiguration configuration = 
AwsS3ObjectStorageConfiguration.builder()
+        AwsS3AuthConfiguration configuration = AwsS3AuthConfiguration.builder()
             .endpoint(endpoint)
             .accessKeyId(accessKeyId)
             .secretKey(secretKey)
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3ConfigurationReaderTest.java
 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3ConfigurationReaderTest.java
new file mode 100644
index 0000000..4f59cc3
--- /dev/null
+++ 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/AwsS3ConfigurationReaderTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.james.modules.objectstorage.aws.s3;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.jupiter.api.Test;
+
+class AwsS3ConfigurationReaderTest {
+
+    @Test
+    void fromShouldThrowWhenEndpointIsNull() {
+        Configuration configuration = new PropertiesConfiguration();
+        assertThatThrownBy(() -> AwsS3ConfigurationReader.from(configuration))
+            .isInstanceOf(NullPointerException.class)
+            .hasMessage("'endpoint' is mandatory");
+    }
+
+    @Test
+    void fromShouldThrowWhenAccessKeyIdIsNull() {
+        Configuration configuration = new PropertiesConfiguration();
+        
configuration.addProperty(AwsS3ConfigurationReader.OBJECTSTORAGE_ENDPOINT, 
"myEndpoint");
+        assertThatThrownBy(() -> AwsS3ConfigurationReader.from(configuration))
+            .isInstanceOf(NullPointerException.class)
+            .hasMessage("'accessKeyId' is mandatory");
+    }
+
+    @Test
+    void fromShouldThrowWhenSecretKeyIsNull() {
+        Configuration configuration = new PropertiesConfiguration();
+        
configuration.addProperty(AwsS3ConfigurationReader.OBJECTSTORAGE_ENDPOINT, 
"myEndpoint");
+        
configuration.addProperty(AwsS3ConfigurationReader.OBJECTSTORAGE_ACCESKEYID, 
"myAccessKeyId");
+        assertThatThrownBy(() -> AwsS3ConfigurationReader.from(configuration))
+            .isInstanceOf(NullPointerException.class)
+            .hasMessage("'secretKey' is mandatory");
+    }
+
+    @Test
+    void fromShouldWork() {
+        Configuration configuration = new PropertiesConfiguration();
+        String endpoint = "myEndpoint";
+        
configuration.addProperty(AwsS3ConfigurationReader.OBJECTSTORAGE_ENDPOINT, 
endpoint);
+        String accessKeyId = "myAccessKeyId";
+        
configuration.addProperty(AwsS3ConfigurationReader.OBJECTSTORAGE_ACCESKEYID, 
accessKeyId);
+        String secretKey = "mySecretKey";
+        
configuration.addProperty(AwsS3ConfigurationReader.OBJECTSTORAGE_SECRETKEY, 
secretKey);
+
+        AwsS3AuthConfiguration expected = AwsS3AuthConfiguration.builder()
+            .endpoint(endpoint)
+            .accessKeyId(accessKeyId)
+            .secretKey(secretKey)
+            .build();
+        AwsS3AuthConfiguration authConfiguration = 
AwsS3ConfigurationReader.from(configuration);
+        assertThat(authConfiguration).isEqualTo(expected);
+    }
+}
\ No newline at end of file
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/swift/DockerSwiftTestRule.java
 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/swift/DockerSwiftTestRule.java
index 76481c3..67a2a53 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/swift/DockerSwiftTestRule.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/swift/DockerSwiftTestRule.java
@@ -27,6 +27,7 @@ import javax.inject.Inject;
 import org.apache.james.CleanupTasksPerformer;
 import org.apache.james.GuiceModuleTestRule;
 import org.apache.james.blob.objectstorage.ContainerName;
+import org.apache.james.blob.objectstorage.DockerSwiftRule;
 import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
 import org.apache.james.blob.objectstorage.PayloadCodec;
 import org.apache.james.blob.objectstorage.swift.Credentials;
@@ -36,7 +37,6 @@ import org.apache.james.blob.objectstorage.swift.UserName;
 import org.apache.james.modules.objectstorage.ObjectStorageBlobConfiguration;
 import org.apache.james.modules.objectstorage.ObjectStorageProvider;
 import org.apache.james.modules.objectstorage.PayloadCodecFactory;
-import org.apache.james.modules.objectstorage.swift.SwiftAuthConfiguration;
 import org.apache.james.utils.GuiceProbe;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
@@ -78,8 +78,7 @@ public class DockerSwiftTestRule implements 
GuiceModuleTestRule {
     }
 
     private final PayloadCodecFactory payloadCodecFactory;
-    private org.apache.james.blob.objectstorage.DockerSwiftRule swiftContainer 
=
-        new org.apache.james.blob.objectstorage.DockerSwiftRule();
+    private DockerSwiftRule swiftContainer = new DockerSwiftRule();
 
     public DockerSwiftTestRule() {
         this(PayloadCodecFactory.DEFAULT);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to