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 3e6f9f3dbf3443faeb8873972a1af966ec57fd0d Author: Benoit Tellier <[email protected]> AuthorDate: Tue Jun 18 11:28:45 2019 +0700 JAMES-2794 Create an EnqueueId POJO in RabbitMQMailQueue The aim is not to identify a given email but rather identify a given enqueue hence I do not reuse the MailKey class, that marks the intent to identify a given mail, regardless of specific enqueues. --- .../model/MailKey.java => EnQueueId.java} | 45 +++++++++++++--------- .../model/{MailKeyTest.java => EnQueueIdTest.java} | 32 ++++++++++++++- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/MailKey.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/EnQueueId.java similarity index 62% rename from server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/MailKey.java rename to server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/EnQueueId.java index 4f17a71..133172d 100644 --- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/model/MailKey.java +++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/EnQueueId.java @@ -17,49 +17,56 @@ * under the License. * ****************************************************************/ -package org.apache.james.queue.rabbitmq.view.cassandra.model; +package org.apache.james.queue.rabbitmq; import java.util.Objects; +import java.util.UUID; -import org.apache.mailet.Mail; - +import com.datastax.driver.core.utils.UUIDs; import com.google.common.base.Preconditions; -public class MailKey { +public class EnQueueId { + + public static EnQueueId generate() { + return of(UUIDs.timeBased()); + } - public static MailKey fromMail(Mail mail) { - return of(mail.getName()); + public static EnQueueId of(UUID uuid) { + Preconditions.checkNotNull(uuid); + return new EnQueueId(uuid); } - public static MailKey of(String mailKey) { - return new MailKey(mailKey); + public static EnQueueId ofSerialized(String serialized) { + Preconditions.checkNotNull(serialized); + return of(UUID.fromString(serialized)); } - private final String mailKey; + private final UUID id; - private MailKey(String mailKey) { - Preconditions.checkNotNull(mailKey); - Preconditions.checkArgument(!mailKey.isEmpty()); + private EnQueueId(UUID id) { + this.id = id; + } - this.mailKey = mailKey; + public UUID asUUID() { + return id; } - public String getMailKey() { - return mailKey; + public String serialize() { + return id.toString(); } @Override public final boolean equals(Object o) { - if (o instanceof MailKey) { - MailKey mailKey1 = (MailKey) o; + if (o instanceof EnQueueId) { + EnQueueId enQueueId = (EnQueueId) o; - return Objects.equals(this.mailKey, mailKey1.mailKey); + return Objects.equals(this.id, enQueueId.id); } return false; } @Override public final int hashCode() { - return Objects.hash(mailKey); + return Objects.hash(id); } } diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/MailKeyTest.java b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/EnQueueIdTest.java similarity index 60% rename from server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/MailKeyTest.java rename to server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/EnQueueIdTest.java index c1a854e..2f21c34 100644 --- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/MailKeyTest.java +++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/view/cassandra/model/EnQueueIdTest.java @@ -19,15 +19,43 @@ package org.apache.james.queue.rabbitmq.view.cassandra.model; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.UUID; + +import org.apache.james.queue.rabbitmq.EnQueueId; import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -class MailKeyTest { +class EnQueueIdTest { + private static final UUID UUID_1 = UUID.fromString("110e8400-e29b-11d4-a716-446655440000"); @Test void shouldMatchBeanContract() { - EqualsVerifier.forClass(MailKey.class) + EqualsVerifier.forClass(EnQueueId.class) .verify(); } + + @Test + void ofSerializedShouldDeserializeTheGivenEnqueueId() { + assertThat(EnQueueId.ofSerialized(UUID_1.toString())) + .isEqualTo(EnQueueId.of(UUID_1)); + } + + @Test + void serializeShouldReturnAStringRepresentation() { + EnQueueId enQueueId = EnQueueId.of(UUID_1); + + assertThat(enQueueId.serialize()) + .isEqualTo(UUID_1.toString()); + } + + @Test + void ofSerializedShouldRevertSerialize() { + EnQueueId enQueueId = EnQueueId.of(UUID_1); + + assertThat(EnQueueId.ofSerialized(enQueueId.serialize())) + .isEqualTo(enQueueId); + } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
