james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [05/14] james-project git commit: JAMES-2525 refactors Identity to be built of TenantName and UserName
Date Fri, 05 Oct 2018 11:12:48 GMT
JAMES-2525 refactors Identity to be built of TenantName and UserName


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/ff835fd8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/ff835fd8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/ff835fd8

Branch: refs/heads/master
Commit: ff835fd87fa72fdd0b461688fcace868114ea97e
Parents: db660ef
Author: Jean Helou <jhe@codamens.fr>
Authored: Thu Aug 30 14:58:35 2018 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Fri Oct 5 18:11:42 2018 +0700

----------------------------------------------------------------------
 .../james/blob/objectstorage/Identity.java      | 63 ----------------
 .../objectstorage/ObjectStorageBlobsDAO.java    |  2 +-
 .../ObjectStorageConfiguration.java             | 41 ++++++++---
 .../james/blob/objectstorage/SwiftIdentity.java | 75 ++++++++++++++++++++
 .../james/blob/objectstorage/TenantName.java    | 63 ++++++++++++++++
 .../james/blob/objectstorage/UserName.java      | 63 ++++++++++++++++
 .../james/blob/objectstorage/IdentityTest.java  | 31 --------
 .../ObjectStorageBlobsDAOTest.java              | 10 +--
 .../ObjectStorageConfigurationTest.java         | 60 +++++++++++++---
 .../blob/objectstorage/SwiftIdentityTest.java   | 39 ++++++++++
 .../blob/objectstorage/TenantNameTest.java      | 31 ++++++++
 .../james/blob/objectstorage/UserNameTest.java  | 31 ++++++++
 12 files changed, 389 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/Identity.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/Identity.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/Identity.java
deleted file mode 100644
index 094ba30..0000000
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/Identity.java
+++ /dev/null
@@ -1,63 +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;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-
-public final class Identity {
-    public static Identity of(String value) {
-        return new Identity(value);
-    }
-
-    private final String identity;
-
-    private Identity(String value) {
-        this.identity = value;
-    }
-
-    public String value() {
-        return identity;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
-        }
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        Identity identity1 = (Identity) o;
-        return Objects.equal(identity, identity1.identity);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hashCode(identity);
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(this)
-            .add("identity", identity)
-            .toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
index 0afbbaf..5cb5c77 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
@@ -60,7 +60,7 @@ class ObjectStorageBlobsDAO implements BlobStore {
         RegionScopedBlobStoreContext blobStoreContext = ContextBuilder.newBuilder("openstack-swift")
             .endpoint(objectStorageConfiguration.getEndpoint().toString())
             .credentials(
-                objectStorageConfiguration.getIdentity().value(),
+                objectStorageConfiguration.getSwiftIdentity().asString(),
                 objectStorageConfiguration.getCredentials().value())
             .overrides(objectStorageConfiguration.getOverrides())
             .modules(JCLOUDS_MODULES)

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageConfiguration.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageConfiguration.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageConfiguration.java
index 67be702..58ef7a2 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageConfiguration.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageConfiguration.java
@@ -31,11 +31,12 @@ import com.google.common.base.Preconditions;
 public class ObjectStorageConfiguration {
     public static class Builder {
         private URI endpoint;
-        private Identity identity;
         private Credentials credentials;
         private Optional<Region> region;
         private Optional<UserHeaderName> userHeaderName;
         private Optional<PassHeaderName> passHeaderName;
+        private UserName userName;
+        private TenantName tenantName;
 
         public Builder() {
             region = Optional.empty();
@@ -48,11 +49,23 @@ public class ObjectStorageConfiguration {
             return this;
         }
 
-        public ObjectStorageConfiguration.Builder identity(Identity identity) {
-            this.identity = identity;
+        public ObjectStorageConfiguration.Builder identity(SwiftIdentity swiftIdentity) {
+            this.tenantName = swiftIdentity.getTenant();
+            this.userName = swiftIdentity.getUserName();
             return this;
         }
 
+        public ObjectStorageConfiguration.Builder tenantName(TenantName tenantName) {
+            this.tenantName = tenantName;
+            return this;
+        }
+
+        public ObjectStorageConfiguration.Builder userName(UserName userName) {
+            this.userName = userName;
+            return this;
+        }
+
+
         public ObjectStorageConfiguration.Builder credentials(Credentials credentials) {
             this.credentials = credentials;
             return this;
@@ -75,21 +88,29 @@ public class ObjectStorageConfiguration {
 
         public ObjectStorageConfiguration build() {
             Preconditions.checkState(endpoint != null);
-            Preconditions.checkState(identity != null);
+            Preconditions.checkState(tenantName != null);
+            Preconditions.checkState(userName != null);
             Preconditions.checkState(credentials != null);
-            return new ObjectStorageConfiguration(endpoint, identity, credentials, region,
userHeaderName, passHeaderName);
+            SwiftIdentity swiftIdentity = SwiftIdentity.of(tenantName, userName);
+            return new ObjectStorageConfiguration(
+                endpoint,
+                swiftIdentity,
+                credentials,
+                region,
+                userHeaderName,
+                passHeaderName);
         }
     }
 
     private final URI endpoint;
     private final Optional<Region> region;
-    private final Identity identity;
+    private final SwiftIdentity swiftIdentity;
     private final Credentials credentials;
     private final Optional<UserHeaderName> userHeaderName;
     private final Optional<PassHeaderName> passHeaderName;
 
     private ObjectStorageConfiguration(URI endpoint,
-                                       Identity identity,
+                                       SwiftIdentity swiftIdentity,
                                        Credentials credentials,
                                        Optional<Region> region,
                                        Optional<UserHeaderName> userHeaderName,
@@ -98,7 +119,7 @@ public class ObjectStorageConfiguration {
         this.region = region;
         this.userHeaderName = userHeaderName;
         this.passHeaderName = passHeaderName;
-        this.identity = identity;
+        this.swiftIdentity = swiftIdentity;
         this.credentials = credentials;
     }
 
@@ -106,8 +127,8 @@ public class ObjectStorageConfiguration {
         return endpoint;
     }
 
-    public Identity getIdentity() {
-        return identity;
+    public SwiftIdentity getSwiftIdentity() {
+        return swiftIdentity;
     }
 
     public Credentials getCredentials() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/SwiftIdentity.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/SwiftIdentity.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/SwiftIdentity.java
new file mode 100644
index 0000000..e23a602
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/SwiftIdentity.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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 com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+
+public final class SwiftIdentity {
+    public static SwiftIdentity of(TenantName tenant, UserName userName) {
+        return new SwiftIdentity(tenant, userName);
+    }
+
+    private final TenantName tenant;
+    private final UserName userName;
+
+    private SwiftIdentity(TenantName tenant, UserName userName) {
+        this.tenant = tenant;
+        this.userName = userName;
+    }
+
+    public String asString() {
+        return tenant.value() + ":" + userName.value();
+    }
+
+    public TenantName getTenant() {
+        return tenant;
+    }
+
+    public UserName getUserName() {
+        return userName;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        SwiftIdentity swiftIdentity = (SwiftIdentity) o;
+        return Objects.equal(tenant, swiftIdentity.tenant) &&
+            Objects.equal(userName, swiftIdentity.userName);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(tenant, userName);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("tenant", tenant)
+            .add("userName", userName)
+            .toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/TenantName.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/TenantName.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/TenantName.java
new file mode 100644
index 0000000..85fb17d
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/TenantName.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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 com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+
+public final class TenantName {
+    public static TenantName of(String value) {
+        return new TenantName(value);
+    }
+
+    private final String value;
+
+    private TenantName(String value) {
+        this.value = value;
+    }
+
+    public String value() {
+        return value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        TenantName that = (TenantName) o;
+        return Objects.equal(value, that.value);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(value);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("value", value)
+            .toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/UserName.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/UserName.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/UserName.java
new file mode 100644
index 0000000..a2b7d64
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/UserName.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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 com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+
+public final class UserName {
+    public static UserName of(String value) {
+        return new UserName(value);
+    }
+
+    private final String value;
+
+    private UserName(String value) {
+        this.value = value;
+    }
+
+    public String value() {
+        return value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        UserName that = (UserName) o;
+        return Objects.equal(value, that.value);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(value);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("value", value)
+            .toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/IdentityTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/IdentityTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/IdentityTest.java
deleted file mode 100644
index 0910bff..0000000
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/IdentityTest.java
+++ /dev/null
@@ -1,31 +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;
-
-import org.junit.jupiter.api.Test;
-
-import nl.jqno.equalsverifier.EqualsVerifier;
-
-class IdentityTest {
-    @Test
-    public void credentialsShouldRespectBeanContract() {
-        EqualsVerifier.forClass(Identity.class).verify();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
index 7db44bc..ddef841 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
@@ -37,10 +37,10 @@ import org.junit.jupiter.api.extension.ExtendWith;
 
 @ExtendWith(DockerSwiftExtension.class)
 public class ObjectStorageBlobsDAOTest implements BlobStoreContract {
-    private static final String TENANT_NAME = "test";
-    private static final String USER_NAME = "tester";
+    private static final TenantName TENANT_NAME = TenantName.of("test");
+    private static final UserName USER_NAME = UserName.of("tester");
     private static final Credentials PASSWORD = Credentials.of("testing");
-    private static final Identity IDENTITY = Identity.of(TENANT_NAME + ":" + USER_NAME);
+    private static final SwiftIdentity SWIFT_IDENTITY = SwiftIdentity.of(TENANT_NAME, USER_NAME);
 
     private URI swiftEndpoint;
     private ContainerName containerName;
@@ -55,7 +55,7 @@ public class ObjectStorageBlobsDAOTest implements BlobStoreContract {
         swiftEndpoint = dockerSwift.swiftEndpoint();
         BlobStoreContext blobStoreContext = ContextBuilder.newBuilder("openstack-swift")
             .endpoint(swiftEndpoint.toString())
-            .credentials(IDENTITY.value(), PASSWORD.value())
+            .credentials(SWIFT_IDENTITY.asString(), PASSWORD.value())
             .overrides(overrides)
             .buildView(BlobStoreContext.class);
         blobStore = blobStoreContext.getBlobStore();
@@ -74,7 +74,7 @@ public class ObjectStorageBlobsDAOTest implements BlobStoreContract {
         ObjectStorageConfiguration testConfig =
             new ObjectStorageConfiguration.Builder()
                 .endpoint(swiftEndpoint)
-                .identity(IDENTITY)
+                .identity(SWIFT_IDENTITY)
                 .credentials(PASSWORD)
                 .tempAuthHeaderUserName(UserHeaderName.of("X-Storage-User"))
                 .tempAuthHeaderPassName(PassHeaderName.of("X-Storage-Pass"))

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageConfigurationTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageConfigurationTest.java
index 7939921..9c51394 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageConfigurationTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageConfigurationTest.java
@@ -28,31 +28,55 @@ import org.junit.jupiter.api.Test;
 
 class ObjectStorageConfigurationTest {
 
+    private static final TenantName TENANT_NAME = TenantName.of("fake");
+    private static final UserName USER_NAME = UserName.of("fake");
     private static URI ENDPOINT = URI.create("http://example.com");
     private static Credentials CREDENTIALS = Credentials.of("fake");
-    private static Identity IDENTITY = Identity.of("fake");
+    private static SwiftIdentity SWIFT_IDENTITY = SwiftIdentity.of(TenantName.of("fake"),
+        UserName.of("fake"));
 
     @Test
     void enpointIsMandatoryToBuildConfiguration() throws Exception {
         ObjectStorageConfiguration.Builder builder = new ObjectStorageConfiguration.Builder();
-        assertThatThrownBy(() -> builder.build()).isInstanceOf(IllegalStateException.class);
+        builder
+            .tenantName(TENANT_NAME)
+            .userName(USER_NAME)
+            .credentials(CREDENTIALS);
+
+        assertThatThrownBy(builder::build).isInstanceOf(IllegalStateException.class);
+    }
+
+    @Test
+    void tenantNameIsMandatoryToBuildConfiguration() throws Exception {
+        ObjectStorageConfiguration.Builder builder = new ObjectStorageConfiguration.Builder();
+        builder
+            .endpoint(ENDPOINT)
+            .userName(USER_NAME)
+            .credentials(CREDENTIALS);
+
+        assertThatThrownBy(builder::build).isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    void identityIsMandatoryToBuildConfiguration() throws Exception {
+    void userNameIsMandatoryToBuildConfiguration() throws Exception {
         ObjectStorageConfiguration.Builder builder = new ObjectStorageConfiguration.Builder();
         builder
-            .endpoint(new URI("http", "example.com", null, null));
-        assertThatThrownBy(() -> builder.build()).isInstanceOf(IllegalStateException.class);
+            .endpoint(ENDPOINT)
+            .tenantName(TENANT_NAME)
+            .credentials(CREDENTIALS);
+
+        assertThatThrownBy(builder::build).isInstanceOf(IllegalStateException.class);
     }
 
     @Test
     void credentialsIsMandatoryToBuildConfiguration() throws Exception {
         ObjectStorageConfiguration.Builder builder = new ObjectStorageConfiguration.Builder();
         builder
-            .endpoint(new URI("http", "example.com", null, null))
-            .identity(Identity.of("fake"));
-        assertThatThrownBy(() -> builder.build()).isInstanceOf(IllegalStateException.class);
+            .endpoint(ENDPOINT)
+            .tenantName(TENANT_NAME)
+            .userName(USER_NAME);
+
+        assertThatThrownBy(builder::build).isInstanceOf(IllegalStateException.class);
     }
 
     @Test
@@ -60,13 +84,29 @@ class ObjectStorageConfigurationTest {
         ObjectStorageConfiguration.Builder builder = new ObjectStorageConfiguration.Builder();
         builder
             .endpoint(ENDPOINT)
-            .identity(IDENTITY)
+            .tenantName(TENANT_NAME)
+            .userName(USER_NAME)
+            .credentials(CREDENTIALS);
+
+        ObjectStorageConfiguration build = builder.build();
+
+        assertThat(build.getEndpoint()).isEqualTo(ENDPOINT);
+        assertThat(build.getSwiftIdentity()).isEqualTo(SWIFT_IDENTITY);
+        assertThat(build.getCredentials()).isEqualTo(CREDENTIALS);
+    }
+
+    @Test
+    void identityCanReplaceTenantAndUserName() throws Exception {
+        ObjectStorageConfiguration.Builder builder = new ObjectStorageConfiguration.Builder();
+        builder
+            .endpoint(ENDPOINT)
+            .identity(SWIFT_IDENTITY)
             .credentials(CREDENTIALS);
 
         ObjectStorageConfiguration build = builder.build();
 
         assertThat(build.getEndpoint()).isEqualTo(ENDPOINT);
-        assertThat(build.getIdentity()).isEqualTo(IDENTITY);
+        assertThat(build.getSwiftIdentity()).isEqualTo(SWIFT_IDENTITY);
         assertThat(build.getCredentials()).isEqualTo(CREDENTIALS);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/SwiftIdentityTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/SwiftIdentityTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/SwiftIdentityTest.java
new file mode 100644
index 0000000..785a1b1
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/SwiftIdentityTest.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class SwiftIdentityTest {
+    @Test
+    void swiftIdentityRendersProperlyAsString() {
+        SwiftIdentity swiftIdentity = SwiftIdentity.of(TenantName.of("tenant"), UserName.of("user"));
+        assertThat(swiftIdentity.asString()).isEqualTo("tenant:user");
+    }
+
+    @Test
+    public void credentialsShouldRespectBeanContract() {
+        EqualsVerifier.forClass(SwiftIdentity.class).verify();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/TenantNameTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/TenantNameTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/TenantNameTest.java
new file mode 100644
index 0000000..2394757
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/TenantNameTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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 org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class TenantNameTest {
+    @Test
+    public void tenantNameShouldRespectBeanContract() {
+        EqualsVerifier.forClass(TenantName.class).verify();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff835fd8/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/UserNameTest.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/UserNameTest.java
b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/UserNameTest.java
new file mode 100644
index 0000000..da73e4e
--- /dev/null
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/UserNameTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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 org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class UserNameTest {
+    @Test
+    public void userNameShouldRespectBeanContract() {
+        EqualsVerifier.forClass(UserName.class).verify();
+    }
+}
\ 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


Mime
View raw message