You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2018/04/06 13:20:36 UTC
[17/24] james-project git commit: JAMES-2366 Factorize some common
JMAP calls in JMAP integration tests
JAMES-2366 Factorize some common JMAP calls in JMAP integration tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7be706d8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7be706d8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7be706d8
Branch: refs/heads/master
Commit: 7be706d808f253053cef42e4e815507c822fa357
Parents: a2f301f
Author: benwa <bt...@linagora.com>
Authored: Thu Apr 5 16:54:22 2018 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Fri Apr 6 15:04:49 2018 +0200
----------------------------------------------------------------------
.../apache/james/jmap/JmapCommonRequests.java | 101 +++++++++++++++++++
.../integration/ForwardIntegrationTest.java | 44 +-------
.../methods/integration/SendMDNMethodTest.java | 54 +---------
3 files changed, 107 insertions(+), 92 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7be706d8/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
new file mode 100644
index 0000000..6397833
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
@@ -0,0 +1,101 @@
+/****************************************************************
+ * 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.with;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.james.jmap.api.access.AccessToken;
+import org.apache.james.mailbox.Role;
+
+public class JmapCommonRequests {
+ private static final String NAME = "[0][0]";
+ private static final String ARGUMENTS = "[0][1]";
+
+ public static String getOutboxId(AccessToken accessToken) {
+ return getMailboxId(accessToken, Role.OUTBOX);
+ }
+
+ public static String getMailboxId(AccessToken accessToken, Role role) {
+ return getAllMailboxesIds(accessToken).stream()
+ .filter(x -> x.get("role").equalsIgnoreCase(role.serialize()))
+ .map(x -> x.get("id"))
+ .findFirst().get();
+ }
+
+ public static List<Map<String, String>> getAllMailboxesIds(AccessToken accessToken) {
+ return with()
+ .header("Authorization", accessToken.serialize())
+ .body("[[\"getMailboxes\", {\"properties\": [\"role\", \"id\"]}, \"#0\"]]")
+ .post("/jmap")
+ .andReturn()
+ .body()
+ .jsonPath()
+ .getList(ARGUMENTS + ".list");
+ }
+
+ public static boolean isAnyMessageFoundInRecipientsMailboxes(AccessToken recipientToken) {
+ try {
+ with()
+ .header("Authorization", recipientToken.serialize())
+ .body("[[\"getMessageList\", {}, \"#0\"]]")
+ .when()
+ .post("/jmap")
+ .then()
+ .statusCode(200)
+ .body(NAME, equalTo("messageList"))
+ .body(ARGUMENTS + ".messageIds", hasSize(1));
+ return true;
+
+ } catch (AssertionError e) {
+ return false;
+ }
+ }
+
+ public static String getInboxId(AccessToken accessToken) {
+ return getMailboxId(accessToken, Role.INBOX);
+ }
+
+ public static List<String> listMessageIdsForAccount(AccessToken accessToken) {
+ return with()
+ .header("Authorization", accessToken.serialize())
+ .body("[[\"getMessageList\", {}, \"#0\"]]")
+ .post("/jmap")
+ .then()
+ .extract()
+ .body()
+ .path(ARGUMENTS + ".messageIds");
+ }
+
+ public static List<String> listMessageIdsInMailbox(AccessToken accessToken, String mailboxId) {
+ return with()
+ .header("Authorization", accessToken.serialize())
+ .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId + "\"]}}, \"#0\"]]")
+ .post("/jmap")
+ .then()
+ .extract()
+ .body()
+ .path(ARGUMENTS + ".messageIds");
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7be706d8/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/ForwardIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/ForwardIntegrationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/ForwardIntegrationTest.java
index 92d02b6..8511b45 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/ForwardIntegrationTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/ForwardIntegrationTest.java
@@ -22,19 +22,18 @@ package org.apache.james.jmap.methods.integration;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.with;
import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
+import static org.apache.james.jmap.JmapCommonRequests.isAnyMessageFoundInRecipientsMailboxes;
import static org.apache.james.jmap.JmapURIBuilder.baseUri;
import static org.apache.james.jmap.TestingConstants.calmlyAwait;
import static org.apache.james.jmap.TestingConstants.jmapRequestSpecBuilder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
-import java.util.List;
-import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.james.GuiceJamesServer;
import org.apache.james.jmap.api.access.AccessToken;
-import org.apache.james.mailbox.Role;
import org.apache.james.probe.DataProbe;
import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.JmapGuiceProbe;
@@ -241,43 +240,4 @@ public abstract class ForwardIntegrationTest {
.body(ARGUMENTS + ".messageIds", hasSize(0));
}
- private String getOutboxId(AccessToken accessToken) {
- return getMailboxId(accessToken, Role.OUTBOX);
- }
-
- private String getMailboxId(AccessToken accessToken, Role role) {
- return getAllMailboxesIds(accessToken).stream()
- .filter(x -> x.get("role").equalsIgnoreCase(role.serialize()))
- .map(x -> x.get("id"))
- .findFirst().get();
- }
-
- private List<Map<String, String>> getAllMailboxesIds(AccessToken accessToken) {
- return with()
- .header("Authorization", accessToken.serialize())
- .body("[[\"getMailboxes\", {\"properties\": [\"role\", \"id\"]}, \"#0\"]]")
- .post("/jmap")
- .andReturn()
- .body()
- .jsonPath()
- .getList(ARGUMENTS + ".list");
- }
-
- private boolean isAnyMessageFoundInRecipientsMailboxes(AccessToken recipientToken) {
- try {
- with()
- .header("Authorization", recipientToken.serialize())
- .body("[[\"getMessageList\", {}, \"#0\"]]")
- .when()
- .post("/jmap")
- .then()
- .statusCode(200)
- .body(NAME, equalTo("messageList"))
- .body(ARGUMENTS + ".messageIds", hasSize(1));
- return true;
-
- } catch (AssertionError e) {
- return false;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7be706d8/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
index cc3d9c9..faeb705 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SendMDNMethodTest.java
@@ -22,6 +22,10 @@ package org.apache.james.jmap.methods.integration;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.with;
import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JmapCommonRequests.getInboxId;
+import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
+import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsForAccount;
+import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsInMailbox;
import static org.apache.james.jmap.JmapURIBuilder.baseUri;
import static org.apache.james.jmap.TestingConstants.calmlyAwait;
import static org.apache.james.jmap.TestingConstants.jmapRequestSpecBuilder;
@@ -34,14 +38,12 @@ import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
import org.apache.james.GuiceJamesServer;
import org.apache.james.jmap.MessageAppender;
import org.apache.james.jmap.api.access.AccessToken;
import org.apache.james.mailbox.DefaultMailboxes;
-import org.apache.james.mailbox.Role;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MessageId;
@@ -490,52 +492,4 @@ public abstract class SendMDNMethodTest {
.body(ARGUMENTS + ".description", containsString("Unrecognized MDN Disposition action mode invalid. Should be one of [manual-action, automatic-action]"));
}
- private String getInboxId(AccessToken accessToken) {
- return getMailboxId(accessToken, Role.INBOX);
- }
-
- private String getOutboxId(AccessToken accessToken) {
- return getMailboxId(accessToken, Role.OUTBOX);
- }
-
- private String getMailboxId(AccessToken accessToken, Role role) {
- return getAllMailboxesIds(accessToken).stream()
- .filter(x -> x.get("role").equalsIgnoreCase(role.serialize()))
- .map(x -> x.get("id"))
- .findFirst().get();
- }
-
- private List<Map<String, String>> getAllMailboxesIds(AccessToken accessToken) {
- return with()
- .header("Authorization", accessToken.serialize())
- .body("[[\"getMailboxes\", {\"properties\": [\"role\", \"id\"]}, \"#0\"]]")
- .post("/jmap")
- .andReturn()
- .body()
- .jsonPath()
- .getList(ARGUMENTS + ".list");
- }
-
- private List<String> listMessageIdsForAccount(AccessToken accessToken) {
- return with()
- .header("Authorization", accessToken.serialize())
- .body("[[\"getMessageList\", {}, \"#0\"]]")
- .post("/jmap")
- .then()
- .extract()
- .body()
- .path(ARGUMENTS + ".messageIds");
- }
-
- private List<String> listMessageIdsInMailbox(AccessToken accessToken, String mailboxId) {
- return with()
- .header("Authorization", accessToken.serialize())
- .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId + "\"]}}, \"#0\"]]")
- .post("/jmap")
- .then()
- .extract()
- .body()
- .path(ARGUMENTS + ".messageIds");
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org