james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/6] james-project git commit: JAMES-1947 Add testing for applicable flag on MessageMapper
Date Tue, 28 Feb 2017 03:38:12 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 44728d3fc -> 2d7b78a05


JAMES-1947 Add testing for applicable flag on MessageMapper


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

Branch: refs/heads/master
Commit: c7f3e371db3fba28c292a8d011e59835895dabf2
Parents: f7321c9
Author: Quynh Nguyen <qnguyen@linagora.com>
Authored: Thu Feb 23 16:01:35 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Feb 28 10:37:10 2017 +0700

----------------------------------------------------------------------
 .../store/mail/model/MapperProvider.java        |   3 +-
 .../store/mail/model/MessageMapperTest.java     | 176 +++++++++++++++++++
 2 files changed, 178 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c7f3e371/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java
index e8fb38d..d33d4f8 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java
@@ -39,7 +39,8 @@ public interface MapperProvider {
         ANNOTATION,
         MOVE,
         UNIQUE_MESSAGE_ID,
-        THREAD_SAFE_FLAGS_UPDATE
+        THREAD_SAFE_FLAGS_UPDATE,
+        INCREMENTAL_APPLICABLE_FLAGS
     }
 
     List<Capabilities> getSupportedCapabilities();

http://git-wip-us.apache.org/repos/asf/james-project/blob/c7f3e371/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 61d1d5d..8e8e494 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
@@ -31,6 +31,7 @@ import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import javax.mail.Flags;
+import javax.mail.Flags.Flag;
 import javax.mail.util.SharedByteArrayInputStream;
 
 import org.apache.james.mailbox.FlagsBuilder;
@@ -46,6 +47,7 @@ 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.MapperProvider.Capabilities;
 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;
@@ -70,6 +72,8 @@ public class MessageMapperTest<T extends MapperProvider> {
     public static final int UID_VALIDITY = 42;
     public static final String USER_FLAG = "userFlag";
 
+    public static final String CUSTOMS_USER_FLAGS_VALUE = "CustomsFlags";
+
     private IProducer<T> producer;
     private MapperProvider mapperProvider;
     private MessageMapper messageMapper;
@@ -820,6 +824,178 @@ public class MessageMapperTest<T extends MapperProvider> {
         assertThat(retrieveMessageFromStorage(message)).hasFlags(new Flags(USER_FLAG));
     }
 
+    @ContractTest
+    public void getApplicableFlagShouldUnionAllMessageFlags() throws Exception {
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+
+        saveMessages();
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldUnionAllMessageFlagsExceptRecentAndUser() throws Exception
{
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+
+        Flags recentAndUser = new Flags(Flag.RECENT);
+        recentAndUser.add(Flag.USER);
+        recentAndUser.add(CUSTOMS_USER_FLAGS_VALUE);
+        message3.setFlags(recentAndUser);
+
+        saveMessages();
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED)
+                .add(CUSTOMS_USER_FLAGS_VALUE)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveEffectWhenUpdateFlagsByAddingThenComputingApplicableFlagsFromCurrentMailboxState()
throws Exception {
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN),
FlagsUpdateMode.ADD);
+
+        saveMessages();
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED, Flag.SEEN)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveNotEffectWhenUpdateFlagsByReplaceThenIncrementalApplicableFlags()
throws Exception {
+        Assume.assumeTrue(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN),
FlagsUpdateMode.REPLACE);
+
+        saveMessages();
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED, Flag.SEEN)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveEffectWhenUpdateFlagsByReplaceThenComputingApplicableFlagsFromCurrentMailboxState()
throws Exception {
+        Assume.assumeFalse(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN),
FlagsUpdateMode.REPLACE);
+
+        saveMessages();
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.DELETED, Flag.SEEN)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveNotEffectWhenUpdateFlagsByRemoveThenIncrementalApplicableFlags()
throws Exception {
+        Assume.assumeTrue(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
+        message1.setFlags(new FlagsBuilder().add(Flag.ANSWERED, Flag.SEEN).build());
+        message2.setFlags(new Flags(Flag.DELETED));
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN),
FlagsUpdateMode.REMOVE);
+
+        saveMessages();
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED, Flag.SEEN)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveEffectWhenUpdateFlagsByRemoveThenComputingApplicableFlagsFromCurrentMailboxState()
throws Exception {
+        Assume.assumeFalse(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
+        message1.setFlags(new FlagsBuilder().add(Flag.ANSWERED, Flag.SEEN).build());
+        message2.setFlags(new Flags(Flag.DELETED));
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN),
FlagsUpdateMode.REMOVE);
+
+        saveMessages();
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveEffectWhenUnsetMessageFlagThenComputingApplicableFlagsFromCurrentMailboxState()
throws Exception {
+        Assume.assumeFalse(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
+        message1.setFlags(new FlagsBuilder().add(Flag.ANSWERED, Flag.SEEN).build());
+        message2.setFlags(new Flags(Flag.DELETED));
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(), FlagsUpdateMode.REPLACE);
+
+        saveMessages();
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.DELETED)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveNotEffectWhenUnsetMessageFlagThenIncrementalApplicableFlags()
throws Exception {
+        Assume.assumeTrue(mapperProvider.getSupportedCapabilities().contains(MapperProvider.Capabilities.THREAD_SAFE_FLAGS_UPDATE));
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+        FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(), FlagsUpdateMode.REPLACE);
+
+        saveMessages();
+        messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED)
+                .build());
+    }
+
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveNotEffectWhenDeleteMessageThenIncrementalApplicableFlags()
throws Exception {
+        Assume.assumeTrue(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+
+        saveMessages();
+        messageMapper.delete(benwaInboxMailbox, message1);
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new FlagsBuilder()
+                .add(Flag.ANSWERED, Flag.DELETED)
+                .build());
+    }
+
+    @ContractTest
+    public void getApplicableFlagShouldHaveEffectWhenDeleteMessageThenComputingApplicableFlagsFromCurrentMailboxState()
throws Exception {
+        Assume.assumeFalse(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
+        message1.setFlags(new Flags(Flag.ANSWERED));
+        message2.setFlags(new Flags(Flag.DELETED));
+
+        saveMessages();
+        messageMapper.delete(benwaInboxMailbox, message1);
+
+        assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
+            .isEqualTo(new Flags(Flag.DELETED));
+    }
+
     private Map<MessageUid, MessageMetaData> markThenPerformExpunge(MessageRange range)
throws MailboxException {
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.DELETED),
FlagsUpdateMode.REPLACE), MessageRange.one(message1.getUid()));
         messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.DELETED),
FlagsUpdateMode.REPLACE), MessageRange.one(message4.getUid()));


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