Author: matthieu
Date: Tue Jan 12 13:12:26 2016
New Revision: 1724222
URL: http://svn.apache.org/viewvc?rev=1724222&view=rev
Log:
MAILBOX-261 Message now have a unique MessageId
Added:
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageId.java
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
Modified:
james/project/trunk/mailbox/pom.xml
james/project/trunk/mailbox/store/pom.xml
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
Modified: james/project/trunk/mailbox/pom.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/pom.xml?rev=1724222&r1=1724221&r2=1724222&view=diff
==============================================================================
--- james/project/trunk/mailbox/pom.xml (original)
+++ james/project/trunk/mailbox/pom.xml Tue Jan 12 13:12:26 2016
@@ -449,6 +449,11 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
+ <dependency>
+ <groupId>nl.jqno.equalsverifier</groupId>
+ <artifactId>equalsverifier</artifactId>
+ <version>1.7.6</version>
+ </dependency>
<!--
END Testing
-->
Modified: james/project/trunk/mailbox/store/pom.xml
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/pom.xml?rev=1724222&r1=1724221&r2=1724222&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/pom.xml (original)
+++ james/project/trunk/mailbox/store/pom.xml Tue Jan 12 13:12:26 2016
@@ -107,6 +107,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>nl.jqno.equalsverifier</groupId>
+ <artifactId>equalsverifier</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<scope>test</scope>
Modified:
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java?rev=1724222&r1=1724221&r2=1724222&view=diff
==============================================================================
---
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java
(original)
+++
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AbstractMessage.java
Tue Jan 12 13:12:26 2016
@@ -118,6 +118,9 @@ public abstract class AbstractMessage<Id
return new SequenceInputStream(getHeaderContent(), getBodyContent());
}
-
+ @Override
+ public DefaultMessageId getMessageId() {
+ return new DefaultMessageId(getMailboxId(), getUid());
+ }
}
Added:
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java?rev=1724222&view=auto
==============================================================================
---
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
(added)
+++
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
Tue Jan 12 13:12:26 2016
@@ -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.mailbox.store.mail.model;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+public class DefaultMessageId implements MessageId {
+
+ private final MailboxId mailboxId;
+ private final long messageUid;
+
+ public DefaultMessageId(MailboxId mailboxId, long messageUid) {
+ Preconditions.checkNotNull(mailboxId);
+ this.mailboxId = mailboxId;
+ this.messageUid = messageUid;
+ }
+
+ @Override
+ public String serialize() {
+ return String.format("%s-%d", mailboxId.serialize(), messageUid);
+ }
+
+ @Override
+ public final boolean equals(Object obj) {
+ if (obj instanceof DefaultMessageId) {
+ DefaultMessageId other = (DefaultMessageId) obj;
+ return Objects.equal(mailboxId, other.mailboxId) &&
+ Objects.equal(messageUid, other.messageUid);
+
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hashCode(mailboxId, messageUid);
+ }
+}
Modified:
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java?rev=1724222&r1=1724221&r2=1724222&view=diff
==============================================================================
---
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
(original)
+++
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
Tue Jan 12 13:12:26 2016
@@ -32,6 +32,8 @@ import javax.mail.Flags;
*/
public interface Message<Id extends MailboxId> extends Comparable<Message<Id>>{
+ MessageId getMessageId();
+
Date getInternalDate();
/**
Added:
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageId.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageId.java?rev=1724222&view=auto
==============================================================================
---
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageId.java
(added)
+++
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageId.java
Tue Jan 12 13:12:26 2016
@@ -0,0 +1,23 @@
+/****************************************************************
+ * 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.mailbox.store.mail.model;
+
+public interface MessageId {
+ String serialize();
+}
Modified:
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java?rev=1724222&r1=1724221&r2=1724222&view=diff
==============================================================================
---
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
(original)
+++
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
Tue Jan 12 13:12:26 2016
@@ -35,6 +35,7 @@ import java.util.Map.Entry;
import javax.mail.Flags;
+import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.Message;
import org.apache.james.mailbox.store.mail.model.Property;
@@ -71,79 +72,46 @@ public class SimpleMailboxMembership imp
setFlags(flags);
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#getInternalDate()
- */
public Date getInternalDate() {
return internalDate;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#getMailboxId()
- */
public TestId getMailboxId() {
return mailboxId;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#getUid()
- */
public long getUid() {
return uid;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#isAnswered()
- */
public boolean isAnswered() {
return answered;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#isDeleted()
- */
public boolean isDeleted() {
return deleted;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#isDraft()
- */
public boolean isDraft() {
return draft;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#isFlagged()
- */
public boolean isFlagged() {
return flagged;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#isRecent()
- */
public boolean isRecent() {
return recent;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#isSeen()
- */
public boolean isSeen() {
return seen;
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#unsetRecent()
- */
public void unsetRecent() {
recent = false;
}
- /**
- * @see
org.apache.james.imap.Message.mail.model.Document#setFlags(javax.mail.Flags)
- */
public void setFlags(Flags flags) {
answered = flags.contains(Flags.Flag.ANSWERED);
deleted = flags.contains(Flags.Flag.DELETED);
@@ -153,9 +121,6 @@ public class SimpleMailboxMembership imp
seen = flags.contains(Flags.Flag.SEEN);
}
- /**
- * @see org.apache.james.imap.Message.mail.model.Document#createFlags()
- */
public Flags createFlags() {
final Flags flags = new Flags();
@@ -240,17 +205,10 @@ public class SimpleMailboxMembership imp
private long modSeq;
- /**
- * @throws IOException
- * @see org.apache.james.imap.Message.mail.model.Document#getBodyContent()
- */
public InputStream getBodyContent() throws IOException {
return new ByteArrayInputStream(body);
}
- /**
- * @see
org.apache.james.mailbox.store.mail.model.Message#getHeaderContent()
- */
public InputStream getHeaderContent() throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Writer writer = new OutputStreamWriter(baos, "us-ascii");
@@ -293,9 +251,6 @@ public class SimpleMailboxMembership imp
return size;
}
- /**
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
public int compareTo(Message<TestId> other) {
return (int) (getUid() - other.getUid());
}
@@ -316,7 +271,10 @@ public class SimpleMailboxMembership imp
public InputStream getFullContent() throws IOException {
return new SequenceInputStream(getHeaderContent(), getBodyContent());
}
-
-
+ @Override
+ public DefaultMessageId getMessageId() {
+ return new DefaultMessageId(getMailboxId(), getUid());
+ }
+
}
Added:
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
URL:
http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java?rev=1724222&view=auto
==============================================================================
---
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
(added)
+++
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
Tue Jan 12 13:12:26 2016
@@ -0,0 +1,46 @@
+/****************************************************************
+ * 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.mailbox.store.mail.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.store.TestId;
+import org.junit.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class DefaultMessageIdTest {
+
+ @Test(expected=NullPointerException.class)
+ public void constructorShouldThrowWhenNullMailboxId() {
+ new DefaultMessageId(null, 1);
+ }
+
+ @Test
+ public void serializeShouldFormatMailboxIdAndUid() {
+ DefaultMessageId id = new DefaultMessageId(TestId.of(12l), 1);
+ assertThat(id.serialize()).isEqualTo("12-1");
+ }
+
+ @Test
+ public void shouldRespectJavaBeanContract() {
+ EqualsVerifier.forClass(DefaultMessageId.class).verify();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]