james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [11/15] james-project git commit: JAMES-2255 Mailbox from JMAP should use Number for number data
Date Fri, 05 Jan 2018 09:17:37 GMT
JAMES-2255 Mailbox from JMAP should use Number for number data


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

Branch: refs/heads/master
Commit: a80260236ba83929dcbdab29df49fbaf145c3d85
Parents: a763b17
Author: quynhn <qnguyen@linagora.com>
Authored: Tue Dec 12 13:57:59 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jan 5 16:10:52 2018 +0700

----------------------------------------------------------------------
 .../james/jmap/model/mailbox/Mailbox.java       | 44 ++++++++++----------
 .../jmap/methods/GetMailboxesMethodTest.java    |  9 ++--
 .../GetMailboxMessageListResponseTest.java      |  3 +-
 .../james/jmap/model/mailbox/MailboxTest.java   | 23 ++++++----
 4 files changed, 44 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a8026023/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
index 235f741..c910369 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/Mailbox.java
@@ -23,6 +23,7 @@ import java.util.Objects;
 import java.util.Optional;
 
 import org.apache.james.jmap.methods.JmapResponseWriterImpl;
+import org.apache.james.jmap.model.Number;
 import org.apache.james.mailbox.model.MailboxId;
 
 import com.fasterxml.jackson.annotation.JsonFilter;
@@ -57,10 +58,10 @@ public class Mailbox {
         private boolean mayCreateChild;
         private boolean mayRename;
         private boolean mayDelete;
-        private Optional<Long> totalMessages;
-        private Optional<Long> unreadMessages;
-        private long totalThreads;
-        private long unreadThreads;
+        private Optional<Number> totalMessages;
+        private Optional<Number> unreadMessages;
+        private Optional<Number> totalThreads;
+        private Optional<Number> unreadThreads;
         private Optional<Rights> sharedWith;
         private Optional<MailboxNamespace> namespace;
 
@@ -70,6 +71,8 @@ public class Mailbox {
             namespace = Optional.empty();
             totalMessages = Optional.empty();
             unreadMessages = Optional.empty();
+            totalThreads = Optional.empty();
+            unreadThreads = Optional.empty();
             role = Optional.empty();
         }
 
@@ -136,22 +139,22 @@ public class Mailbox {
         }
 
         public Builder totalMessages(long totalMessages) {
-            this.totalMessages = Optional.of(totalMessages);
+            this.totalMessages = Optional.of(Number.fromOutboundLong(totalMessages));
             return this;
         }
 
         public Builder unreadMessages(long unreadMessages) {
-            this.unreadMessages = Optional.of(unreadMessages);
+            this.unreadMessages = Optional.of(Number.fromOutboundLong(unreadMessages));
             return this;
         }
 
         public Builder totalThreads(long totalThreads) {
-            this.totalThreads = totalThreads;
+            this.totalThreads = Optional.of(Number.fromOutboundLong(totalThreads));
             return this;
         }
 
         public Builder unreadThreads(long unreadThreads) {
-            this.unreadThreads = unreadThreads;
+            this.unreadThreads = Optional.of(Number.fromOutboundLong(unreadThreads));
             return this;
         }
 
@@ -170,12 +173,7 @@ public class Mailbox {
             Preconditions.checkState(id != null, "'id' is mandatory");
 
             return new Mailbox(id, name, parentId, role, sortOrder, mustBeOnlyMailbox, mayReadItems,
mayAddItems, mayRemoveItems, mayCreateChild, mayRename, mayDelete,
-                    negativeToZero(totalMessages), negativeToZero(unreadMessages), totalThreads,
unreadThreads, sharedWith.orElse(Rights.EMPTY), namespace.orElse(MailboxNamespace.personal()));
-        }
-
-        private long negativeToZero(Optional<Long> number) {
-            return number.filter(value -> value >= 0)
-                .orElse(0L);
+                    totalMessages.orElse(Number.ZERO), unreadMessages.orElse(Number.ZERO),
totalThreads.orElse(Number.ZERO), unreadThreads.orElse(Number.ZERO), sharedWith.orElse(Rights.EMPTY),
namespace.orElse(MailboxNamespace.personal()));
         }
     }
 
@@ -191,16 +189,16 @@ public class Mailbox {
     private final boolean mayCreateChild;
     private final boolean mayRename;
     private final boolean mayDelete;
-    private final long totalMessages;
-    private final long unreadMessages;
-    private final long totalThreads;
-    private final long unreadThreads;
+    private final Number totalMessages;
+    private final Number unreadMessages;
+    private final Number totalThreads;
+    private final Number unreadThreads;
     private final Rights sharedWith;
     private final MailboxNamespace namespace;
 
     @VisibleForTesting Mailbox(MailboxId id, String name, Optional<MailboxId> parentId,
Optional<Role> role, SortOrder sortOrder, boolean mustBeOnlyMailbox,
                                boolean mayReadItems, boolean mayAddItems, boolean mayRemoveItems,
boolean mayCreateChild, boolean mayRename, boolean mayDelete,
-                               long totalMessages, long unreadMessages, long totalThreads,
long unreadThreads, Rights sharedWith, MailboxNamespace namespace) {
+                               Number totalMessages, Number unreadMessages, Number totalThreads,
Number unreadThreads, Rights sharedWith, MailboxNamespace namespace) {
 
         this.id = id;
         this.name = name;
@@ -270,19 +268,19 @@ public class Mailbox {
         return mayDelete;
     }
 
-    public long getTotalMessages() {
+    public Number getTotalMessages() {
         return totalMessages;
     }
 
-    public long getUnreadMessages() {
+    public Number getUnreadMessages() {
         return unreadMessages;
     }
 
-    public long getTotalThreads() {
+    public Number getTotalThreads() {
         return totalThreads;
     }
 
-    public long getUnreadThreads() {
+    public Number getUnreadThreads() {
         return unreadThreads;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/a8026023/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index 1356a6b..cf498df 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -35,6 +35,7 @@ import org.apache.james.jmap.model.ClientId;
 import org.apache.james.jmap.model.GetMailboxesRequest;
 import org.apache.james.jmap.model.GetMailboxesResponse;
 import org.apache.james.jmap.model.MailboxFactory;
+import org.apache.james.jmap.model.Number;
 import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.jmap.model.mailbox.SortOrder;
@@ -138,7 +139,7 @@ public class GetMailboxesMethodTest {
                 .extracting(GetMailboxesResponse.class::cast)
                 .flatExtracting(GetMailboxesResponse::getList)
                 .extracting(Mailbox::getId, Mailbox::getName, Mailbox::getUnreadMessages)
-                .containsOnly(Tuple.tuple(InMemoryId.of(1), mailboxPath.getName(), 2L));
+                .containsOnly(Tuple.tuple(InMemoryId.of(1), mailboxPath.getName(), Number.fromLong(2L)));
     }
 
     @Test
@@ -281,7 +282,7 @@ public class GetMailboxesMethodTest {
                 .extracting(GetMailboxesResponse.class::cast)
                 .flatExtracting(GetMailboxesResponse::getList)
                 .extracting(Mailbox::getTotalMessages, Mailbox::getUnreadMessages)
-                .containsOnly(Tuple.tuple(0L, 0L));
+                .containsOnly(Tuple.tuple(Number.ZERO, Number.ZERO));
     }
 
     @Test
@@ -305,7 +306,7 @@ public class GetMailboxesMethodTest {
                 .extracting(GetMailboxesResponse.class::cast)
                 .flatExtracting(GetMailboxesResponse::getList)
                 .extracting(Mailbox::getTotalMessages)
-                .containsExactly(2L);
+                .containsExactly(Number.fromLong(2L));
     }
 
     @Test
@@ -332,7 +333,7 @@ public class GetMailboxesMethodTest {
                 .extracting(GetMailboxesResponse.class::cast)
                 .flatExtracting(GetMailboxesResponse::getList)
                 .extracting(Mailbox::getUnreadMessages)
-                .containsExactly(2L);
+                .containsExactly(Number.fromLong(2L));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/a8026023/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetMailboxMessageListResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetMailboxMessageListResponseTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetMailboxMessageListResponseTest.java
index e3c1fc4..4cf79fa 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetMailboxMessageListResponseTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/GetMailboxMessageListResponseTest.java
@@ -75,7 +75,8 @@ public class GetMailboxMessageListResponseTest {
                 .build();
         List<String> sort = ImmutableList.of("date desc");
         List<MessageId> messageIds = ImmutableList.of(TestMessageId.of(3), TestMessageId.of(4));
-        GetMessageListResponse expectedGetMessageListResponse = new GetMessageListResponse(null,
filterCondition, sort, false, null, false, 0, 0, ImmutableList.of(), messageIds);
+        GetMessageListResponse expectedGetMessageListResponse = new GetMessageListResponse(null,
filterCondition, sort, false, null, false,
+            Number.ZERO, Number.ZERO, ImmutableList.of(), messageIds);
 
         GetMessageListResponse getMessageListResponse = GetMessageListResponse.builder()
             .filter(filterCondition)

http://git-wip-us.apache.org/repos/asf/james-project/blob/a8026023/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
index 94c5937..384ff73 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.Optional;
 
+import org.apache.james.jmap.model.Number;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.junit.Test;
 
@@ -62,8 +63,14 @@ public class MailboxTest {
 
     @Test
     public void buildShouldWork() {
+        Number totalMessages = Number.fromLong(456);
+        Number unreadMessages = Number.fromLong(789);
+        Number totalThreads = Number.fromLong(741);
+        Number unreadThreads = Number.fromLong(852);
         Mailbox expectedMailbox = new Mailbox(InMemoryId.of(1), "name", Optional.of(InMemoryId.of(0)),
Optional.of(Role.DRAFTS), SortOrder.of(123),
-                true, true, true, true, true, true, true, 456, 789, 741, 852, Rights.EMPTY,
MailboxNamespace.personal());
+            true, true, true, true, true, true, true,
+            totalMessages, unreadMessages, totalThreads, unreadThreads,
+            Rights.EMPTY, MailboxNamespace.personal());
 
         Mailbox mailbox = Mailbox.builder()
             .id(InMemoryId.of(1))
@@ -105,7 +112,7 @@ public class MailboxTest {
                 .totalMessages(-1234)
                 .build();
 
-        assertThat(mailbox.getTotalMessages()).isEqualTo(0);
+        assertThat(mailbox.getTotalMessages()).isEqualTo(Number.ZERO);
     }
 
     @Test
@@ -116,7 +123,7 @@ public class MailboxTest {
                 .unreadMessages(-1234)
                 .build();
 
-        assertThat(mailbox.getUnreadMessages()).isEqualTo(0);
+        assertThat(mailbox.getUnreadMessages()).isEqualTo(Number.ZERO);
     }
 
     @Test
@@ -127,7 +134,7 @@ public class MailboxTest {
                 .totalMessages(0)
                 .build();
 
-        assertThat(mailbox.getTotalMessages()).isEqualTo(0);
+        assertThat(mailbox.getTotalMessages()).isEqualTo(Number.ZERO);
     }
 
     @Test
@@ -138,7 +145,7 @@ public class MailboxTest {
                 .unreadMessages(0)
                 .build();
 
-        assertThat(mailbox.getUnreadMessages()).isEqualTo(0);
+        assertThat(mailbox.getUnreadMessages()).isEqualTo(Number.ZERO);
     }
 
     @Test
@@ -149,7 +156,8 @@ public class MailboxTest {
                 .totalMessages(1234)
                 .build();
 
-        assertThat(mailbox.getTotalMessages()).isEqualTo(1234);
+        Number expectedTotalMessages = Number.fromLong(1234);
+        assertThat(mailbox.getTotalMessages()).isEqualTo(expectedTotalMessages);
     }
 
     @Test
@@ -160,7 +168,8 @@ public class MailboxTest {
             .unreadMessages(1234)
             .build();
 
-        assertThat(mailbox.getUnreadMessages()).isEqualTo(1234);
+        Number expectedTotalMessages = Number.fromLong(1234);
+        assertThat(mailbox.getUnreadMessages()).isEqualTo(expectedTotalMessages);
     }
 
     @Test


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