JAMES-1874 Add missing tests for CassandraMailboxCounterDAO

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

Branch: refs/heads/master
Commit: 4297b454e7b4ec30ea56433d2228195a192eb7d9
Parents: bbe8e8a
Author: Benoit Tellier <btell...@linagora.com>
Authored: Fri Feb 3 10:41:18 2017 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Tue Feb 7 08:57:45 2017 +0700

----------------------------------------------------------------------
 .../mail/CassandraMailboxCounterDAOTest.java    | 152 +++++++++++++++++++
 1 file changed, 152 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4297b454/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
new file mode 100644
index 0000000..013f20c
--- /dev/null
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
@@ -0,0 +1,152 @@
+/****************************************************************
+ * 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.cassandra.mail;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.mailbox.cassandra.CassandraId;
+import 
org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CassandraMailboxCounterDAOTest {
+    public static final int UID_VALIDITY = 15;
+    public static final CassandraId MAILBOX_ID = CassandraId.timeBased();
+
+    private CassandraCluster cassandra;
+    private CassandraMailboxCounterDAO testee;
+    private SimpleMailbox mailbox;
+
+    @Before
+    public void setUp() {
+        cassandra = CassandraCluster.create(new 
CassandraMailboxCounterModule());
+        cassandra.ensureAllTables();
+
+        testee = new CassandraMailboxCounterDAO(cassandra.getConf());
+
+        mailbox = new SimpleMailbox(new MailboxPath("#private", "user", 
"name"), UID_VALIDITY, MAILBOX_ID);
+    }
+
+    @After
+    public void tearDown() {
+        cassandra.clearAllTables();
+    }
+
+    @Test
+    public void countMessagesInMailboxShouldReturnEmptyByDefault() throws 
Exception {
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().isPresent()).isFalse();
+    }
+
+    @Test
+    public void countUnseenMessagesInMailboxShouldReturnEmptyByDefault() 
throws Exception {
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().isPresent()).isFalse();
+    }
+
+    @Test
+    public void incrementCountShouldAddOneWhenAbsent() throws Exception {
+        testee.incrementCount(MAILBOX_ID).join();
+
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().get()).isEqualTo(1);
+    }
+
+    @Test
+    public void incrementUnseenShouldAddOneWhenAbsent() throws Exception {
+        testee.incrementUnseen(MAILBOX_ID).join();
+
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().get()).isEqualTo(1);
+    }
+
+    @Test
+    public void decrementCountShouldRemoveOne() throws Exception {
+        testee.incrementCount(MAILBOX_ID).join();
+
+        testee.decrementCount(MAILBOX_ID).join();
+
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().get()).isEqualTo(0);
+    }
+
+    @Test
+    public void decrementUnseenShouldRemoveOne() throws Exception {
+        testee.incrementUnseen(MAILBOX_ID).join();
+
+        testee.decrementUnseen(MAILBOX_ID).join();
+
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().get()).isEqualTo(0);
+    }
+
+    @Test
+    public void incrementUnseenShouldHaveNoImpactOnMessageCount() throws 
Exception {
+        testee.incrementUnseen(MAILBOX_ID).join();
+
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().get()).isEqualTo(0);
+    }
+
+    @Test
+    public void incrementCountShouldHaveNoEffectOnUnseenCount() throws 
Exception {
+        testee.incrementCount(MAILBOX_ID).join();
+
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().get()).isEqualTo(0);
+    }
+
+    @Test
+    public void decrementUnseenShouldHaveNoEffectOnMessageCount() throws 
Exception {
+        testee.incrementCount(MAILBOX_ID).join();
+
+        testee.decrementUnseen(MAILBOX_ID).join();
+
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().get()).isEqualTo(1);
+    }
+
+    @Test
+    public void decrementCountShouldHaveNoEffectOnUnseenCount() throws 
Exception {
+        testee.incrementUnseen(MAILBOX_ID).join();
+
+        testee.decrementCount(MAILBOX_ID).join();
+
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().get()).isEqualTo(1);
+    }
+
+    @Test
+    public void decrementCountCanLeadToNegativeValue() throws Exception {
+        testee.decrementCount(MAILBOX_ID).join();
+
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countMessagesInMailbox(mailbox).join().get()).isEqualTo(-1);
+    }
+
+    @Test
+    public void decrementUnseenCanLeadToNegativeValue() throws Exception {
+        testee.decrementUnseen(MAILBOX_ID).join();
+
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().isPresent()).isTrue();
+        
assertThat(testee.countUnseenMessagesInMailbox(mailbox).join().get()).isEqualTo(-1);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to