You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/07/09 07:55:42 UTC

[james-project] 02/06: JAMES-2806 new ObjectStorageBucketName POJO

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

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

commit e52e97198d5f3b9d96db5e3d39074c6171a03c30
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Mon Jul 8 11:51:27 2019 +0700

    JAMES-2806 new ObjectStorageBucketName POJO
    
    Because the BucketName passed into ObjectStorageBlobsDAO will be
    re calculated to take care about bucket prefix which is only the matter
    with ObjectStorage concern.
    
    To avoid confusing of return type when resolving BucketName,
    we create another type.
---
 .../objectstorage/ObjectStorageBucketName.java     | 68 ++++++++++++++++++++++
 .../objectstorage/ObjectStorageBucketNameTest.java | 55 +++++++++++++++++
 2 files changed, 123 insertions(+)

diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBucketName.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBucketName.java
new file mode 100644
index 0000000..62bd0c0
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBucketName.java
@@ -0,0 +1,68 @@
+/****************************************************************
+ * 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;
+
+import java.util.Objects;
+
+import org.apache.commons.lang3.StringUtils;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+class ObjectStorageBucketName {
+
+    static ObjectStorageBucketName of(String value) {
+        return new ObjectStorageBucketName(value);
+    }
+
+    private final String value;
+
+    private ObjectStorageBucketName(String value) {
+        Preconditions.checkNotNull(value);
+        Preconditions.checkArgument(StringUtils.isNotBlank(value), "`value` cannot be blank");
+
+        this.value = value;
+    }
+
+    String asString() {
+        return value;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof ObjectStorageBucketName) {
+            ObjectStorageBucketName that = (ObjectStorageBucketName) o;
+            return Objects.equals(this.value, that.value);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(value);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("value", value)
+            .toString();
+    }
+}
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBucketNameTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBucketNameTest.java
new file mode 100644
index 0000000..58d48d6
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBucketNameTest.java
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class ObjectStorageBucketNameTest {
+
+    @Test
+    void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(ObjectStorageBucketName.class)
+            .verify();
+    }
+
+    @Test
+    void newBucketNameShouldThrowWhenNullValue() {
+        String nullName = null;
+        assertThatThrownBy(() -> ObjectStorageBucketName.of(nullName))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    void newBucketNameShouldThrowWhenEmptyValue() {
+        assertThatThrownBy(() -> ObjectStorageBucketName.of(""))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void newBucketNameShouldThrowWhenBlankValue() {
+        assertThatThrownBy(() -> ObjectStorageBucketName.of("   "))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+}
\ No newline at end of file


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