james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject svn commit: r1719396 - in /james/project/trunk/server/protocols: jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/ jmap/src/main/java/org/apache/james/jmap/methods/ jmap/src/main/java/org/apache/james/jmap/model/ jmap/src/test/java/...
Date Fri, 11 Dec 2015 12:35:55 GMT
Author: matthieu
Date: Fri Dec 11 12:35:54 2015
New Revision: 1719396

URL: http://svn.apache.org/viewvc?rev=1719396&view=rev
Log:
JAMES-1644 Response method name is different than request method name

Modified:
    james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
    james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
    james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
    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/methods/GetMessageListMethod.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedProtocolRequest.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
    james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
    james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java

Modified: james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
(original)
+++ james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
Fri Dec 11 12:35:54 2015
@@ -150,7 +150,7 @@ public abstract class GetMailboxesMethod
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(equalTo("[[\"getMailboxes\",{\"accountId\":null,\"state\":null,\"list\":[],\"notFound\":null},\"#0\"]]"));
+            .content(equalTo("[[\"mailboxes\",{\"accountId\":null,\"state\":null,\"list\":[],\"notFound\":null},\"#0\"]]"));
     }
 
     @Test
@@ -170,7 +170,7 @@ public abstract class GetMailboxesMethod
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMailboxes\",{\"accountId\":null,\"state\":null,\"list\":[{\"id\":\""),

+            .content(startsWith("[[\"mailboxes\",{\"accountId\":null,\"state\":null,\"list\":[{\"id\":\""),

                     endsWith("\",\"name\":\"name\",\"parentId\":null,\"role\":null,\"sortOrder\":0,\"mustBeOnlyMailbox\":false,\"mayReadItems\":false,\"mayAddItems\":false,\"mayRemoveItems\":false,\"mayCreateChild\":false,\"mayRename\":false,\"mayDelete\":false,\"totalMessages\":0,\"unreadMessages\":1,\"totalThreads\":0,\"unreadThreads\":0}],\"notFound\":null},\"#0\"]]"));
     }
 }

Modified: james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
(original)
+++ james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java
Fri Dec 11 12:35:54 2015
@@ -117,7 +117,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\"]},"
                     + "\"#0\"]]"));
@@ -145,7 +145,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\"]},"
                     + "\"#0\"]]"));
@@ -169,7 +169,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\"]},"
                     + "\"#0\"]]"));
@@ -194,7 +194,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\"]},"
                     + "\"#0\"]]"));
@@ -218,7 +218,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[]},"
                     + "\"#0\"]]"));
@@ -245,7 +245,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\"]},"
                     + "\"#0\"]]"));
@@ -272,7 +272,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"2\",\"1\"]},"
                     + "\"#0\"]]"));
@@ -299,7 +299,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\"]},"
                     + "\"#0\"]]"));
@@ -326,7 +326,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\"]},"
                     + "\"#0\"]]"));
@@ -353,7 +353,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"2\"]},"
                     + "\"#0\"]]"));
@@ -380,7 +380,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\"]},"
                     + "\"#0\"]]"));
@@ -407,7 +407,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\"]},"
                     + "\"#0\"]]"));
@@ -438,7 +438,7 @@ public abstract class GetMessageListMeth
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessageList\","
+            .content(startsWith("[[\"messageList\","
                     + "{\"accountId\":null,\"filter\":null,\"sort\":[],\"collapseThreads\":false,\"state\":null,"
                     +   "\"canCalculateUpdates\":false,\"position\":0,\"total\":0,\"threadIds\":[],\"messageIds\":[\"1\",\"2\",\"3\"]},"
                     + "\"#0\"]]"));

Modified: james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
(original)
+++ james/project/trunk/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
Fri Dec 11 12:35:54 2015
@@ -150,7 +150,7 @@ public abstract class GetMessagesMethodT
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessages\","))
+            .content(startsWith("[[\"messages\","))
             .extract()
             .asString();
         
@@ -169,7 +169,7 @@ public abstract class GetMessagesMethodT
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessages\","))
+            .content(startsWith("[[\"messages\","))
             .extract()
             .asString();
         
@@ -194,7 +194,7 @@ public abstract class GetMessagesMethodT
             .post("/jmap")
         .then()
             .statusCode(200)
-            .content(startsWith("[[\"getMessages\","))
+            .content(startsWith("[[\"messages\","))
             .extract()
             .asString();
 

Modified: 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=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
Fri Dec 11 12:35:54 2015
@@ -23,6 +23,7 @@ import java.util.Optional;
 
 import javax.inject.Inject;
 
+import org.apache.james.jmap.methods.Method.Response.Name;
 import org.apache.james.jmap.model.GetMailboxesRequest;
 import org.apache.james.jmap.model.GetMailboxesResponse;
 import org.apache.james.jmap.model.Mailbox;
@@ -46,7 +47,8 @@ public class GetMailboxesMethod<Id exten
     
     private static final boolean DONT_RESET_RECENT = false;
     private static final Logger LOGGER = LoggerFactory.getLogger(GetMailboxesMethod.class);
-    private static final Method.Name METHOD_NAME = Method.name("getMailboxes");
+    private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMailboxes");
+    private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("mailboxes");
     
     private final MailboxManager mailboxManager; 
     private final MailboxMapperFactory<Id> mailboxMapperFactory;
@@ -58,11 +60,16 @@ public class GetMailboxesMethod<Id exten
     }
 
     @Override
-    public Name methodName() {
+    public Method.Request.Name requestHandled() {
         return METHOD_NAME;
     }
 
     @Override
+    public Method.Response.Name responseName() {
+        return RESPONSE_NAME;
+    }
+    
+    @Override
     public Class<? extends JmapRequest> requestType() {
         return GetMailboxesRequest.class;
     }

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java
Fri Dec 11 12:35:54 2015
@@ -27,6 +27,7 @@ import java.util.stream.Collectors;
 import javax.inject.Inject;
 import javax.inject.Named;
 
+import org.apache.james.jmap.methods.Method.Response.Name;
 import org.apache.james.jmap.model.FilterCondition;
 import org.apache.james.jmap.model.GetMessageListRequest;
 import org.apache.james.jmap.model.GetMessageListResponse;
@@ -59,7 +60,8 @@ public class GetMessageListMethod<Id ext
     public static final int DEFAULT_MAXIMUM_LIMIT = 256;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(GetMailboxesMethod.class);
-    private static final Method.Name METHOD_NAME = Method.name("getMessageList");
+    private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMessageList");
+    private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("messageList");
     private static final int NO_LIMIT = -1;
 
     private final MailboxManager mailboxManager;
@@ -76,11 +78,16 @@ public class GetMessageListMethod<Id ext
     }
 
     @Override
-    public Name methodName() {
+    public Method.Request.Name requestHandled() {
         return METHOD_NAME;
     }
 
     @Override
+    public Method.Response.Name responseName() {
+        return RESPONSE_NAME;
+    }
+    
+    @Override
     public Class<? extends JmapRequest> requestType() {
         return GetMessageListRequest.class;
     }

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
Fri Dec 11 12:35:54 2015
@@ -29,6 +29,7 @@ import java.util.stream.StreamSupport;
 import javax.inject.Inject;
 
 import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.jmap.methods.Method.Response.Name;
 import org.apache.james.jmap.model.GetMessagesRequest;
 import org.apache.james.jmap.model.GetMessagesResponse;
 import org.apache.james.jmap.model.Message;
@@ -54,7 +55,8 @@ import com.google.common.collect.Immutab
 
 public class GetMessagesMethod<Id extends MailboxId> implements Method {
 
-    private static final Method.Name METHOD_NAME = Method.name("getMessages");
+    private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMessages");
+    private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("messages");
     private final MessageMapperFactory<Id> messageMapperFactory;
     private final MailboxMapperFactory<Id> mailboxMapperFactory;
     
@@ -68,11 +70,16 @@ public class GetMessagesMethod<Id extend
     }
     
     @Override
-    public Method.Name methodName() {
+    public Method.Request.Name requestHandled() {
         return METHOD_NAME;
     }
     
     @Override
+    public Method.Response.Name responseName() {
+        return RESPONSE_NAME;
+    }
+    
+    @Override
     public Class<? extends JmapRequest> requestType() {
         return GetMessagesRequest.class;
     }

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponse.java
Fri Dec 11 12:35:54 2015
@@ -30,21 +30,17 @@ public class JmapResponse {
         return new Builder();
     }
     
-    public static Builder forRequest(ProtocolRequest request) {
-        return builder().clientId(request.getClientId()).method(request.getMethod());
-    }
-    
     public static class Builder {
         
-        private Method.Name method;
+        private Method.Response.Name responseName;
         private ClientId id;
         private Object response;
 
         private Builder() {
         }
 
-        public Builder method(Method.Name name) {
-            this.method = name;
+        public Builder responseName(Method.Response.Name name) {
+            this.responseName = name;
             return this;
         }
         
@@ -64,13 +60,13 @@ public class JmapResponse {
 
         public Builder error(String message) {
             this.response = new ErrorResponse(message);
-            this.method = ERROR_METHOD;
+            this.responseName = ERROR_METHOD;
             return this;
         }
 
         
         public JmapResponse build() {
-            return new JmapResponse(method, id, response);
+            return new JmapResponse(responseName, id, response);
         }
     }
 
@@ -88,19 +84,20 @@ public class JmapResponse {
     }
     
     @VisibleForTesting static final String DEFAULT_ERROR_MESSAGE = "Error while processing";
-    @VisibleForTesting static final Method.Name ERROR_METHOD = Method.name("error");
+    public static final Method.Response.Name ERROR_METHOD = Method.Response.name("error");
 
-    private final Method.Name method;
+    
+    private final Method.Response.Name method;
     private final ClientId clientId;
     private final Object response;
     
-    private JmapResponse(Method.Name method, ClientId clientId, Object response) {
+    private JmapResponse(Method.Response.Name method, ClientId clientId, Object response)
{
         this.method = method;
         this.clientId = clientId;
         this.response = response;
     }
 
-    public Method.Name getMethod() {
+    public Method.Response.Name getResponseName() {
         return method;
     }
     

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/JmapResponseWriterImpl.java
Fri Dec 11 12:35:54 2015
@@ -42,7 +42,7 @@ public class JmapResponseWriterImpl impl
     @Override
     public ProtocolResponse formatMethodResponse(JmapResponse jmapResponse) {
         return new ProtocolResponse(
-                jmapResponse.getMethod(), 
+                jmapResponse.getResponseName(), 
                 objectMapper.valueToTree(jmapResponse.getResponse()), 
                 jmapResponse.getClientId());
     }

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/Method.java
Fri Dec 11 12:35:54 2015
@@ -30,49 +30,96 @@ import com.google.common.base.Preconditi
 
 public interface Method {
 
-    interface Response {};
-    
-    public static Name name(String name) {
-        return new Name(name);
-    }
-    
-    public class Name {
+    interface Request {
 
-        private final String name;
-        
-        private Name(String name) {
-            Preconditions.checkNotNull(name);
-            Preconditions.checkArgument(!name.isEmpty());
-            this.name = name;
-        }
-
-        @JsonValue
-        public String getName() {
-            return name;
+        public static Name name(String name) {
+            return new Name(name);
         }
         
-        @Override
-        public boolean equals(Object obj) {
-            if (obj instanceof Name) {
-                Name other = (Name) obj;
-                return Objects.equals(name, other.name);
+        public class Name {
+
+            private final String name;
+            
+            private Name(String name) {
+                Preconditions.checkNotNull(name);
+                Preconditions.checkArgument(!name.isEmpty());
+                this.name = name;
+            }
+
+            @JsonValue
+            public String getName() {
+                return name;
+            }
+
+            @Override
+            public boolean equals(Object obj) {
+                if (obj instanceof Name) {
+                    Name other = (Name) obj;
+                    return Objects.equals(name, other.name);
+                }
+                return false;
+            }
+
+            @Override
+            public int hashCode() {
+                return Objects.hash(name);
+            }
+
+            @Override
+            public String toString() {
+                return toStringHelper(this).add("name", name).toString();
             }
-            return false;
         }
-        
-        @Override
-        public int hashCode() {
-            return Objects.hash(name);
+
+    }
+    
+    interface Response {
+
+        public static Name name(String name) {
+            return new Name(name);
         }
         
-        @Override
-        public String toString() {
-            return toStringHelper(this).add("name", name).toString();
+        public class Name {
+
+            private final String name;
+
+            protected Name(String name) {
+                Preconditions.checkNotNull(name);
+                Preconditions.checkArgument(!name.isEmpty());
+                this.name = name;
+            }
+
+            @JsonValue
+            public String getName() {
+                return name;
+            }
+            
+            @Override
+            public boolean equals(Object obj) {
+                if (obj instanceof Name) {
+                    Name other = (Name) obj;
+                    return Objects.equals(name, other.name);
+                }
+                return false;
+            }
+            
+            @Override
+            public int hashCode() {
+                return Objects.hash(name);
+            }
+            
+            @Override
+            public String toString() {
+                return toStringHelper(this).add("name", name).toString();
+            }
         }
-    }
-    
-    Name methodName();
+    };
+
 
+    Request.Name requestHandled();
+
+    Response.Name responseName();
+    
     Class<? extends JmapRequest> requestType();
     
     Response process(JmapRequest request, MailboxSession mailboxSession);

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/RequestHandler.java
Fri Dec 11 12:35:54 2015
@@ -38,19 +38,19 @@ public class RequestHandler {
 
     private final JmapRequestParser jmapRequestParser;
     private final JmapResponseWriter jmapResponseWriter;
-    private final Map<Method.Name, Method> methods;
+    private final Map<Method.Request.Name, Method> methods;
 
     @Inject
     public RequestHandler(Set<Method> methods, JmapRequestParser jmapRequestParser,
JmapResponseWriter jmapResponseWriter) {
         this.jmapRequestParser = jmapRequestParser;
         this.jmapResponseWriter = jmapResponseWriter;
         this.methods = methods.stream()
-                .collect(Collectors.toMap(Method::methodName, Function.identity()));
+                .collect(Collectors.toMap(Method::requestHandled, Function.identity()));
     }
 
     public ProtocolResponse handle(AuthenticatedProtocolRequest request) {
-        Builder responseBuilder = JmapResponse.forRequest(request);
-        return Optional.ofNullable(methods.get(request.getMethod()))
+        Builder responseBuilder = JmapResponse.builder().clientId(request.getClientId());
+        return Optional.ofNullable(methods.get(request.getMethodName()))
                         .map(extractAndProcess(request, responseBuilder))
                         .map(jmapResponseWriter::formatMethodResponse)
                         .orElseThrow(() -> new IllegalStateException("unknown method"));
@@ -63,6 +63,7 @@ public class RequestHandler {
                         JmapRequest jmapRequest = jmapRequestParser.extractJmapRequest(request,
method.requestType());
                         return responseBuilder
                                 .response(method.process(jmapRequest, mailboxSession))
+                                .responseName(method.responseName())
                                 .build();
                     } catch (IOException e) {
                         if (e.getCause() instanceof NotImplementedException) {

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedProtocolRequest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedProtocolRequest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedProtocolRequest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/AuthenticatedProtocolRequest.java
Fri Dec 11 12:35:54 2015
@@ -32,7 +32,7 @@ public class AuthenticatedProtocolReques
     private final HttpServletRequest httpServletRequest;
 
     private AuthenticatedProtocolRequest(ProtocolRequest request, HttpServletRequest httpServletRequest)
{
-        super(request.getMethod(), request.getParameters(), request.getClientId());
+        super(request.getMethodName(), request.getParameters(), request.getClientId());
         this.httpServletRequest = httpServletRequest;
         
     }

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolRequest.java
Fri Dec 11 12:35:54 2015
@@ -31,20 +31,20 @@ public class ProtocolRequest {
         Preconditions.checkState(json[0].isTextual(), "first element should be a String");
         Preconditions.checkState(json[1].isObject(), "second element should be a Json");
         Preconditions.checkState(json[2].isTextual(), "third element should be a String");
-        return new ProtocolRequest(Method.name(json[0].textValue()), (ObjectNode) json[1],
ClientId.of(json[2].textValue()));
+        return new ProtocolRequest(Method.Request.name(json[0].textValue()), (ObjectNode)
json[1], ClientId.of(json[2].textValue()));
     }
 
-    private final Method.Name method;
+    private final Method.Request.Name method;
     private final ObjectNode parameters;
     private final ClientId clientId;
 
-    protected ProtocolRequest(Method.Name method, ObjectNode parameters, ClientId clientId)
{
+    protected ProtocolRequest(Method.Request.Name method, ObjectNode parameters, ClientId
clientId) {
         this.method = method;
         this.parameters = parameters;
         this.clientId = clientId;
     }
 
-    public Method.Name getMethod() {
+    public Method.Request.Name getMethodName() {
         return method;
     }
 

Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/ProtocolResponse.java
Fri Dec 11 12:35:54 2015
@@ -25,21 +25,21 @@ import com.google.common.base.Preconditi
 
 public class ProtocolResponse {
 
-    private final Method.Name method;
+    private final Method.Response.Name name;
     private final ObjectNode results;
     private final ClientId clientId;
 
-    public ProtocolResponse(Method.Name name, ObjectNode results, ClientId clientId) {
+    public ProtocolResponse(Method.Response.Name name, ObjectNode results, ClientId clientId)
{
         Preconditions.checkNotNull(name, "method is mandatory");
         Preconditions.checkNotNull(results, "results is mandatory");
         Preconditions.checkNotNull(clientId,  "clientId is mandatory");
-        this.method = name;
+        this.name = name;
         this.results = results;
         this.clientId = clientId;
     }
 
-    public Method.Name getMethod() {
-        return method;
+    public Method.Response.Name getResponseName() {
+        return name;
     }
 
     public ObjectNode getResults() {
@@ -51,6 +51,6 @@ public class ProtocolResponse {
     }
 
     public Object[] asProtocolSpecification() {
-        return new Object[] { getMethod(), getResults(), getClientId() };
+        return new Object[] { getResponseName(), getResults(), getClientId() };
     }
 }
\ No newline at end of file

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPServletTest.java
Fri Dec 11 12:35:54 2015
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
 
 import org.apache.james.http.jetty.Configuration;
 import org.apache.james.http.jetty.JettyHttpServer;
+import org.apache.james.jmap.methods.JmapResponse;
 import org.apache.james.jmap.methods.Method;
 import org.apache.james.jmap.methods.RequestHandler;
 import org.apache.james.jmap.model.ClientId;
@@ -91,7 +92,7 @@ public class JMAPServletTest {
         json.put("type", "invalidArgument");
 
         when(requestHandler.handle(any()))
-            .thenReturn(new ProtocolResponse(Method.name("error"), json, ClientId.of("#0")));
+            .thenReturn(new ProtocolResponse(JmapResponse.ERROR_METHOD, json, ClientId.of("#0")));
 
         given()
             .accept(ContentType.JSON)
@@ -115,7 +116,7 @@ public class JMAPServletTest {
         arrayNode.add(list);
 
         when(requestHandler.handle(any()))
-            .thenReturn(new ProtocolResponse(Method.name("accounts"), json, ClientId.of("#0")));
+            .thenReturn(new ProtocolResponse(Method.Response.name("accounts"), json, ClientId.of("#0")));
 
         given()
             .accept(ContentType.JSON)

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/JmapResponseWriterImplTest.java
Fri Dec 11 12:35:54 2015
@@ -38,37 +38,37 @@ public class JmapResponseWriterImplTest
     @Ignore
     @Test(expected=IllegalStateException.class)
     public void formatMethodResponseShouldWorkWhenNullJmapResponse() {
-        String expectedMethod = "unknwonMethod";
+        String expectedMethod = "nwonMethod";
         String expectedClientId = "#1";
         String expectedId = "myId";
 
         ObjectNode parameters = new ObjectNode(new JsonNodeFactory(false));
         parameters.put("id", expectedId);
-        JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode(expectedMethod),
+        JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("unknwonMethod"),
                 parameters,
                 new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)} ;
 
         JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new
Jdk8Module()));
         ProtocolRequest request = ProtocolRequest.deserialize(nodes);
         ProtocolResponse response = jmapResponseWriterImpl.formatMethodResponse(JmapResponse
-                .forRequest(request)
+                .builder()
+                .clientId(request.getClientId())
                 .response(null)
                 .build());
 
-        assertThat(response.getMethod()).isEqualTo(expectedMethod);
+        assertThat(response.getResponseName()).isEqualTo(expectedMethod);
         assertThat(response.getResults().findValue("id").asText()).isEqualTo(expectedId);
         assertThat(response.getClientId()).isEqualTo(expectedClientId);
     }
 
     @Test
     public void formatMethodResponseShouldWork() {
-        String expectedMethod = "unknwonMethod";
         String expectedClientId = "#1";
         String expectedId = "myId";
 
         ObjectNode parameters = new ObjectNode(new JsonNodeFactory(false));
         parameters.put("id", expectedId);
-        JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode(expectedMethod),
+        JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("unknwonMethod"),
                 parameters,
                 new ObjectNode(new JsonNodeFactory(false)).textNode(expectedClientId)} ;
 
@@ -78,11 +78,13 @@ public class JmapResponseWriterImplTest
         JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new
Jdk8Module()));
         ProtocolResponse response = jmapResponseWriterImpl.formatMethodResponse(
                 JmapResponse
-                .forRequest(ProtocolRequest.deserialize(nodes))
+                .builder()
+                .responseName(Method.Response.name("unknownMethod"))
+                .clientId(ProtocolRequest.deserialize(nodes).getClientId())
                 .response(responseClass)
                 .build());
 
-        assertThat(response.getMethod()).isEqualTo(Method.name(expectedMethod));
+        assertThat(response.getResponseName()).isEqualTo(Method.Response.name("unknownMethod"));
         assertThat(response.getResults().findValue("id").asText()).isEqualTo(expectedId);
         assertThat(response.getClientId()).isEqualTo(ClientId.of(expectedClientId));
     }
@@ -107,11 +109,12 @@ public class JmapResponseWriterImplTest
         JmapResponseWriterImpl jmapResponseWriterImpl = new JmapResponseWriterImpl(ImmutableSet.of(new
Jdk8Module()));
         ProtocolResponse response = jmapResponseWriterImpl.formatMethodResponse(
                 JmapResponse
-                    .forRequest(ProtocolRequest.deserialize(nodes))
+                    .builder()
+                    .clientId(ProtocolRequest.deserialize(nodes).getClientId())
                     .error()
                     .build());
 
-        assertThat(response.getMethod()).isEqualTo(JmapResponse.ERROR_METHOD);
+        assertThat(response.getResponseName()).isEqualToComparingFieldByField(JmapResponse.ERROR_METHOD);
         assertThat(response.getResults().findValue("type").asText()).isEqualTo(JmapResponse.DEFAULT_ERROR_MESSAGE);
         assertThat(response.getClientId()).isEqualTo(ClientId.of(expectedClientId));
     }

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/RequestHandlerTest.java
Fri Dec 11 12:35:54 2015
@@ -25,6 +25,7 @@ import static org.assertj.core.api.Asser
 import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.james.jmap.methods.Method.Response.Name;
 import org.apache.james.jmap.model.AuthenticatedProtocolRequest;
 import org.apache.james.jmap.model.ProtocolRequest;
 import org.apache.james.jmap.model.ProtocolResponse;
@@ -83,18 +84,21 @@ public class RequestHandlerTest {
 
     public static class TestMethod implements Method {
 
-        private static final Method.Name METHOD_NAME = Method.name("testMethod");
-        
         @Inject
         @VisibleForTesting TestMethod() {
         }
 
         @Override
-        public Name methodName() {
-            return METHOD_NAME;
+        public Method.Request.Name requestHandled() {
+            return Method.Request.name("getTestMethod");
         }
 
         @Override
+        public Method.Response.Name responseName() {
+            return Method.Response.name("testMethod");
+        }
+        
+        @Override
         public Class<? extends JmapRequest> requestType() {
             return TestJmapRequest.class;
         }
@@ -145,8 +149,8 @@ public class RequestHandlerTest {
     public void requestHandlerShouldThrowWhenTwoMethodsWithSameName() {
         new RequestHandler(
                 ImmutableSet.of(
-                        new NamedMethod(Method.name("name")),
-                        new NamedMethod(Method.name("name"))),
+                        new NamedMethod(Method.Request.name("name")),
+                        new NamedMethod(Method.Request.name("name"))),
                 jmapRequestParser, 
                 jmapResponseWriter);
     }
@@ -155,25 +159,30 @@ public class RequestHandlerTest {
     public void requestHandlerMayBeCreatedWhenTwoMethodsWithDifferentName() {
         new RequestHandler(
                 ImmutableSet.of(
-                        new NamedMethod(Method.name("name")), 
-                        new NamedMethod(Method.name("name2"))),
+                        new NamedMethod(Method.Request.name("name")), 
+                        new NamedMethod(Method.Request.name("name2"))),
                 jmapRequestParser, 
                 jmapResponseWriter);
     }
 
     private class NamedMethod implements Method {
 
-        private final Name methodName;
+        private final Method.Request.Name methodName;
 
-        public NamedMethod(Method.Name methodName) {
+        public NamedMethod(Method.Request.Name methodName) {
             this.methodName = methodName;
             
         }
 
         @Override
-        public Name methodName() {
+        public Method.Request.Name requestHandled() {
             return methodName;
         }
+        
+        @Override
+        public Name responseName() {
+            return null;
+        }
 
         @Override
         public Class<? extends JmapRequest> requestType() {
@@ -192,7 +201,7 @@ public class RequestHandlerTest {
         parameters.put("id", "testId");
         parameters.put("name", "testName");
         
-        JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("testMethod"),
+        JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("getTestMethod"),
                 parameters,
                 new ObjectNode(new JsonNodeFactory(false)).textNode("#1")} ;
 

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolRequestTest.java
Fri Dec 11 12:35:54 2015
@@ -87,7 +87,7 @@ public class ProtocolRequestTest {
 
         ProtocolRequest request = ProtocolRequest.deserialize(nodes);
 
-        assertThat(request.getMethod()).isEqualTo(Method.name("getAccounts"));
+        assertThat(request.getMethodName()).isEqualTo(Method.Request.name("getAccounts"));
         assertThat(request.getParameters()).isNotNull();
         assertThat(request.getClientId()).isEqualTo(ClientId.of("#1"));
     }

Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java?rev=1719396&r1=1719395&r2=1719396&view=diff
==============================================================================
--- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java
(original)
+++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/ProtocolResponseTest.java
Fri Dec 11 12:35:54 2015
@@ -36,22 +36,22 @@ public class ProtocolResponseTest {
 
     @Test(expected=IllegalArgumentException.class)
     public void newInstanceShouldThrowWhenMethodIsEmpty() {
-        new ProtocolResponse(Method.name(""), new ObjectNode(JsonNodeFactory.instance), ClientId.of("id"));
+        new ProtocolResponse(Method.Response.name(""), new ObjectNode(JsonNodeFactory.instance),
ClientId.of("id"));
     }
 
     @Test(expected=NullPointerException.class)
     public void newInstanceShouldThrowWhenResultsIsNull() {
-        new ProtocolResponse(Method.name("method"), null, ClientId.of("id"));
+        new ProtocolResponse(Method.Response.name("method"), null, ClientId.of("id"));
     }
 
     @Test(expected=NullPointerException.class)
     public void newInstanceShouldThrowWhenClientIdIsNull() {
-        new ProtocolResponse(Method.name("method"), new ObjectNode(new JsonNodeFactory(false)).putObject("{}"),
null);
+        new ProtocolResponse(Method.Response.name("method"), new ObjectNode(new JsonNodeFactory(false)).putObject("{}"),
null);
     }
 
     @Test
     public void asProtocolSpecificationShouldReturnAnArrayWithThreeElements() {
-        Object[] asProtocolSpecification = new ProtocolResponse(Method.name("method"), new
ObjectNode(new JsonNodeFactory(false)).putObject("{}"), ClientId.of("#1"))
+        Object[] asProtocolSpecification = new ProtocolResponse(Method.Response.name("method"),
new ObjectNode(new JsonNodeFactory(false)).putObject("{}"), ClientId.of("#1"))
                 .asProtocolSpecification();
 
         assertThat(asProtocolSpecification).hasSize(3);




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