james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [4/6] james-project git commit: MAILBOX-279: JPAMappersTest should work with MESSAGE
Date Mon, 09 Jan 2017 09:13:32 GMT
MAILBOX-279: JPAMappersTest should work with MESSAGE


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

Branch: refs/heads/master
Commit: 1ccb1eca78ae2c20d4c2b3ed9d984ec54de40b14
Parents: fc42d06
Author: Quynh Nguyen <qnguyen@linagora.com>
Authored: Wed Dec 7 14:16:43 2016 +0700
Committer: Quynh Nguyen <qnguyen@linagora.com>
Committed: Mon Jan 9 15:16:52 2017 +0700

----------------------------------------------------------------------
 .../mailbox/jpa/mail/JPAMailboxMapper.java      |  10 +-
 .../mailbox/jpa/mail/JPAMessageMapper.java      |  43 ++--
 .../mailbox/jpa/mail/model/JPAMailbox.java      |   9 +-
 .../openjpa/AbstractJPAMailboxMessage.java      |  29 +--
 .../jpa/mail/TransactionalMessageMapper.java    |  42 ++--
 .../mailbox/store/mail/MessageMetadata.java     |  69 ------
 .../james/mailbox/store/mail/MessageUtils.java  | 118 ++++++++++
 .../mailbox/store/mail/MessageUtilsTest.java    | 117 ++++++++++
 .../store/mail/model/ListMessageAssert.java     | 145 ++++++++++++
 .../store/mail/model/ListMessageAssertTest.java | 230 +++++++++++++++++++
 .../mail/model/ListMessagePropertiesAssert.java |  99 ++++++++
 .../model/ListMessagePropertiesAssertTest.java  |  97 ++++++++
 .../store/mail/model/MessageMapperTest.java     | 136 ++++++-----
 .../model/MessageWithAttachmentMapperTest.java  |   3 +-
 14 files changed, 944 insertions(+), 203 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
index d2d883b..7fe207a 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java
@@ -77,12 +77,10 @@ public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxM
     public void save(Mailbox mailbox) throws MailboxException {
         try {
             this.lastMailboxName = mailbox.getName();
-            if (mailbox instanceof JPAMailbox) {
-                getEntityManager().persist(mailbox);
-            } else {
-                JPAMailbox persistedData = new JPAMailbox(mailbox);
-                getEntityManager().persist(persistedData);
-                mailbox.setMailboxId(persistedData.getMailboxId());
+            JPAMailbox persistedMailbox = JPAMailbox.from(mailbox);
+            getEntityManager().persist(mailbox);
+            if (!(mailbox instanceof JPAMailbox)) {
+                mailbox.setMailboxId(persistedMailbox.getMailboxId());
             }
         } catch (PersistenceException e) {
             throw new MailboxException("Save of mailbox " + mailbox.getName() +" failed", e);

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
index b7542c6..ac581a0 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
@@ -45,7 +45,8 @@ import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.FlagsUpdateCalculator;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
 import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.MessageMetadata;
+import org.apache.james.mailbox.store.mail.MessageUtils;
+import org.apache.james.mailbox.store.mail.MessageUtils.MessageChangedFlags;
 import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.UidProvider;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -59,11 +60,12 @@ import com.google.common.collect.ImmutableList;
  * JPA implementation of a {@link MessageMapper}. This class is not thread-safe!
  */
 public class JPAMessageMapper extends JPATransactionalMapper implements MessageMapper {
-    private final MessageMetadata messageMetadataMapper;
+    private static final int UNLIMIT_MAX_SIZE = -1;
+    private final MessageUtils messageMetadataMapper;
 
     public JPAMessageMapper(MailboxSession mailboxSession, UidProvider uidProvider, ModSeqProvider modSeqProvider, EntityManagerFactory entityManagerFactory) {
         super(entityManagerFactory);
-        this.messageMetadataMapper = new MessageMetadata(mailboxSession, uidProvider, modSeqProvider);
+        this.messageMetadataMapper = new MessageUtils(mailboxSession, uidProvider, modSeqProvider);
     }
 
     /**
@@ -249,30 +251,15 @@ public class JPAMessageMapper extends JPATransactionalMapper implements MessageM
     @Override
     public Iterator<UpdatedFlags> updateFlags(Mailbox mailbox, FlagsUpdateCalculator flagsUpdateCalculator,
             MessageRange set) throws MailboxException {
-        ImmutableList.Builder<UpdatedFlags> updatedFlags = ImmutableList.builder();
-        Iterator<MailboxMessage> messages = findInMailbox(mailbox, set, FetchType.Metadata, -1);
-        
-        long modSeq = -1;
-        if (messages.hasNext()) {
-            modSeq = messageMetadataMapper.nextModSeq(mailbox);
-        }
-        while(messages.hasNext()) {
-            MailboxMessage member = messages.next();
-            Flags originalFlags = member.createFlags();
-            member.setFlags(flagsUpdateCalculator.buildNewFlags(originalFlags));
-            Flags newFlags = member.createFlags();
-            if (UpdatedFlags.flagsChanged(originalFlags, newFlags)) {
-                member.setModSeq(modSeq);
-                save(mailbox, member);
-            }
+        Iterator<MailboxMessage> messages = findInMailbox(mailbox, set, FetchType.Metadata, UNLIMIT_MAX_SIZE);
+
+        MessageChangedFlags messageChangedFlags = messageMetadataMapper.updateFlags(mailbox, flagsUpdateCalculator, messages);
 
-            UpdatedFlags uFlags = new UpdatedFlags(member.getUid(), member.getModSeq(), originalFlags, newFlags);
-            
-            updatedFlags.add(uFlags);
-            
+        for (MailboxMessage mailboxMessage : messageChangedFlags.getChangedFlags()) {
+            save(mailbox, mailboxMessage);
         }
 
-        return updatedFlags.build().iterator();
+        return messageChangedFlags.getUpdatedFlags();
     }
 
     @Override
@@ -293,12 +280,8 @@ public class JPAMessageMapper extends JPATransactionalMapper implements MessageM
     private MessageMetaData copy(Mailbox mailbox, MessageUid uid, long modSeq, MailboxMessage original)
             throws MailboxException {
         MailboxMessage copy;
-        JPAMailbox currentMailbox;
-        if (mailbox instanceof JPAMailbox) {
-            currentMailbox = (JPAMailbox) mailbox;
-        } else {
-            currentMailbox = new JPAMailbox(mailbox);
-        }
+        JPAMailbox currentMailbox = JPAMailbox.from(mailbox);
+
         if (original instanceof JPAStreamingMailboxMessage) {
             copy = new JPAStreamingMailboxMessage(currentMailbox, uid, modSeq, original);
         } else if (original instanceof JPAEncryptedMailboxMessage) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java
index 95adcd7..f47f222 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailbox.java
@@ -96,6 +96,13 @@ public class JPAMailbox implements Mailbox {
     @Column(name = "MAILBOX_HIGHEST_MODSEQ", nullable = true)
     private long highestModSeq;
     
+    public static JPAMailbox from(Mailbox mailbox) {
+        if (mailbox instanceof JPAMailbox) {
+            return (JPAMailbox) mailbox;
+        }
+        return new JPAMailbox(mailbox);
+    }
+
     /**
      * JPA only
      */
@@ -230,5 +237,5 @@ public class JPAMailbox implements Mailbox {
     @Override
     public void setACL(MailboxACL acl) {
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
index 48896d7..8df5a47 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
@@ -61,6 +61,8 @@ import org.apache.openjpa.persistence.jdbc.ElementJoinColumn;
 import org.apache.openjpa.persistence.jdbc.ElementJoinColumns;
 import org.apache.openjpa.persistence.jdbc.Index;
 
+import com.google.common.base.Objects;
+
 /**
  * Abstract base class for JPA based implementations of
  * {@link DelegatingMailboxMessage}
@@ -297,32 +299,17 @@ public abstract class AbstractJPAMailboxMessage implements MailboxMessage {
 
     @Override
     public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + (int) (getMailboxId().getRawId() ^ (getMailboxId().getRawId() >>> 32));
-        result = PRIME * result + (int) (uid ^ (uid >>> 32));
-        return result;
+        return Objects.hashCode(getMailboxId().getRawId(), uid);
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final AbstractJPAMailboxMessage other = (AbstractJPAMailboxMessage) obj;
-        if (getMailboxId() != null) {
-            if (!getMailboxId().equals(other.getMailboxId()))
-                return false;
-        } else {
-            if (other.getMailboxId() != null)
-                return false;
+        if (obj instanceof AbstractJPAMailboxMessage) {
+            AbstractJPAMailboxMessage other = (AbstractJPAMailboxMessage) obj;
+            return Objects.equal(getMailboxId(), other.getMailboxId())
+                    && Objects.equal(uid, other.getUid());
         }
-        if (uid != other.uid)
-            return false;
-        return true;
+        return false;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
index 4f105d9..1e0715a 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
@@ -38,10 +38,10 @@ import com.google.common.base.Optional;
 import com.google.common.base.Throwables;
 
 public class TransactionalMessageMapper implements MessageMapper {
-    private final JPAMessageMapper wrapped;
+    private final JPAMessageMapper messageMapper;
 
-    public TransactionalMessageMapper(JPAMessageMapper wrapped) {
-        this.wrapped = wrapped;
+    public TransactionalMessageMapper(JPAMessageMapper messageMapper) {
+        this.messageMapper = messageMapper;
     }
     @Override
     public void endRequest() {
@@ -56,16 +56,16 @@ public class TransactionalMessageMapper implements MessageMapper {
     @Override
     public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox, MessageRange set, FetchType type, int limit)
             throws MailboxException {
-        return wrapped.findInMailbox(mailbox, set, type, limit);
+        return messageMapper.findInMailbox(mailbox, set, type, limit);
     }
 
     @Override
     public Map<MessageUid, MessageMetaData> expungeMarkedForDeletionInMailbox(final Mailbox mailbox, final MessageRange set)
             throws MailboxException {
-        Map<MessageUid, MessageMetaData> data = wrapped.execute(new Transaction<Map<MessageUid, MessageMetaData>>() {
+        Map<MessageUid, MessageMetaData> data = messageMapper.execute(new Transaction<Map<MessageUid, MessageMetaData>>() {
             @Override
             public Map<MessageUid, MessageMetaData> run() throws MailboxException {
-                return wrapped.expungeMarkedForDeletionInMailbox(mailbox, set);
+                return messageMapper.expungeMarkedForDeletionInMailbox(mailbox, set);
             }
         });
         return data;
@@ -73,21 +73,21 @@ public class TransactionalMessageMapper implements MessageMapper {
 
     @Override
     public long countMessagesInMailbox(Mailbox mailbox) throws MailboxException {
-        return wrapped.countMessagesInMailbox(mailbox);
+        return messageMapper.countMessagesInMailbox(mailbox);
     }
 
     @Override
     public long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException {
-        return wrapped.countUnseenMessagesInMailbox(mailbox);
+        return messageMapper.countUnseenMessagesInMailbox(mailbox);
     }
 
     @Override
     public void delete(final Mailbox mailbox, final MailboxMessage message) throws MailboxException {
         try {
-            wrapped.execute(new VoidTransaction() {
+            messageMapper.execute(new VoidTransaction() {
                 @Override
                 public void runVoid() throws MailboxException {
-                    wrapped.delete(mailbox, message);
+                    messageMapper.delete(mailbox, message);
                 }
             });
         } catch (MailboxException e) {
@@ -97,20 +97,20 @@ public class TransactionalMessageMapper implements MessageMapper {
 
     @Override
     public MessageUid findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException {
-        return wrapped.findFirstUnseenMessageUid(mailbox);
+        return messageMapper.findFirstUnseenMessageUid(mailbox);
     }
 
     @Override
     public List<MessageUid> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException {
-        return wrapped.findRecentMessageUidsInMailbox(mailbox);
+        return messageMapper.findRecentMessageUidsInMailbox(mailbox);
     }
 
     @Override
     public MessageMetaData add(final Mailbox mailbox, final MailboxMessage message) throws MailboxException {
-        MessageMetaData data = wrapped.execute(new Transaction<MessageMetaData>() {
+        MessageMetaData data = messageMapper.execute(new Transaction<MessageMetaData>() {
             @Override
             public MessageMetaData run() throws MailboxException {
-                return wrapped.add(mailbox, message);
+                return messageMapper.add(mailbox, message);
             }
         });
         return data;
@@ -119,10 +119,10 @@ public class TransactionalMessageMapper implements MessageMapper {
     @Override
     public Iterator<UpdatedFlags> updateFlags(final Mailbox mailbox, final FlagsUpdateCalculator flagsUpdateCalculator,
             final MessageRange set) throws MailboxException {
-        Iterator<UpdatedFlags> data = wrapped.execute(new Transaction<Iterator<UpdatedFlags>>() {
+        Iterator<UpdatedFlags> data = messageMapper.execute(new Transaction<Iterator<UpdatedFlags>>() {
             @Override
             public Iterator<UpdatedFlags> run() throws MailboxException {
-                return wrapped.updateFlags(mailbox, flagsUpdateCalculator, set);
+                return messageMapper.updateFlags(mailbox, flagsUpdateCalculator, set);
             }
         });
         return data;
@@ -130,10 +130,10 @@ public class TransactionalMessageMapper implements MessageMapper {
 
     @Override
     public MessageMetaData copy(final Mailbox mailbox, final MailboxMessage original) throws MailboxException {
-        MessageMetaData data = wrapped.execute(new Transaction<MessageMetaData>() {
+        MessageMetaData data = messageMapper.execute(new Transaction<MessageMetaData>() {
             @Override
             public MessageMetaData run() throws MailboxException {
-                return wrapped.copy(mailbox, original);
+                return messageMapper.copy(mailbox, original);
             }
         });
         return data;
@@ -141,17 +141,17 @@ public class TransactionalMessageMapper implements MessageMapper {
 
     @Override
     public MessageMetaData move(Mailbox mailbox, MailboxMessage original) throws MailboxException {
-        return wrapped.move(mailbox, original);
+        return messageMapper.move(mailbox, original);
     }
 
     @Override
     public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException {
-        return wrapped.getLastUid(mailbox);
+        return messageMapper.getLastUid(mailbox);
     }
 
     @Override
     public long getHighestModSeq(Mailbox mailbox) throws MailboxException {
-        return wrapped.getHighestModSeq(mailbox);
+        return messageMapper.getHighestModSeq(mailbox);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMetadata.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMetadata.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMetadata.java
deleted file mode 100644
index 1907cf0..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMetadata.java
+++ /dev/null
@@ -1,69 +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.mailbox.store.mail;
-
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-
-import com.google.common.base.Optional;
-
-public class MessageMetadata {
-    private final MailboxSession mailboxSession;
-    private final UidProvider uidProvider;
-    private final ModSeqProvider modSeqProvider;
-
-    public MessageMetadata(MailboxSession mailboxSession, UidProvider uidProvider, ModSeqProvider modSeqProvider) {
-        this.mailboxSession = mailboxSession;
-        this.uidProvider = uidProvider;
-        this.modSeqProvider = modSeqProvider;
-    }
-    
-    public long getHighestModSeq(Mailbox mailbox) throws MailboxException {
-        return modSeqProvider.highestModSeq(mailboxSession, mailbox);
-    }
-
-    public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException {
-        return uidProvider.lastUid(mailboxSession, mailbox);
-    }
-    
-
-    public MessageUid nextUid(Mailbox mailbox) throws MailboxException {
-        return uidProvider.nextUid(mailboxSession, mailbox);
-    }
-
-    public long nextModSeq(Mailbox mailbox) throws MailboxException {
-        if (modSeqProvider != null) {
-            return modSeqProvider.nextModSeq(mailboxSession, mailbox);
-        }
-        return -1;
-    }
-
-    public void enrichMessage(Mailbox mailbox, MailboxMessage message) throws MailboxException { 
-        message.setUid(nextUid(mailbox));
-        
-        if (modSeqProvider != null) {
-            message.setModSeq(nextModSeq(mailbox));
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageUtils.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageUtils.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageUtils.java
new file mode 100644
index 0000000..7cdcab0
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageUtils.java
@@ -0,0 +1,118 @@
+/****************************************************************
+ * 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;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.UpdatedFlags;
+import org.apache.james.mailbox.store.FlagsUpdateCalculator;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+public class MessageUtils {
+    private final MailboxSession mailboxSession;
+    private final UidProvider uidProvider;
+    private final ModSeqProvider modSeqProvider;
+
+    public MessageUtils(MailboxSession mailboxSession, UidProvider uidProvider, ModSeqProvider modSeqProvider) {
+        Preconditions.checkNotNull(uidProvider);
+        Preconditions.checkNotNull(modSeqProvider);
+        this.mailboxSession = mailboxSession;
+        this.uidProvider = uidProvider;
+        this.modSeqProvider = modSeqProvider;
+    }
+    
+    public long getHighestModSeq(Mailbox mailbox) throws MailboxException {
+        return modSeqProvider.highestModSeq(mailboxSession, mailbox);
+    }
+
+    public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException {
+        return uidProvider.lastUid(mailboxSession, mailbox);
+    }
+    
+
+    public MessageUid nextUid(Mailbox mailbox) throws MailboxException {
+        return uidProvider.nextUid(mailboxSession, mailbox);
+    }
+
+    public long nextModSeq(Mailbox mailbox) throws MailboxException {
+        return modSeqProvider.nextModSeq(mailboxSession, mailbox);
+    }
+
+    public void enrichMessage(Mailbox mailbox, MailboxMessage message) throws MailboxException { 
+        message.setUid(nextUid(mailbox));
+        message.setModSeq(nextModSeq(mailbox));
+    }
+
+    public MessageChangedFlags updateFlags(Mailbox mailbox, FlagsUpdateCalculator flagsUpdateCalculator, 
+            Iterator<MailboxMessage> messages) throws MailboxException {
+        ImmutableList.Builder<UpdatedFlags> updatedFlags = ImmutableList.builder();
+        ImmutableList.Builder<MailboxMessage> changedFlags = ImmutableList.builder();
+
+        long modSeq = nextModSeq(mailbox);
+
+        while(messages.hasNext()) {
+            MailboxMessage member = messages.next();
+            Flags originalFlags = member.createFlags();
+            member.setFlags(flagsUpdateCalculator.buildNewFlags(originalFlags));
+            Flags newFlags = member.createFlags();
+            if (UpdatedFlags.flagsChanged(originalFlags, newFlags)) {
+                member.setModSeq(modSeq);
+                changedFlags.add(member);
+            }
+
+            UpdatedFlags uFlags = new UpdatedFlags(member.getUid(), member.getModSeq(), originalFlags, newFlags);
+
+            updatedFlags.add(uFlags);
+
+        }
+
+        return new MessageChangedFlags(updatedFlags.build().iterator(), changedFlags.build());
+    }
+
+    
+    public class MessageChangedFlags {
+        private final Iterator<UpdatedFlags> updatedFlags;
+        private final List<MailboxMessage> changedFlags;
+
+        public MessageChangedFlags(Iterator<UpdatedFlags> updatedFlags, List<MailboxMessage> changedFlags) {
+            this.updatedFlags = updatedFlags;
+            this.changedFlags = changedFlags;
+        }
+
+        public Iterator<UpdatedFlags> getUpdatedFlags() {
+            return updatedFlags;
+        }
+
+        public List<MailboxMessage> getChangedFlags() {
+            return changedFlags;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/MessageUtilsTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/MessageUtilsTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/MessageUtilsTest.java
new file mode 100644
index 0000000..a58d645
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/MessageUtilsTest.java
@@ -0,0 +1,117 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Date;
+
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class MessageUtilsTest {
+    private static final MailboxSession mailboxSession = new MockMailboxSession("user");
+    private static final MessageUid MESSAGE_UID = MessageUid.of(1);
+    private static final MessageId MESSAGE_ID = new DefaultMessageId();
+    private static final int BODY_START = 16;
+    private static final String CONTENT = "anycontent";
+    
+    @Mock private ModSeqProvider modSeqProvider;
+    @Mock private UidProvider uidProvider;
+    @Mock private Mailbox mailbox;
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    private MessageUtils messageUtils;
+    private MailboxMessage message;
+
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+        messageUtils = new MessageUtils(mailboxSession, uidProvider, modSeqProvider);
+        message = new SimpleMailboxMessage(MESSAGE_ID, new Date(), CONTENT.length(), BODY_START, new SharedByteArrayInputStream(CONTENT.getBytes()), new Flags(), new PropertyBuilder(), mailbox.getMailboxId());
+    }
+    @Test
+    public void newInstanceShouldFailWhenNullUidProvider() {
+        expectedException.expect(NullPointerException.class);
+        new MessageUtils(mailboxSession, null, modSeqProvider);
+    }
+    
+    @Test
+    public void newInstanceShouldFailWhenNullModSeqProvider() {
+        expectedException.expect(NullPointerException.class);
+        new MessageUtils(mailboxSession, uidProvider, null);
+    }
+    
+    @Test
+    public void getHighestModSeqShouldCallModSeqProvider() throws Exception {
+        messageUtils.getHighestModSeq(mailbox);
+        verify(modSeqProvider).highestModSeq(eq(mailboxSession), eq(mailbox));
+    }
+    
+    @Test
+    public void nextModSeqShouldCallModSeqProvider() throws Exception {
+        messageUtils.nextModSeq(mailbox);
+        verify(modSeqProvider).nextModSeq(eq(mailboxSession), eq(mailbox));
+    }
+    
+    @Test
+    public void getLastUidShouldCallUidProvider() throws Exception {
+        messageUtils.getLastUid(mailbox);
+        verify(uidProvider).lastUid(eq(mailboxSession), eq(mailbox));
+    }
+    
+    @Test
+    public void nextUidShouldCallUidProvider() throws Exception {
+        messageUtils.nextUid(mailbox);
+        verify(uidProvider).nextUid(eq(mailboxSession), eq(mailbox));
+    }
+    
+    @Test
+    public void enrichMesageShouldEnrichUidAndModSeq() throws Exception {
+        when(uidProvider.nextUid(eq(mailboxSession), eq(mailbox))).thenReturn(MESSAGE_UID);
+        when(modSeqProvider.nextModSeq(eq(mailboxSession), eq(mailbox))).thenReturn(11L);
+
+        messageUtils.enrichMessage(mailbox, message);
+        
+        assertThat(message.getUid()).isEqualTo(MESSAGE_UID);
+        assertThat(message.getModSeq()).isEqualTo(11L);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssert.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssert.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssert.java
new file mode 100644
index 0000000..7772ea1
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssert.java
@@ -0,0 +1,145 @@
+/****************************************************************
+ * 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 java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageId;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.base.Throwables;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Lists;
+
+public class ListMessageAssert {
+    private final List<MailboxMessage> actual;
+
+    private final List<InnerMessage> messageToInnerMessage(List<MailboxMessage> messages) {
+        return FluentIterable.from(messages).transform(new Function<MailboxMessage, InnerMessage>() {
+            @Override
+            public InnerMessage apply(MailboxMessage input) {
+                try {
+                    return new InnerMessage(input.getMessageId(), input.getUid(), input.getMailboxId(), input.getInternalDate(), input.getBodyOctets(), 
+                            input.getFullContentOctets(), input.getMediaType(), input.getSubType(), IOUtils.toString(input.getFullContent()));
+                } catch (IOException e) {
+                    Throwables.propagate(e);
+                    return null;
+                }
+            }
+            
+        }).toList();
+    }
+
+    private ListMessageAssert(List<MailboxMessage> actual) {
+        this.actual = actual;
+    }
+
+    public static ListMessageAssert assertMessages(List<MailboxMessage> actual) {
+        return new ListMessageAssert(actual);
+    }
+
+    public void containOnly(MailboxMessage... expecteds) throws IOException {
+        assertThat(messageToInnerMessage(actual)).containsOnlyElementsOf(messageToInnerMessage(Lists.newArrayList(expecteds)));
+    }
+
+    private final class InnerMessage {
+        private final MessageUid uid;
+        private final MailboxId mailboxId;
+        private final Date internalDate;
+        private final long bodyOctets;
+        private final long fullContentOctets;
+        private final String mediaType;
+        private final String subType;
+        private final String content;
+
+        public InnerMessage(MessageId id, MessageUid uid, MailboxId mailboxId, Date internalDate, long bodyOctets,
+                long fullContentOctets, String mediaType, String subType, String content) {
+            this.uid = uid;
+            this.mailboxId = mailboxId;
+            this.internalDate = internalDate;
+            this.bodyOctets = bodyOctets;
+            this.fullContentOctets = fullContentOctets;
+            this.mediaType = mediaType;
+            this.subType = subType;
+            this.content = content;
+        }
+
+        public MessageUid getUid() {
+            return uid;
+        }
+
+        public MailboxId getMailboxId() {
+            return mailboxId;
+        }
+
+        public Date getInternalDate() {
+            return internalDate;
+        }
+
+        public long getBodyOctets() {
+            return bodyOctets;
+        }
+
+        public long getFullContentOctets() {
+            return fullContentOctets;
+        }
+
+        public String getMediaType() {
+            return mediaType;
+        }
+
+        public String getSubType() {
+            return subType;
+        }
+
+        public String getContent() {
+            return content;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hashCode(uid, mailboxId, internalDate, bodyOctets, fullContentOctets, mediaType, subType, content);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj instanceof InnerMessage) {
+                InnerMessage o = (InnerMessage)obj;
+                return Objects.equal(uid, o.getUid())
+                    && Objects.equal(mailboxId, o.getMailboxId())
+                    && Objects.equal(internalDate, o.getInternalDate())
+                    && Objects.equal(bodyOctets, o.getBodyOctets())
+                    && Objects.equal(fullContentOctets, o.getFullContentOctets())
+                    && Objects.equal(mediaType, o.getMediaType())
+                    && Objects.equal(subType, o.getSubType())
+                    && Objects.equal(content, o.getContent());
+            }
+            return false;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssertTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssertTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssertTest.java
new file mode 100644
index 0000000..b123739
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessageAssertTest.java
@@ -0,0 +1,230 @@
+/****************************************************************
+ * 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.apache.james.mailbox.store.mail.model.ListMessageAssert.assertMessages;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageAttachment;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.store.TestId;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class ListMessageAssertTest {
+    private static final String BODY_CONTENT2 = "Subject: Test2 \n\nBody2\n.\n";
+    private static final String BODY_CONTENT1 = "Subject: Test1 \n\nBody1\n.\n";
+    private static final int BODY_START = 16;
+    private static final int UID_VALIDITY = 42;
+    private static final MailboxId MAILBOX_ID = TestId.of(1);
+    private static final MessageUid MESSAGE_UID = MessageUid.of(2);
+    private static final MessageId MESSAGE_ID = new DefaultMessageId();
+    private static final Date INTERNAL_DATE = new Date();
+
+    private Mailbox benwaInboxMailbox;
+
+    private MailboxMessage message1;
+    private MailboxMessage message2;
+    
+    @Before
+    public void setUp() {
+        benwaInboxMailbox = createMailbox(new MailboxPath("#private", "user", "INBOX"));
+
+        message1 = createMessage(benwaInboxMailbox, MESSAGE_ID, BODY_CONTENT1, BODY_START, new PropertyBuilder());
+        message2 = createMessage(benwaInboxMailbox, MESSAGE_ID, BODY_CONTENT2, BODY_START, new PropertyBuilder());
+    }
+
+    @Test
+    public void containsOnlyShouldWork() throws IOException {
+        List<MailboxMessage> actual = ImmutableList.of(message1, message2);
+        assertMessages(actual).containOnly(createMailboxMessage(MAILBOX_ID, MESSAGE_ID, MESSAGE_UID, INTERNAL_DATE, BODY_CONTENT1, BODY_START, new PropertyBuilder()),
+                createMailboxMessage(MAILBOX_ID, MESSAGE_ID, MESSAGE_UID, INTERNAL_DATE, BODY_CONTENT2, BODY_START, new PropertyBuilder()));
+    }
+
+    @Test(expected = AssertionError.class)
+    public void containsOnlyShouldThrowExceptionWhenHavingElementDoesNotBelongToList() throws IOException {
+        List<MailboxMessage> actual = ImmutableList.of(message1);
+        assertMessages(actual).containOnly(createMailboxMessage(MAILBOX_ID, MESSAGE_ID, MESSAGE_UID, INTERNAL_DATE, BODY_CONTENT2, BODY_START, new PropertyBuilder()));
+    }
+
+    private MailboxMessage createMailboxMessage(final MailboxId mailboxId, final MessageId messageId, final MessageUid uid,
+            final Date internalDate, final String content, final int bodyStart, final PropertyBuilder propertyBuilder) {
+        return new MailboxMessage() {
+            @Override
+            public MailboxId getMailboxId() {
+                return mailboxId;
+            }
+
+            @Override
+            public MessageUid getUid() {
+                return uid;
+            }
+
+            @Override
+            public void setUid(MessageUid uid) {
+
+            }
+
+            @Override
+            public void setModSeq(long modSeq) {
+
+            }
+
+            @Override
+            public long getModSeq() {
+                return 0;
+            }
+
+            @Override
+            public boolean isAnswered() {
+                return false;
+            }
+
+            @Override
+            public boolean isDeleted() {
+                return false;
+            }
+
+            @Override
+            public boolean isDraft() {
+                return false;
+            }
+
+            @Override
+            public boolean isFlagged() {
+                return false;
+            }
+
+            @Override
+            public boolean isRecent() {
+                return false;
+            }
+
+            @Override
+            public boolean isSeen() {
+                return false;
+            }
+
+            @Override
+            public void setFlags(Flags flags) {
+
+            }
+
+            @Override
+            public Flags createFlags() {
+                return null;
+            }
+
+            @Override
+            public int compareTo(MailboxMessage o) {
+                return 0;
+            }
+
+            @Override
+            public MessageId getMessageId() {
+                return messageId;
+            }
+
+            @Override
+            public Date getInternalDate() {
+                return internalDate;
+            }
+
+            @Override
+            public InputStream getBodyContent() throws IOException {
+                return null;
+            }
+
+            @Override
+            public String getMediaType() {
+                return null;
+            }
+
+            @Override
+            public String getSubType() {
+                return null;
+            }
+
+            @Override
+            public long getBodyOctets() {
+                return content.length() - bodyStart;
+            }
+
+            @Override
+            public long getFullContentOctets() {
+                return content.length();
+            }
+
+            @Override
+            public Long getTextualLineCount() {
+                return null;
+            }
+
+            @Override
+            public InputStream getHeaderContent() throws IOException {
+                return null;
+            }
+
+            @Override
+            public InputStream getFullContent() throws IOException {
+                return new SharedByteArrayInputStream(content.getBytes());
+            }
+
+            @Override
+            public List<Property> getProperties() {
+                return null;
+            }
+
+            @Override
+            public List<MessageAttachment> getAttachments() {
+                return null;
+            }
+        };
+    }
+
+    private SimpleMailbox createMailbox(MailboxPath mailboxPath) {
+        SimpleMailbox mailbox = new SimpleMailbox(mailboxPath, UID_VALIDITY);
+        mailbox.setMailboxId(MAILBOX_ID);
+
+        return mailbox;
+    }
+
+    private MailboxMessage createMessage(Mailbox mailbox, MessageId messageId, String content, int bodyStart, PropertyBuilder propertyBuilder) {
+        SimpleMailboxMessage simpleMailboxMessage = new SimpleMailboxMessage(messageId, INTERNAL_DATE, content.length(), bodyStart, new SharedByteArrayInputStream(content.getBytes()), new Flags(), propertyBuilder, mailbox.getMailboxId());
+        simpleMailboxMessage.setUid(MESSAGE_UID);
+        return simpleMailboxMessage;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssert.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssert.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssert.java
new file mode 100644
index 0000000..4c22bdd
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssert.java
@@ -0,0 +1,99 @@
+/****************************************************************
+ * 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 java.util.List;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.FluentIterable;
+
+public class ListMessagePropertiesAssert {
+    private final List<InnerProperty> propertiesToInnerProperties(List<Property> properties) {
+        return FluentIterable.from(properties)
+            .transform(propertyToInnerProperty())
+            .toList();
+    }
+
+    private final Function<Property, InnerProperty> propertyToInnerProperty() {
+        return new Function<Property, InnerProperty>() {
+            @Override
+            public InnerProperty apply(Property input) {
+                return new InnerProperty(input.getNamespace(), input.getLocalName(), input.getValue());
+            }
+        };
+    }
+
+    public static ListMessagePropertiesAssert assertProperties(List<Property> actual) {
+        return new ListMessagePropertiesAssert(actual);
+    }
+
+    private final List<Property> actual;
+
+    private ListMessagePropertiesAssert(List<Property> actual) {
+        this.actual = actual;
+    }
+
+    public void containsOnly(List<Property> expected) {
+        assertThat(propertiesToInnerProperties(actual)).containsOnlyElementsOf(propertiesToInnerProperties(expected));
+    }
+    
+    private final class InnerProperty {
+        private final String namespace;
+        private final String name;
+        private final String value;
+
+        public InnerProperty(String namespace, String name, String value) {
+            this.namespace = namespace;
+            this.name = name;
+            this.value = value;
+        }
+
+        public String getNamespace() {
+            return namespace;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hashCode(namespace, name, value);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj instanceof InnerProperty) {
+                InnerProperty o = (InnerProperty)obj;
+                return Objects.equal(namespace, o.getNamespace())
+                    && Objects.equal(name, o.getName())
+                    && Objects.equal(value, o.getValue());
+            }
+            return false;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssertTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssertTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssertTest.java
new file mode 100644
index 0000000..ba33af8
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/ListMessagePropertiesAssertTest.java
@@ -0,0 +1,97 @@
+/****************************************************************
+ * 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.apache.james.mailbox.store.mail.model.ListMessagePropertiesAssert.assertProperties;
+
+import java.util.List;
+
+import org.apache.james.mailbox.store.SimpleProperty;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class ListMessagePropertiesAssertTest {
+    private static final String OTHER_VALUE = "US-ASCII";
+    private static final String OTHER_LOCAL_NAME = StandardNames.MIME_CONTENT_TYPE_PARAMETER_CHARSET_NAME;
+    private static final String OTHER_NAMESPACE = StandardNames.MIME_CONTENT_TYPE_PARAMETER_SPACE;
+    private static final String VALUE = "7bit";
+    private static final String LOCAL_NAME = StandardNames.MIME_CONTENT_TRANSFER_ENCODING_NAME;
+    private static final String NAMESPACE = StandardNames.NAMESPACE_RFC_2045;
+
+    private static final Property PROPERTY1 = new SimpleProperty(NAMESPACE, LOCAL_NAME, VALUE);
+    private static final Property PROPERTY2 = new SimpleProperty(OTHER_NAMESPACE, OTHER_LOCAL_NAME, OTHER_VALUE);
+    
+    private List<Property> actual;
+    
+    @Before
+    public void setUp() {
+        actual = ImmutableList.of(PROPERTY1, PROPERTY2);
+    }
+    
+    @Test
+    public void containsOnlyShouldWork() {
+        assertProperties(actual).containsOnly(ImmutableList.of(createProperty(NAMESPACE, LOCAL_NAME, VALUE),
+            createProperty(OTHER_NAMESPACE, OTHER_LOCAL_NAME, OTHER_VALUE)));
+    }
+    
+    @Test(expected = AssertionError.class)
+    public void containsOnlyShouldFailWhenNotEnoughElement() {
+        assertProperties(actual).containsOnly(ImmutableList.of(createProperty(NAMESPACE, LOCAL_NAME, VALUE)));
+    }
+
+    @Test(expected = AssertionError.class)
+    public void containsOnlyShouldFailWhenNamespaceMismatch() {
+        assertProperties(actual).containsOnly(ImmutableList.of(createProperty(NAMESPACE, LOCAL_NAME, VALUE),
+            createProperty(OTHER_NAMESPACE, LOCAL_NAME, VALUE)));
+    }
+
+    @Test(expected = AssertionError.class)
+    public void containsOnlyShouldFailWhenNameMismatch() {
+        assertProperties(actual).containsOnly(ImmutableList.of(createProperty(NAMESPACE, LOCAL_NAME, VALUE),
+            createProperty(NAMESPACE, OTHER_LOCAL_NAME, VALUE)));
+    }
+
+    @Test(expected = AssertionError.class)
+    public void containsOnlyShouldFailWhenValueMismatch() {
+        assertProperties(actual).containsOnly(ImmutableList.of(createProperty(NAMESPACE, LOCAL_NAME, VALUE),
+            createProperty(NAMESPACE, LOCAL_NAME, OTHER_VALUE)));
+    }
+
+    private Property createProperty(final String namespace, final String name, final String value) {
+        return new Property() {
+            @Override
+            public String getValue() {
+                return value;
+            }
+            
+            @Override
+            public String getNamespace() {
+                return namespace;
+            }
+            
+            @Override
+            public String getLocalName() {
+                return name;
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
index d42a1cf..c45b5b7 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
@@ -19,6 +19,9 @@
 
 package org.apache.james.mailbox.store.mail.model;
 
+import static org.apache.james.mailbox.store.mail.model.ListMessageAssert.assertMessages;
+import static org.apache.james.mailbox.store.mail.model.ListMessagePropertiesAssert.assertProperties;
+import static org.apache.james.mailbox.store.mail.model.MessageAssert.assertThat;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.IOException;
@@ -33,13 +36,13 @@ import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MessageManager.FlagsUpdateMode;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.FlagsUpdateCalculator;
+import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
@@ -54,6 +57,7 @@ import org.xenei.junit.contract.ContractTest;
 import org.xenei.junit.contract.IProducer;
 
 import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
 
 @Contract(MapperProvider.class)
 public class MessageMapperTest<T extends MapperProvider> {
@@ -67,16 +71,17 @@ public class MessageMapperTest<T extends MapperProvider> {
     private IProducer<T> producer;
     private MapperProvider mapperProvider;
     private MessageMapper messageMapper;
+    private MailboxMapper mailboxMapper;
 
     private SimpleMailbox benwaInboxMailbox;
     private SimpleMailbox benwaWorkMailbox;
     
-    private SimpleMailboxMessage message1;
-    private SimpleMailboxMessage message2;
-    private SimpleMailboxMessage message3;
-    private SimpleMailboxMessage message4;
-    private SimpleMailboxMessage message5;
-    private SimpleMailboxMessage message6;
+    private MailboxMessage message1;
+    private MailboxMessage message2;
+    private MailboxMessage message3;
+    private MailboxMessage message4;
+    private MailboxMessage message5;
+    private MailboxMessage message6;
 
     @Rule
     public ExpectedException expected = ExpectedException.none();
@@ -90,7 +95,12 @@ public class MessageMapperTest<T extends MapperProvider> {
         Assume.assumeFalse(mapperProvider.getNotImplemented().contains(MapperProvider.Capabilities.MESSAGE));
 
         this.messageMapper = mapperProvider.createMessageMapper();
+        this.mailboxMapper = mapperProvider.createMailboxMapper();
 
+        initData();
+    }
+
+    private void initData() throws MailboxException {
         benwaInboxMailbox = createMailbox(new MailboxPath("#private", "benwa", "INBOX"));
         benwaWorkMailbox = createMailbox( new MailboxPath("#private", "benwa", "INBOX"+DELIMITER+"work"));
 
@@ -139,7 +149,10 @@ public class MessageMapperTest<T extends MapperProvider> {
     @ContractTest
     public void mailboxUnSeenCountShouldBeDecrementedAfterAMessageIsMarkedSeen() throws MailboxException {
         saveMessages();
-        messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.REPLACE), message1.getUid().toRange()).hasNext();
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.REPLACE);
+
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
         assertThat(messageMapper.countUnseenMessagesInMailbox(benwaInboxMailbox)).isEqualTo(4);
     }
 
@@ -170,8 +183,9 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         message6.setUid(messageMapper.getLastUid(benwaInboxMailbox).get().next());
         messageMapper.delete(benwaInboxMailbox, message6);
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
-            .containsOnly(message1, message2, message3, message4, message5);
+
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message1, message2, message3, message4, message5);
     }
 
     @ContractTest
@@ -184,8 +198,8 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         MessageMapper.FetchType fetchType = MessageMapper.FetchType.Full;
         int limit =10;
-        MessageAssert.assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message1.getUid()), fetchType, limit).next())
-            .isEqualTo(message1, fetchType);
+        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message1.getUid()), fetchType, limit).next())
+            .isEqualToWithoutAttachment(message1, fetchType);
     }
 
     @ContractTest
@@ -193,16 +207,17 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper
                 .findInMailbox(benwaInboxMailbox, MessageRange.range(message1.getUid(), message4.getUid()), MessageMapper.FetchType.Full, LIMIT);
-        assertThat(retrievedMessageIterator).containsOnly(message1, message2, message3, message4);
-    }
 
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message1, message2, message3, message4);
+    }
+    
     @ContractTest
     public void messagesCanBeRetrievedInMailboxWithRangeTypeRangeContainingAHole() throws MailboxException, IOException {
         saveMessages();
         messageMapper.delete(benwaInboxMailbox, message3);
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper
             .findInMailbox(benwaInboxMailbox, MessageRange.range(message1.getUid(), message4.getUid()), MessageMapper.FetchType.Full, LIMIT);
-        assertThat(retrievedMessageIterator).containsOnly(message1, message2, message4);
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message1, message2, message4);
     }
 
     @ContractTest
@@ -210,7 +225,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper
                 .findInMailbox(benwaInboxMailbox, MessageRange.from(message3.getUid()), MessageMapper.FetchType.Full, LIMIT);
-        assertThat(retrievedMessageIterator).containsOnly(message3, message4, message5);
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message3, message4, message5);
     }
 
     @ContractTest
@@ -219,14 +234,14 @@ public class MessageMapperTest<T extends MapperProvider> {
         messageMapper.delete(benwaInboxMailbox, message4);
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper
                 .findInMailbox(benwaInboxMailbox, MessageRange.from(message3.getUid()), MessageMapper.FetchType.Full, LIMIT);
-        assertThat(retrievedMessageIterator).containsOnly(message3, message5);
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message3, message5);
     }
 
     @ContractTest
     public void messagesCanBeRetrievedInMailboxWithRangeTypeAll() throws MailboxException, IOException {
         saveMessages();
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
-            .containsOnly(message1, message2, message3, message4, message5);
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message1, message2, message3, message4, message5);
     }
 
     @ContractTest
@@ -235,7 +250,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         messageMapper.delete(benwaInboxMailbox, message1);
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper
                 .findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
-        assertThat(retrievedMessageIterator).containsOnly(message2, message3, message4, message5);
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message2, message3, message4, message5);
     }
 
     @ContractTest
@@ -243,7 +258,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         MessageMapper.FetchType fetchType = MessageMapper.FetchType.Metadata;
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message1.getUid()), fetchType, LIMIT);
-        MessageAssert.assertThat(retrievedMessageIterator.next()).isEqualTo(message1, fetchType);
+        assertThat(retrievedMessageIterator.next()).isEqualTo(message1, fetchType);
         assertThat(retrievedMessageIterator).isEmpty();
     }
 
@@ -252,7 +267,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         MessageMapper.FetchType fetchType = MessageMapper.FetchType.Headers;
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message1.getUid()), fetchType, LIMIT);
-        MessageAssert.assertThat(retrievedMessageIterator.next()).isEqualTo(message1, fetchType);
+        assertThat(retrievedMessageIterator.next()).isEqualTo(message1, fetchType);
         assertThat(retrievedMessageIterator).isEmpty();
     }
 
@@ -261,7 +276,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         MessageMapper.FetchType fetchType = MessageMapper.FetchType.Body;
         Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message1.getUid()), fetchType, LIMIT);
-        MessageAssert.assertThat(retrievedMessageIterator.next()).isEqualTo(message1, fetchType);
+        assertThat(retrievedMessageIterator.next()).isEqualToWithoutAttachment(message1, fetchType);
         assertThat(retrievedMessageIterator).isEmpty();
     }
 
@@ -315,8 +330,9 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void expungeMarkedForDeletionInMailboxShouldReturnEmptyResultWhenNoMessageInMailboxIsDeleted() throws MailboxException, IOException {
         saveMessages();
         assertThat(messageMapper.expungeMarkedForDeletionInMailbox(benwaInboxMailbox, MessageRange.all())).isEmpty();
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
-            .containsOnly(message1, message2, message3, message4, message5);
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message1, message2, message3, message4, message5);
     }
 
     @ContractTest
@@ -331,8 +347,10 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void expungeShouldModifyUnderlyingStorageWithRangeAll() throws MailboxException, IOException {
         saveMessages();
         markThenPerformExpunge(MessageRange.all());
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
-            .containsOnly(message2, message3, message5);
+
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message2, message3, message5);
     }
 
     @ContractTest
@@ -347,8 +365,10 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void expungeShouldModifyUnderlyingStorageWithRangeOne() throws MailboxException, IOException {
         saveMessages();
         markThenPerformExpunge(MessageRange.one(message1.getUid()));
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
-            .containsOnly(message4, message2, message3, message5);
+
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message4, message2, message3, message5);
     }
 
     @ContractTest
@@ -363,8 +383,10 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void expungeShouldModifyUnderlyingStorageWithRangeFrom() throws MailboxException, IOException {
         saveMessages();
         markThenPerformExpunge(MessageRange.from(message3.getUid()));
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
-            .containsOnly(message1, message2, message3, message5);
+
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message1, message2, message3, message5);
     }
 
     @ContractTest
@@ -379,8 +401,10 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void expungeShouldModifyUnderlyingStorageWithRange() throws MailboxException, IOException {
         saveMessages();
         markThenPerformExpunge(MessageRange.range(message3.getUid(), message5.getUid()));
-        assertThat(messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT))
-            .containsOnly(message1, message2, message3, message5);
+
+        Iterator<MailboxMessage> retrievedMessageIterator = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.all(), MessageMapper.FetchType.Full, LIMIT);
+
+        assertMessages(Lists.newArrayList(retrievedMessageIterator)).containOnly(message1, message2, message3, message5);
     }
 
     @ContractTest
@@ -455,7 +479,7 @@ public class MessageMapperTest<T extends MapperProvider> {
             LIMIT)
             .next();
 
-        MessageAssert.assertThat(result).isEqualToWithoutUid(message7, MessageMapper.FetchType.Full);
+        assertThat(result).isEqualToWithoutUidAndAttachment(message7, MessageMapper.FetchType.Full);
         assertThat(result.getUid()).isEqualTo(messageMapper.getLastUid(benwaInboxMailbox).get());
     }
 
@@ -516,14 +540,16 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void flagsReplacementShouldReplaceStoredMessageFlags() throws MailboxException {
         saveMessages();
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.FLAGGED), FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid()));
-        MessageAssert.assertThat(retrieveMessageFromStorage(message1)).hasFlags(new Flags(Flags.Flag.FLAGGED));
+        assertThat(retrieveMessageFromStorage(message1)).hasFlags(new Flags(Flags.Flag.FLAGGED));
     }
 
     @ContractTest
     public void flagsReplacementShouldReturnAnUpdatedFlagHighlightingTheReplacement() throws MailboxException {
         saveMessages();
         long modSeq = messageMapper.getHighestModSeq(benwaInboxMailbox);
-        assertThat(messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.FLAGGED), FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid())))
+        Iterator<UpdatedFlags> updatedFlags = messageMapper.updateFlags(benwaInboxMailbox, 
+                new FlagsUpdateCalculator(new Flags(Flags.Flag.FLAGGED), FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid()));
+        assertThat(Lists.newArrayList(updatedFlags))
             .containsOnly(new UpdatedFlags(message1.getUid(), modSeq + 1, new Flags(), new Flags(Flags.Flag.FLAGGED)));
     }
 
@@ -541,7 +567,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.FLAGGED), FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid()));
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.ADD), MessageRange.one(message1.getUid()));
-        MessageAssert.assertThat(retrieveMessageFromStorage(message1)).hasFlags(new FlagsBuilder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build());
+        assertThat(retrieveMessageFromStorage(message1)).hasFlags(new FlagsBuilder().add(Flags.Flag.SEEN, Flags.Flag.FLAGGED).build());
     }
 
     @ContractTest
@@ -558,7 +584,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         saveMessages();
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new FlagsBuilder().add(Flags.Flag.FLAGGED, Flags.Flag.SEEN).build(), FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid()));
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.REMOVE), MessageRange.one(message1.getUid()));
-        MessageAssert.assertThat(retrieveMessageFromStorage(message1)).hasFlags(new Flags(Flags.Flag.FLAGGED));
+        assertThat(retrieveMessageFromStorage(message1)).hasFlags(new Flags(Flags.Flag.FLAGGED));
     }
 
     @ContractTest
@@ -589,27 +615,29 @@ public class MessageMapperTest<T extends MapperProvider> {
         propBuilder.setProperty(StandardNames.NAMESPACE_RFC_2045, StandardNames.MIME_CONTENT_TRANSFER_ENCODING_NAME, "7bit");
         propBuilder.setProperty(StandardNames.MIME_CONTENT_TYPE_PARAMETER_SPACE, StandardNames.MIME_CONTENT_TYPE_PARAMETER_CHARSET_NAME, "US-ASCII");
 
-        SimpleMailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStored \n\nBody\n.\n", BODY_START, propBuilder);
+        MailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStored \n\nBody\n.\n", BODY_START, propBuilder);
         MessageMetaData messageMetaData = messageMapper.add(benwaInboxMailbox, messageWithProperties);
         MailboxMessage message = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(messageMetaData.getUid()), FetchType.Body, 1).next();
-        assertThat(message.getProperties()).containsOnlyElementsOf(propBuilder.toProperties());
-    }
 
+        assertProperties(message.getProperties()).containsOnly(propBuilder.toProperties());
+    }
+    
     @ContractTest
     public void messagePropertiesShouldBeStoredWhenDuplicateEntries() throws Exception {
         PropertyBuilder propBuilder = new PropertyBuilder();
         propBuilder.setProperty(StandardNames.MIME_CONTENT_LANGUAGE_SPACE, StandardNames.MIME_CONTENT_LANGUAGE_NAME, "us");
         propBuilder.setProperty(StandardNames.MIME_CONTENT_LANGUAGE_SPACE, StandardNames.MIME_CONTENT_LANGUAGE_NAME, "fr");
 
-        SimpleMailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
+        MailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
         MessageMetaData messageMetaData = messageMapper.add(benwaInboxMailbox, messageWithProperties);
         MailboxMessage message = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(messageMetaData.getUid()), FetchType.Body, 1).next();
-        assertThat(message.getProperties()).containsOnlyElementsOf(propBuilder.toProperties());
+
+        assertProperties(message.getProperties()).containsOnly(propBuilder.toProperties());
     }
 
     @ContractTest
     public void messagePropertiesShouldBeStoredWhenNoProperty() throws Exception {
-        SimpleMailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenNoProperty \n\nBody\n.\n", BODY_START, new PropertyBuilder());
+        MailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenNoProperty \n\nBody\n.\n", BODY_START, new PropertyBuilder());
         MessageMetaData messageMetaData = messageMapper.add(benwaInboxMailbox, messageWithProperties);
         MailboxMessage message = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(messageMetaData.getUid()), FetchType.Body, 1).next();
         assertThat(message.getProperties()).isEmpty();
@@ -621,7 +649,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         PropertyBuilder propBuilder = new PropertyBuilder();
         propBuilder.setTextualLineCount(textualLineCount);
 
-        SimpleMailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
+        MailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
         MessageMetaData messageMetaData = messageMapper.add(benwaInboxMailbox, messageWithProperties);
         MailboxMessage message = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(messageMetaData.getUid()), FetchType.Body, 1).next();
         assertThat(message.getTextualLineCount()).isEqualTo(textualLineCount);
@@ -633,7 +661,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         PropertyBuilder propBuilder = new PropertyBuilder();
         propBuilder.setMediaType(mediaType);
 
-        SimpleMailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
+        MailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
         MessageMetaData messageMetaData = messageMapper.add(benwaInboxMailbox, messageWithProperties);
         MailboxMessage message = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(messageMetaData.getUid()), FetchType.Body, 1).next();
         assertThat(message.getMediaType()).isEqualTo(mediaType);
@@ -645,7 +673,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         PropertyBuilder propBuilder = new PropertyBuilder();
         propBuilder.setSubType(subType);
 
-        SimpleMailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
+        MailboxMessage messageWithProperties = createMessage(benwaWorkMailbox, mapperProvider.generateMessageId(), "Subject: messagePropertiesShouldBeStoredWhenDuplicateEntries \n\nBody\n.\n", BODY_START, propBuilder);
         MessageMetaData messageMetaData = messageMapper.add(benwaInboxMailbox, messageWithProperties);
         MailboxMessage message = messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(messageMetaData.getUid()), FetchType.Body, 1).next();
         assertThat(message.getSubType()).isEqualTo(subType);
@@ -655,7 +683,7 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void userFlagsShouldBeSupported() throws Exception {
         saveMessages();
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(USER_FLAG), FlagsUpdateMode.ADD), MessageRange.one(message1.getUid()));
-        MessageAssert.assertThat(retrieveMessageFromStorage(message1)).hasFlags(new Flags(USER_FLAG));
+        assertThat(retrieveMessageFromStorage(message1)).hasFlags(new Flags(USER_FLAG));
     }
 
     @ContractTest
@@ -670,7 +698,7 @@ public class MessageMapperTest<T extends MapperProvider> {
     public void messagesShouldBeSavedWithTheirUserFlags() throws Exception {
         MailboxMessage message = SimpleMailboxMessage.copy(benwaInboxMailbox.getMailboxId(), message1);
         messageMapper.add(benwaInboxMailbox, message);
-        MessageAssert.assertThat(retrieveMessageFromStorage(message)).hasFlags(new Flags(USER_FLAG));
+        assertThat(retrieveMessageFromStorage(message)).hasFlags(new Flags(USER_FLAG));
     }
 
     private Map<MessageUid, MessageMetaData> markThenPerformExpunge(MessageRange range) throws MailboxException {
@@ -679,10 +707,12 @@ public class MessageMapperTest<T extends MapperProvider> {
         return messageMapper.expungeMarkedForDeletionInMailbox(benwaInboxMailbox, range);
     }
 
-    private SimpleMailbox createMailbox(MailboxPath mailboxPath) {
+    private SimpleMailbox createMailbox(MailboxPath mailboxPath) throws MailboxException {
         SimpleMailbox mailbox = new SimpleMailbox(mailboxPath, UID_VALIDITY);
-        MailboxId id = mapperProvider.generateId();
-        mailbox.setMailboxId(id);
+        mailbox.setMailboxId(mapperProvider.generateId());
+        
+        mailboxMapper.save(mailbox);
+
         return mailbox;
     }
     
@@ -705,7 +735,7 @@ public class MessageMapperTest<T extends MapperProvider> {
         return messageMapper.findInMailbox(benwaInboxMailbox, MessageRange.one(message.getUid()), MessageMapper.FetchType.Metadata, LIMIT).next();
     }
     
-    private SimpleMailboxMessage createMessage(Mailbox mailbox, MessageId messageId, String content, int bodyStart, PropertyBuilder propertyBuilder) {
+    private MailboxMessage createMessage(Mailbox mailbox, MessageId messageId, String content, int bodyStart, PropertyBuilder propertyBuilder) {
         return new SimpleMailboxMessage(messageId, new Date(), content.length(), bodyStart, new SharedByteArrayInputStream(content.getBytes()), new Flags(), propertyBuilder, mailbox.getMailboxId());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1ccb1eca/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageWithAttachmentMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageWithAttachmentMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageWithAttachmentMapperTest.java
index 5497d14..ff9242d 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageWithAttachmentMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageWithAttachmentMapperTest.java
@@ -183,8 +183,7 @@ public class MessageWithAttachmentMapperTest<T extends MapperProvider> {
     public void messagesCanBeRetrievedInMailboxWithRangeTypeOne() throws MailboxException, IOException{
         saveMessages();
         MessageMapper.FetchType fetchType = MessageMapper.FetchType.Full;
-        int limit =10;
-        assertThat(messageMapper.findInMailbox(attachmentsMailbox, MessageRange.one(messageWith1Attachment.getUid()), fetchType, limit).next())
+        assertThat(messageMapper.findInMailbox(attachmentsMailbox, MessageRange.one(messageWith1Attachment.getUid()), fetchType, LIMIT).next())
             .isEqualTo(messageWith1Attachment, fetchType);
     }
 


---------------------------------------------------------------------
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