JAMES-2525 introduces Keystone v3 datatypes
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1c47e2f5 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1c47e2f5 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1c47e2f5 Branch: refs/heads/master Commit: 1c47e2f59350541e1d0f9ee75d3314b614f2b791 Parents: 70a86f0 Author: Jean Helou <j...@codamens.fr> Authored: Fri Aug 31 17:59:28 2018 +0200 Committer: Benoit Tellier <btell...@linagora.com> Committed: Fri Oct 5 18:11:43 2018 +0700 ---------------------------------------------------------------------- .../blob/objectstorage/swift/DomainId.java | 67 +++++++++++++++ .../blob/objectstorage/swift/DomainName.java | 63 ++++++++++++++ .../blob/objectstorage/swift/IdentityV3.java | 75 +++++++++++++++++ .../james/blob/objectstorage/swift/Project.java | 88 ++++++++++++++++++++ .../blob/objectstorage/swift/ProjectName.java | 4 + .../blob/objectstorage/swift/DomainIdTest.java | 40 +++++++++ .../objectstorage/swift/DomainNameTest.java | 31 +++++++ .../objectstorage/swift/IdentityV3Test.java | 39 +++++++++ .../objectstorage/swift/ProjectNameTest.java | 8 ++ .../blob/objectstorage/swift/ProjectTest.java | 63 ++++++++++++++ 10 files changed, 478 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java new file mode 100644 index 0000000..fef7a7a --- /dev/null +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainId.java @@ -0,0 +1,67 @@ +/**************************************************************** + * 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.swift; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; + +public final class DomainId { + public static DomainId of(String value) { + return new DomainId(value); + } + + private final String value; + + private DomainId(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; + } + DomainId that = (DomainId) 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(); + } + + public String asString() { + return "domain:" + value; + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.java new file mode 100644 index 0000000..6bd921e --- /dev/null +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/DomainName.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.swift; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; + +public final class DomainName { + public static DomainName of(String value) { + return new DomainName(value); + } + + private final String value; + + private DomainName(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; + } + DomainName that = (DomainName) 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/1c47e2f5/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.java new file mode 100644 index 0000000..b8b1d1c --- /dev/null +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/IdentityV3.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.swift; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; + +public final class IdentityV3 { + public static IdentityV3 of(DomainName domainName, UserName userName) { + return new IdentityV3(domainName, userName); + } + + private final DomainName domainName; + private final UserName userName; + + private IdentityV3(DomainName domainName, UserName userName) { + this.domainName = domainName; + this.userName = userName; + } + + public String asString() { + return domainName.value() + ":" + userName.value(); + } + + public DomainName getDomainName() { + return domainName; + } + + public UserName getUserName() { + return userName; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + IdentityV3 identity = (IdentityV3) o; + return Objects.equal(domainName, identity.domainName) && + Objects.equal(userName, identity.userName); + } + + @Override + public int hashCode() { + return Objects.hashCode(domainName, userName); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("domain", domainName) + .add("userName", userName) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java new file mode 100644 index 0000000..963ded4 --- /dev/null +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/Project.java @@ -0,0 +1,88 @@ +/**************************************************************** + * 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.swift; + +import java.util.Optional; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; + +public final class Project { + public static Project of(ProjectName userName) { + return new Project(userName, Optional.empty(), Optional.empty()); + } + + public static Project of(ProjectName userName, DomainName domainName) { + return new Project(userName, Optional.of(domainName), Optional.empty()); + } + + public static Project of(ProjectName userName, DomainId domainId) { + return new Project(userName, Optional.empty(), Optional.of(domainId)); + } + + private final ProjectName name; + private final Optional<DomainName> domainName; + private final Optional<DomainId> domainId; + + private Project(ProjectName name, Optional<DomainName> domainName, Optional<DomainId> domainId) { + this.domainName = domainName; + this.name = name; + this.domainId = domainId; + } + + public Optional<DomainName> domainName() { + return domainName; + } + + public Optional<DomainId> domainId() { + return domainId; + } + + public ProjectName name() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Project project = (Project) o; + return Objects.equal(name, project.name) && + Objects.equal(domainName, project.domainName) && + Objects.equal(domainId, project.domainId); + } + + @Override + public int hashCode() { + return Objects.hashCode(name, domainName, domainId); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("domain", domainName) + .add("name", name) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java index e91adb3..56969bb 100644 --- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/ProjectName.java @@ -37,6 +37,10 @@ public final class ProjectName { return value; } + public String asString() { + return "project:" + value; + } + @Override public boolean equals(Object o) { if (this == o) { http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java new file mode 100644 index 0000000..f95559a --- /dev/null +++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainIdTest.java @@ -0,0 +1,40 @@ +/**************************************************************** + * 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.swift; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class DomainIdTest { + + @Test + public void domainIdShouldRespectBeanContract() { + EqualsVerifier.forClass(DomainId.class).verify(); + } + + @Test + public void domainIdShouldProjectToDomainIdString() { + String actual = DomainId.of("foo").asString(); + assertThat(actual).isEqualTo("domain:foo"); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.java new file mode 100644 index 0000000..4b108c9 --- /dev/null +++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/DomainNameTest.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.swift; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class DomainNameTest { + @Test + public void domainNameShouldRespectBeanContract() { + EqualsVerifier.forClass(DomainName.class).verify(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.java new file mode 100644 index 0000000..39c3e27 --- /dev/null +++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/IdentityV3Test.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.swift; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class IdentityV3Test { + @Test + void identityV3RendersProperlyAsString() { + IdentityV3 identity = IdentityV3.of(DomainName.of("domain"), UserName.of("user")); + assertThat(identity.asString()).isEqualTo("domain:user"); + } + + @Test + public void identityV3ShouldRespectBeanContract() { + EqualsVerifier.forClass(IdentityV3.class).verify(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java index ac9c1b6..080a08e 100644 --- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java +++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectNameTest.java @@ -19,6 +19,8 @@ package org.apache.james.blob.objectstorage.swift; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; @@ -28,4 +30,10 @@ class ProjectNameTest { public void projectNameShouldRespectBeanContract() { EqualsVerifier.forClass(ProjectName.class).verify(); } + + @Test + public void projectNameShouldProjectToProjectNameString() { + String actual = ProjectName.of("bar").asString(); + assertThat(actual).isEqualTo("project:bar"); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/1c47e2f5/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.java new file mode 100644 index 0000000..9956d11 --- /dev/null +++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/swift/ProjectTest.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.swift; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class ProjectTest { + + private static final ProjectName PROJECT_NAME = ProjectName.of("project"); + private static final DomainName DOMAIN_NAME = DomainName.of("domainName"); + private static final DomainId DOMAIN_ID = DomainId.of("domainId"); + + @Test + public void projectShouldRespectBeanContract() { + EqualsVerifier.forClass(Project.class).verify(); + } + + @Test + void projectCanBeBuiltFromNameAlone() { + Project project = Project.of(PROJECT_NAME); + assertThat(project.domainName()).isEmpty(); + assertThat(project.domainId()).isEmpty(); + assertThat(project.name()).isEqualTo(PROJECT_NAME); + } + + + @Test + void projectCanBeBuiltFromNameAnDomainName() { + Project project = Project.of(PROJECT_NAME, DOMAIN_NAME); + assertThat(project.domainName()).contains(DOMAIN_NAME); + assertThat(project.domainId()).isEmpty(); + assertThat(project.name()).isEqualTo(PROJECT_NAME); + } + + @Test + void projectCanBeBuiltFromNameAnDomainId() { + Project project = Project.of(PROJECT_NAME, DOMAIN_ID); + assertThat(project.domainName()).isEmpty(); + assertThat(project.domainId()).contains(DOMAIN_ID); + assertThat(project.name()).isEqualTo(PROJECT_NAME); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org