Author: matthieu
Date: Fri Dec 11 12:29:24 2015
New Revision: 1719361

URL: http://svn.apache.org/viewvc?rev=1719361&view=rev
Log:
JAMES-1644 getMailboxes should return error on unimplemented fields

Added:
    
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
    
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
    
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
    
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Mailbox.java
    
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Role.java
      - copied, changed from r1719360, 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java
    
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPGetMailboxesTest.java
    
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxTest.java
Modified:
    
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java

Modified: 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java?rev=1719361&r1=1719360&r2=1719361&view=diff
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java
 (original)
+++ 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java
 Fri Dec 11 12:29:24 2015
@@ -19,6 +19,7 @@
 
 package org.apache.james.jmap;
 
+import org.apache.james.jmap.methods.GetMailboxesMethod;
 import org.apache.james.jmap.methods.JmapRequestParser;
 import org.apache.james.jmap.methods.JmapRequestParserImpl;
 import org.apache.james.jmap.methods.JmapResponseWriter;
@@ -41,6 +42,7 @@ public class MethodsModule extends Abstr
         
bind(JmapResponseWriter.class).to(JmapResponseWriterImpl.class).in(Singleton.class);
 
         Multibinder<Method> methods = Multibinder.newSetBinder(binder(), 
Method.class);
+        methods.addBinding().to(GetMailboxesMethod.class);
     }
 
 }

Added: 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java?rev=1719361&view=auto
==============================================================================
--- 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
 (added)
+++ 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
 Fri Dec 11 12:29:24 2015
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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.jmap.methods;
+
+import java.io.IOException;
+
+import javax.inject.Inject;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.model.GetMailboxesRequest;
+import org.apache.james.jmap.model.ProtocolRequest;
+import org.apache.james.jmap.model.ProtocolResponse;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class GetMailboxesMethod implements Method {
+    
+    private final JmapRequestParser jmapRequestParser;
+    private final JmapResponseWriter jmapResponseWriter;
+
+    @Inject
+    @VisibleForTesting public GetMailboxesMethod(JmapRequestParser 
jmapRequestParser, JmapResponseWriter jmapResponseWriter) {
+
+        this.jmapRequestParser = jmapRequestParser;
+        this.jmapResponseWriter = jmapResponseWriter;
+    }
+
+    public String methodName() {
+        return "getMailboxes";
+    }
+
+    public ProtocolResponse process(ProtocolRequest request) {
+        try {
+            jmapRequestParser.extractJmapRequest(request, 
GetMailboxesRequest.class);
+        } catch (IOException e) {
+            if (e.getCause() instanceof NotImplementedException) {
+                return jmapResponseWriter.formatErrorResponse(request, "Not 
yet implemented");
+            } else {
+                return jmapResponseWriter.formatErrorResponse(request, 
"invalidArguments");
+            }
+        }
+        return jmapResponseWriter.formatErrorResponse(request);
+    }
+
+}

Added: 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java?rev=1719361&view=auto
==============================================================================
--- 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
 (added)
+++ 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesRequest.java
 Fri Dec 11 12:29:24 2015
@@ -0,0 +1,91 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.methods.JmapRequest;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+
+@JsonDeserialize(builder = GetMailboxesRequest.Builder.class)
+public class GetMailboxesRequest implements JmapRequest {
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    @JsonPOJOBuilder(withPrefix = "")
+    public static class Builder {
+
+        private String accountId;
+        private String[] ids;
+        private String[] properties;
+
+        private Builder() {
+        }
+
+        public Builder accountId(String accountId) {
+            if (accountId != null) {
+                throw new NotImplementedException();
+            }
+            return this;
+        }
+
+        public Builder ids(String[] ids) {
+            if (ids != null) {
+                throw new NotImplementedException();
+            }
+            return this;
+        }
+
+        public Builder properties(String[] properties) {
+            if (properties != null) {
+                throw new NotImplementedException();
+            }
+            return this;
+        }
+
+        public GetMailboxesRequest build() {
+            return new GetMailboxesRequest(accountId, ids, properties);
+        }
+    }
+
+    private final String accountId;
+    private final String[] ids;
+    private final String[] properties;
+
+    private GetMailboxesRequest(String accountId, String[] ids, String[] 
properties) {
+        this.accountId = accountId;
+        this.ids = ids;
+        this.properties = properties;
+    }
+
+    public String getAccountId() {
+        return accountId;
+    }
+
+    public String[] getIds() {
+        return ids;
+    }
+
+    public String[] getProperties() {
+        return properties;
+    }
+}

Added: 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java?rev=1719361&view=auto
==============================================================================
--- 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
 (added)
+++ 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetMailboxesResponse.java
 Fri Dec 11 12:29:24 2015
@@ -0,0 +1,112 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.methods.JmapResponse;
+
+import com.google.common.collect.ImmutableList;
+
+public class GetMailboxesResponse implements JmapResponse {
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static class Builder {
+
+        private String accountId;
+        private String state;
+        private ImmutableList.Builder<Mailbox> mailboxes;
+        private ImmutableList.Builder<String> notFoundBuilder;
+
+        private Builder() {
+            mailboxes = ImmutableList.builder();
+            notFoundBuilder = ImmutableList.builder();
+        }
+
+        public Builder accountId(String accountId) {
+            if (accountId != null) {
+                throw new NotImplementedException();
+            }
+            return this;
+        }
+
+        public Builder state(String state) {
+            if (state != null) {
+                throw new NotImplementedException();
+            }
+            return this;
+        }
+
+        public Builder add(Mailbox mailbox) {
+            this.mailboxes.add(mailbox);
+            return this;
+        }
+
+        public Builder addAll(List<Mailbox> list) {
+            this.mailboxes.addAll(list);
+            return this;
+        }
+        
+        public Builder notFound(String[] notFound) {
+            if (notFound != null) {
+                throw new NotImplementedException();
+            }
+            return this;
+        }
+
+        public GetMailboxesResponse build() {
+            ImmutableList<String> notFound = notFoundBuilder.build();
+            return new GetMailboxesResponse(accountId, state, 
mailboxes.build(), 
+                    notFound.isEmpty() ? Optional.empty() : 
Optional.of(notFound));
+        }
+    }
+
+    private final String accountId;
+    private final String state;
+    private final List<Mailbox> list;
+    private final Optional<List<String>> notFound;
+
+    private GetMailboxesResponse(String accountId, String state, List<Mailbox> 
list, Optional<List<String>> notFound) {
+        this.accountId = accountId;
+        this.state = state;
+        this.list = list;
+        this.notFound = notFound;
+    }
+
+    public String getAccountId() {
+        return accountId;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public List<Mailbox> getList() {
+        return list;
+    }
+
+    public Optional<List<String>> getNotFound() {
+        return notFound;
+    }
+}

Added: 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Mailbox.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Mailbox.java?rev=1719361&view=auto
==============================================================================
--- 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Mailbox.java
 (added)
+++ 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Mailbox.java
 Fri Dec 11 12:29:24 2015
@@ -0,0 +1,257 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import java.util.Optional;
+
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+@JsonDeserialize(builder = Mailbox.Builder.class)
+public class Mailbox {
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    @JsonPOJOBuilder(withPrefix = "")
+    public static class Builder {
+
+        private final static int MAX_SORT_ORDER = Double.valueOf(Math.pow(2, 
31)).intValue();
+
+        private String id;
+        private String name;
+        private String parentId;
+        private Role role;
+        private int sortOrder;
+        private boolean mustBeOnlyMailbox;
+        private boolean mayReadItems;
+        private boolean mayAddItems;
+        private boolean mayRemoveItems;
+        private boolean mayCreateChild;
+        private boolean mayRename;
+        private boolean mayDelete;
+        private long totalMessages;
+        private long unreadMessages;
+        private long totalThreads;
+        private long unreadThreads;
+
+        private Builder() {
+        }
+
+        public Builder id(String id) {
+            Preconditions.checkNotNull(id);
+            this.id = id;
+            return this;
+        }
+
+        public Builder name(String name) {
+            Preconditions.checkNotNull(name);
+            this.name = name;
+            return this;
+        }
+
+        public Builder parentId(String parentId) {
+            this.parentId = parentId;
+            return this;
+        }
+
+        public Builder role(Role role) {
+            this.role = role;
+            return this;
+        }
+
+        public Builder sortOrder(int sortOrder) {
+            this.sortOrder = sortOrder;
+            return this;
+        }
+
+        public Builder mustBeOnlyMailbox(boolean mustBeOnlyMailbox) {
+            this.mustBeOnlyMailbox = mustBeOnlyMailbox;
+            return this;
+        }
+
+        public Builder mayReadItems(boolean mayReadItems) {
+            this.mayReadItems = mayReadItems;
+            return this;
+        }
+
+        public Builder mayAddItems(boolean mayAddItems) {
+            this.mayAddItems = mayAddItems;
+            return this;
+        }
+
+        public Builder mayRemoveItems(boolean mayRemoveItems) {
+            this.mayRemoveItems = mayRemoveItems;
+            return this;
+        }
+
+        public Builder mayCreateChild(boolean mayCreateChild) {
+            this.mayCreateChild = mayCreateChild;
+            return this;
+        }
+
+        public Builder mayRename(boolean mayRename) {
+            this.mayRename = mayRename;
+            return this;
+        }
+
+        public Builder mayDelete(boolean mayDelete) {
+            this.mayDelete = mayDelete;
+            return this;
+        }
+
+        public Builder totalMessages(long totalMessages) {
+            this.totalMessages = totalMessages;
+            return this;
+        }
+
+        public Builder unreadMessages(long unreadMessages) {
+            this.unreadMessages = unreadMessages;
+            return this;
+        }
+
+        public Builder totalThreads(long totalThreads) {
+            this.totalThreads = totalThreads;
+            return this;
+        }
+
+        public Builder unreadThreads(long unreadThreads) {
+            this.unreadThreads = unreadThreads;
+            return this;
+        }
+
+        public Mailbox build() {
+            Preconditions.checkState(!Strings.isNullOrEmpty(name), "'name' is 
mandatory");
+            Preconditions.checkState(!Strings.isNullOrEmpty(id), "'id' is 
mandatory");
+            Preconditions.checkState(sortOrder >= 0, "'sortOrder' must be 
positive");
+            Preconditions.checkState(sortOrder < MAX_SORT_ORDER, "'sortOrder' 
must be lesser than " + MAX_SORT_ORDER);
+
+            return new Mailbox(id, name, Optional.ofNullable(parentId), 
Optional.ofNullable(role), sortOrder, mustBeOnlyMailbox, mayReadItems, 
mayAddItems, mayRemoveItems, mayCreateChild, mayRename, mayDelete,
+                    totalMessages, unreadMessages, totalThreads, 
unreadThreads);
+        }
+    }
+
+    private final String id;
+    private final String name;
+    private final Optional<String> parentId;
+    private final Optional<Role> role;
+    private final int sortOrder;
+    private final boolean mustBeOnlyMailbox;
+    private final boolean mayReadItems;
+    private final boolean mayAddItems;
+    private final boolean mayRemoveItems;
+    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;
+
+    @VisibleForTesting Mailbox(String id, String name, Optional<String> 
parentId, Optional<Role> role, int sortOrder, boolean mustBeOnlyMailbox, 
+            boolean mayReadItems, boolean mayAddItems, boolean mayRemoveItems, 
boolean mayCreateChild, boolean mayRename, boolean mayDelete,
+            long totalMessages, long unreadMessages, long totalThreads, long 
unreadThreads) {
+
+        this.id = id;
+        this.name = name;
+        this.parentId = parentId;
+        this.role = role;
+        this.sortOrder = sortOrder;
+        this.mustBeOnlyMailbox = mustBeOnlyMailbox;
+        this.mayReadItems = mayReadItems;
+        this.mayAddItems = mayAddItems;
+        this.mayRemoveItems = mayRemoveItems;
+        this.mayCreateChild = mayCreateChild;
+        this.mayRename = mayRename;
+        this.mayDelete = mayDelete;
+        this.totalMessages = totalMessages;
+        this.unreadMessages = unreadMessages;
+        this.totalThreads = totalThreads;
+        this.unreadThreads = unreadThreads;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Optional<String> getParentId() {
+        return parentId;
+    }
+
+    public Optional<Role> getRole() {
+        return role;
+    }
+
+    public int getSortOrder() {
+        return sortOrder;
+    }
+
+    public boolean isMustBeOnlyMailbox() {
+        return mustBeOnlyMailbox;
+    }
+
+    public boolean isMayReadItems() {
+        return mayReadItems;
+    }
+
+    public boolean isMayAddItems() {
+        return mayAddItems;
+    }
+
+    public boolean isMayRemoveItems() {
+        return mayRemoveItems;
+    }
+
+    public boolean isMayCreateChild() {
+        return mayCreateChild;
+    }
+
+    public boolean isMayRename() {
+        return mayRename;
+    }
+
+    public boolean isMayDelete() {
+        return mayDelete;
+    }
+
+    public long getTotalMessages() {
+        return totalMessages;
+    }
+
+    public long getUnreadMessages() {
+        return unreadMessages;
+    }
+
+    public long getTotalThreads() {
+        return totalThreads;
+    }
+
+    public long getUnreadThreads() {
+        return unreadThreads;
+    }
+}

Copied: 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Role.java
 (from r1719360, 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java)
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Role.java?p2=james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Role.java&p1=james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java&r1=1719360&r2=1719361&rev=1719361&view=diff
==============================================================================
--- 
james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/MethodsModule.java
 (original)
+++ 
james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Role.java
 Fri Dec 11 12:29:24 2015
@@ -16,31 +16,35 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.james.jmap.model;
 
-package org.apache.james.jmap;
+public enum Role {
 
-import org.apache.james.jmap.methods.JmapRequestParser;
-import org.apache.james.jmap.methods.JmapRequestParserImpl;
-import org.apache.james.jmap.methods.JmapResponseWriter;
-import org.apache.james.jmap.methods.JmapResponseWriterImpl;
-import org.apache.james.jmap.methods.Method;
+    INBOX("inbox"),
+    ARCHIVE("archive"),
+    DRAFTS("drafts"),
+    OUTBOX("outbox"),
+    SENT("sent"),
+    TRASH("trash"),
+    SPAM("spam"),
+    TEMPLATES("templates");
+    
+    private String name;
 
-import com.fasterxml.jackson.databind.Module;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import com.google.inject.AbstractModule;
-import com.google.inject.Singleton;
-import com.google.inject.multibindings.Multibinder;
-
-public class MethodsModule extends AbstractModule {
-
-    @Override
-    protected void configure() {
-        Multibinder<Module> jacksonModules = 
Multibinder.newSetBinder(binder(), Module.class);
-        jacksonModules.addBinding().to(Jdk8Module.class);
-        
bind(JmapRequestParser.class).to(JmapRequestParserImpl.class).in(Singleton.class);
-        
bind(JmapResponseWriter.class).to(JmapResponseWriterImpl.class).in(Singleton.class);
+    private Role(String name) {
+        this.name = name;
+    }
 
-        Multibinder<Method> methods = Multibinder.newSetBinder(binder(), 
Method.class);
+    public static Role from(String name) {
+        for (Role role : values()) {
+            if (role.serialize().equals(name.toLowerCase())) {
+                return role;
+            }
+        }
+        return null;
     }
 
+    public String serialize() {
+        return name;
+    }
 }

Added: 
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPGetMailboxesTest.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPGetMailboxesTest.java?rev=1719361&view=auto
==============================================================================
--- 
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPGetMailboxesTest.java
 (added)
+++ 
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPGetMailboxesTest.java
 Fri Dec 11 12:29:24 2015
@@ -0,0 +1,137 @@
+/****************************************************************
+ * 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.jmap;
+
+import static com.jayway.restassured.RestAssured.given;
+import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
+import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+import static org.hamcrest.Matchers.equalTo;
+import static org.mockito.Mockito.mock;
+
+import org.apache.james.http.jetty.Configuration;
+import org.apache.james.http.jetty.JettyHttpServer;
+import org.apache.james.jmap.api.AccessTokenManager;
+import org.apache.james.jmap.api.ContinuationTokenManager;
+import org.apache.james.jmap.methods.GetMailboxesMethod;
+import org.apache.james.jmap.methods.JmapRequestParser;
+import org.apache.james.jmap.methods.JmapRequestParserImpl;
+import org.apache.james.jmap.methods.JmapResponseWriter;
+import org.apache.james.jmap.methods.JmapResponseWriterImpl;
+import org.apache.james.jmap.methods.RequestHandler;
+import org.apache.james.user.api.UsersRepository;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.http.ContentType;
+
+public class JMAPGetMailboxesTest {
+
+    private UsersRepository mockedUsersRepository;
+    private RequestHandler requestHandler;
+    private JettyHttpServer server;
+
+    @Before
+    public void setup() throws Exception {
+        mockedUsersRepository = mock(UsersRepository.class);
+        AccessTokenManager mockedAccessTokenManager = 
mock(AccessTokenManager.class);
+        ContinuationTokenManager mockedContinuationTokenManager = 
mock(ContinuationTokenManager.class);
+        JmapRequestParser jmapRequestParser = new JmapRequestParserImpl();
+        JmapResponseWriter jmapResponseWriter = new JmapResponseWriterImpl();
+
+        requestHandler = new RequestHandler(ImmutableSet.of(new 
GetMailboxesMethod(jmapRequestParser, jmapResponseWriter)));
+        JMAPServlet jmapServlet = new JMAPServlet(requestHandler);
+
+        AuthenticationServlet authenticationServlet = new 
AuthenticationServlet(mockedUsersRepository, mockedContinuationTokenManager, 
mockedAccessTokenManager);
+        
+        server = JettyHttpServer.create(
+                Configuration.builder()
+                .serve("/authentication")
+                .with(authenticationServlet)
+                .serve("/jmap")
+                .with(jmapServlet)
+                .randomPort()
+                .build());
+        
+        server.start();
+
+        RestAssured.port = server.getPort();
+        RestAssured.config = 
newConfig().encoderConfig(encoderConfig().defaultContentCharset("UTF-8"));
+    }
+
+    @After
+    public void teardown() throws Exception {
+        server.stop();
+    }
+    
+    @Test
+    public void 
getMailboxesShouldErrorNotSupportedWhenRequestContainsNonNullAccountId() throws 
Exception {
+        given()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .body("[[\"getMailboxes\", {\"accountId\": \"1\"}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .content(equalTo("[[\"error\",{\"type\":\"Not yet 
implemented\"},\"#0\"]]"));
+    }
+
+    
+    @Test
+    public void 
getMailboxesShouldErrorNotSupportedWhenRequestContainsNonNullIds() throws 
Exception {
+        given()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .body("[[\"getMailboxes\", {\"ids\": []}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .content(equalTo("[[\"error\",{\"type\":\"Not yet 
implemented\"},\"#0\"]]"));
+    }
+    
+    @Test
+    public void 
getMailboxesShouldErrorNotSupportedWhenRequestContainsNonNullProperties() 
throws Exception {
+        given()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .body("[[\"getMailboxes\", {\"properties\": []}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .content(equalTo("[[\"error\",{\"type\":\"Not yet 
implemented\"},\"#0\"]]"));
+    }
+    
+    @Test
+    public void getMailboxesShouldErrorInvalidArgumentsWhenRequestIsInvalid() 
throws Exception {
+        given()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .body("[[\"getMailboxes\", {\"ids\": true}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            
.content(equalTo("[[\"error\",{\"type\":\"invalidArguments\"},\"#0\"]]"));
+    }
+}

Added: 
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxTest.java
URL: 
http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxTest.java?rev=1719361&view=auto
==============================================================================
--- 
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxTest.java
 (added)
+++ 
james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxTest.java
 Fri Dec 11 12:29:24 2015
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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.jmap.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.junit.Test;
+
+public class MailboxTest {
+
+    @Test(expected=NullPointerException.class)
+    public void idShouldThrowWhenIdIsNull() {
+        Mailbox.builder()
+            .id(null);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void nameShouldThrowWhenNameIsNull() {
+        Mailbox.builder()
+            .name(null);
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenIdIsNull() {
+        Mailbox.builder().build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenIdIsEmpty() {
+        Mailbox.builder()
+            .id("")
+            .build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenNameIsNull() {
+        Mailbox.builder()
+            .id("id")
+            .build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenNameIsEmpty() {
+        Mailbox.builder()
+            .id("id")
+            .name("")
+            .build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSortOrderIsNegative() {
+        Mailbox.builder()
+            .id("id")
+            .name("name")
+            .sortOrder(-1)
+            .build();
+    }
+
+    @Test(expected=IllegalStateException.class)
+    public void buildShouldThrowWhenSortOrderIsGreaterThanMax() {
+        Mailbox.builder()
+            .id("id")
+            .name("name")
+            .sortOrder(Double.valueOf(Math.pow(2, 31)).intValue())
+            .build();
+    }
+
+    @Test
+    public void buildShouldWork() {
+        Mailbox expectedMailbox = new Mailbox("id", "name", 
Optional.of("parentId"), Optional.of(Role.DRAFTS), 123, 
+                true, true, true, true, true, true, true, 456, 789, 741, 852);
+
+        Mailbox mailbox = Mailbox.builder()
+            .id("id")
+            .name("name")
+            .parentId("parentId")
+            .role(Role.DRAFTS)
+            .sortOrder(123)
+            .mustBeOnlyMailbox(true)
+            .mayReadItems(true)
+            .mayAddItems(true)
+            .mayRemoveItems(true)
+            .mayCreateChild(true)
+            .mayRename(true)
+            .mayDelete(true)
+            .totalMessages(456)
+            .unreadMessages(789)
+            .totalThreads(741)
+            .unreadThreads(852)
+            .build();
+
+        assertThat(mailbox).isEqualToComparingFieldByField(expectedMailbox);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to