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 24446f401363d9b675793fe0f0f8fafdc6b4572f Author: Antoine Duprat <adup...@linagora.com> AuthorDate: Mon Feb 25 11:46:37 2019 +0100 JAMES-2669 Introduce basic AWS S3 configuration object --- .../aws/AwsS3ObjectStorageConfiguration.java | 112 +++++++++++++++++++++ .../aws/AwsS3ObjectStorageConfigurationTest.java | 110 ++++++++++++++++++++ 2 files changed, 222 insertions(+) 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 new file mode 100644 index 0000000..53c7e5b --- /dev/null +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfiguration.java @@ -0,0 +1,112 @@ +/* + * 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/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfigurationTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfigurationTest.java new file mode 100644 index 0000000..adf8f1f --- /dev/null +++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorageConfigurationTest.java @@ -0,0 +1,110 @@ +/* + * 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 static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class AwsS3ObjectStorageConfigurationTest { + + @Test + public void credentialsShouldRespectBeanContract() { + EqualsVerifier.forClass(AwsS3ObjectStorageConfiguration.class).verify(); + } + + @Test + public void builderShouldThrowWhenEndpointIsNull() { + assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder() + .build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("'endpoint' is mandatory"); + } + + @Test + public void builderShouldThrowWhenEndpointIsEmpty() { + assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder() + .endpoint("") + .build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("'endpoint' is mandatory"); + } + + @Test + public void builderShouldThrowWhenAccessKeyIdIsNull() { + assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder() + .endpoint("myEndpoint") + .build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("'accessKeyId' is mandatory"); + } + + @Test + public void builderShouldThrowWhenAccessKeyIdIsEmpty() { + assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder() + .endpoint("myEndpoint") + .accessKeyId("") + .build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("'accessKeyId' is mandatory"); + } + + @Test + public void builderShouldThrowWhenSecretKeyIsNull() { + assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder() + .endpoint("myEndpoint") + .accessKeyId("myAccessKeyId") + .build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("'secretKey' is mandatory"); + } + + @Test + public void builderShouldThrowWhenSecretKeyIsEmpty() { + assertThatThrownBy(() -> AwsS3ObjectStorageConfiguration.builder() + .endpoint("myEndpoint") + .accessKeyId("myAccessKeyId") + .secretKey("") + .build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("'secretKey' is mandatory"); + } + + @Test + public void builderShouldWork() { + String endpoint = "myEndpoint"; + String accessKeyId = "myAccessKeyId"; + String secretKey = "mySecretKey"; + AwsS3ObjectStorageConfiguration configuration = AwsS3ObjectStorageConfiguration.builder() + .endpoint(endpoint) + .accessKeyId(accessKeyId) + .secretKey(secretKey) + .build(); + + assertSoftly(softly -> { + softly.assertThat(configuration.getEndpoint()).isEqualTo(endpoint); + softly.assertThat(configuration.getAccessKeyId()).isEqualTo(accessKeyId); + softly.assertThat(configuration.getSecretKey()).isEqualTo(secretKey); + }); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org