JAMES-2538 GetFilter should tolerate null values

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

Branch: refs/heads/master
Commit: 45357f356e62776350efa7abd32d3c58b077feb6
Parents: 3f2f8a7
Author: Raphael Ouazana <raphael.ouaz...@linagora.com>
Authored: Tue Sep 4 15:31:04 2018 +0200
Committer: Antoine Duprat <adup...@linagora.com>
Committed: Wed Sep 5 11:48:33 2018 +0200

----------------------------------------------------------------------
 .../jmap/methods/integration/FilterTest.java    | 39 ++++++++++++++++++++
 .../james/jmap/model/GetFilterRequest.java      |  5 ++-
 2 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/45357f35/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/FilterTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/FilterTest.java
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/FilterTest.java
index e87c417..3b6dab5 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/FilterTest.java
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/FilterTest.java
@@ -117,6 +117,45 @@ public abstract class FilterTest {
     }
 
     @Test
+    public void getFilterShouldReturnEmptyWhenExplicitNullAccountId() {
+        String body = "[[" +
+                "  \"getFilter\", " +
+                "  {\"accountId\": null}, " +
+                "\"#0\"" +
+                "]]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(body)
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("filter"))
+            .body(ARGUMENTS + ".singleton", hasSize(0));
+    }
+
+    @Test
+    public void getFilterShouldReturnErrorWhenUnsupportedAccountId() {
+        String body = "[[" +
+                "  \"getFilter\", " +
+                "  {\"accountId\": \"any\"}, " +
+                "\"#0\"" +
+                "]]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(body)
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("error"))
+            .body(ARGUMENTS + ".type", equalTo("invalidArguments"))
+            .body(ARGUMENTS + ".description", equalTo("The field 'accountId' 
of 'GetFilterRequest' is not supported"));
+    }
+
+    @Test
     public void setFilterShouldOverwritePreviouslyStoredRules() {
         MailboxId mailbox1 = randomMailboxId();
         MailboxId mailbox2 = randomMailboxId();

http://git-wip-us.apache.org/repos/asf/james-project/blob/45357f35/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
index 52195f0..b587d0f 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/GetFilterRequest.java
@@ -37,7 +37,10 @@ public class GetFilterRequest implements JmapRequest {
         }
 
         public Builder accountId(String accountId) {
-            throw new JmapFieldNotSupportedException(ISSUER, "accountId");
+            if (accountId != null) {
+                throw new JmapFieldNotSupportedException(ISSUER, "accountId");
+            }
+            return this;
         }
 
         public GetFilterRequest build() {


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

Reply via email to