james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [3/6] james-project git commit: JAMES-2195 Factorize JMAP request posting
Date Thu, 26 Oct 2017 22:59:10 GMT
JAMES-2195 Factorize JMAP request posting


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

Branch: refs/heads/master
Commit: e39e1f753f03c430ffed23c426e593b68bd79bb0
Parents: 940b85f
Author: benwa <btellier@linagora.com>
Authored: Tue Oct 24 11:17:11 2017 +0700
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Thu Oct 26 09:01:24 2017 +0200

----------------------------------------------------------------------
 .../cucumber/GetMessageListMethodStepdefs.java  |  45 +++-----
 .../cucumber/GetMessagesMethodStepdefs.java     | 105 ++++++++-----------
 .../integration/cucumber/HttpStepDefs.java      |  56 ++++++++++
 .../cucumber/SetMailboxesMethodStepdefs.java    |  32 ++----
 .../cucumber/SetMessagesMethodStepdefs.java     |  57 ++++------
 5 files changed, 143 insertions(+), 152 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e39e1f75/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
index 6858662..930cc16 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessageListMethodStepdefs.java
@@ -25,8 +25,6 @@ import java.util.List;
 
 import javax.inject.Inject;
 
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
@@ -34,10 +32,6 @@ import org.apache.james.modules.MailboxProbeImpl;
 
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Joiner;
-import com.jayway.jsonpath.Configuration;
-import com.jayway.jsonpath.DocumentContext;
-import com.jayway.jsonpath.JsonPath;
-import com.jayway.jsonpath.Option;
 
 import cucumber.api.java.en.Then;
 import cucumber.api.java.en.When;
@@ -48,16 +42,13 @@ public class GetMessageListMethodStepdefs {
 
     private static final String ARGUMENTS = "[0][1]";
     private final MainStepdefs mainStepdefs;
-    private final UserStepdefs userStepdefs;
+    private final HttpStepDefs httpStepDefs;
     private final GetMessagesMethodStepdefs messagesMethodStepdefs;
 
-    private HttpResponse response;
-    private DocumentContext jsonPath;
-
     @Inject
-    private GetMessageListMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs,
GetMessagesMethodStepdefs messagesMethodStepdefs) {
+    private GetMessageListMethodStepdefs(MainStepdefs mainStepdefs, HttpStepDefs httpStepDefs,
GetMessagesMethodStepdefs messagesMethodStepdefs) {
         this.mainStepdefs = mainStepdefs;
-        this.userStepdefs = userStepdefs;
+        this.httpStepDefs = httpStepDefs;
         this.messagesMethodStepdefs = messagesMethodStepdefs;
     }
 
@@ -72,7 +63,7 @@ public class GetMessageListMethodStepdefs {
                     .serialize())
                 .collect(Guavate.toImmutableList()));
 
-        post(String.format(
+        httpStepDefs.post(String.format(
                 "[[\"getMessageList\", {\"filter\":{" +
                 "    \"inMailboxes\":[\"%s\"]," +
                 "    \"hasKeyword\":\"%s\"" +
@@ -88,7 +79,7 @@ public class GetMessageListMethodStepdefs {
             .getMailbox(MailboxConstants.USER_NAMESPACE, username, mailbox)
             .getMailboxId();
 
-        post(String.format(
+        httpStepDefs.post(String.format(
                 "[[\"getMessageList\", {\"filter\":{" +
                 "    \"inMailboxes\":[\"%s\"]," +
                 "    \"hasKeyword\":\"%s\"" +
@@ -99,7 +90,7 @@ public class GetMessageListMethodStepdefs {
 
     @When("^the user asks for message list with flag \"([^\"]*)\"$")
     public void getMessageList(String flag) throws Exception {
-        post(String.format(
+        httpStepDefs.post(String.format(
             "[[\"getMessageList\", {\"filter\":{" +
                 "    \"hasKeyword\":\"%s\"" +
                 "}}, \"#0\"]]",
@@ -108,32 +99,20 @@ public class GetMessageListMethodStepdefs {
 
     @Then("^the message list is empty$")
     public void assertEmpty() throws Exception {
-        assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).isEmpty();
+        assertThat(httpStepDefs.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).isEmpty();
     }
 
     @Then("^the message list has size (\\d+)")
     public void assertSize(int size) throws Exception {
-        assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).hasSize(size);
+        assertThat(httpStepDefs.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).hasSize(size);
     }
 
     @Then("^the message list contains \"([^\"]*)\"")
     public void assertContains(String messsage) throws Exception {
         MessageId messageId = messagesMethodStepdefs.getMessageId(messsage);
-        assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).contains(messageId.serialize());
-    }
-
-    private void post(String requestBody) throws Exception {
-        response = Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-            .addHeader("Authorization", userStepdefs.authenticate(userStepdefs.getConnectedUser()).serialize())
-            .addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.getMimeType())
-            .bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
-            .execute()
-            .returnResponse();
-        jsonPath = JsonPath.using(Configuration.defaultConfiguration()
-            .addOptions(Option.SUPPRESS_EXCEPTIONS))
-            .parse(response.getEntity().getContent());
+        assertThat(httpStepDefs.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".messageIds")).contains(messageId.serialize());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e39e1f75/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index d4ca9a5..524b46c 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -38,8 +38,6 @@ import javax.mail.Flags;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
 import org.apache.james.jmap.DefaultMailboxes;
 import org.apache.james.jmap.methods.integration.cucumber.util.TableRow;
 import org.apache.james.jmap.model.MessagePreviewGenerator;
@@ -58,10 +56,6 @@ import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableList;
-import com.jayway.jsonpath.Configuration;
-import com.jayway.jsonpath.DocumentContext;
-import com.jayway.jsonpath.JsonPath;
-import com.jayway.jsonpath.Option;
 
 import cucumber.api.DataTable;
 import cucumber.api.java.en.Given;
@@ -84,16 +78,17 @@ public class GetMessagesMethodStepdefs {
 
     private final MainStepdefs mainStepdefs;
     private final UserStepdefs userStepdefs;
+    private final HttpStepDefs httpStepDefs;
     private final Map<String, MessageId> messageIdsByName;
 
-    private HttpResponse response;
-    private DocumentContext jsonPath;
     private List<MessageId> requestedMessageIds;
 
     @Inject
-    private GetMessagesMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs)
{
+    private GetMessagesMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs,
+                                      HttpStepDefs httpStepDefs) {
         this.mainStepdefs = mainStepdefs;
         this.userStepdefs = userStepdefs;
+        this.httpStepDefs = httpStepDefs;
         this.messageIdsByName = new HashMap<>();
     }
 
@@ -399,7 +394,7 @@ public class GetMessagesMethodStepdefs {
 
     @When("^\the user ask for messages using its accountId$")
     public void postWithAccountId() throws Exception {
-        post("[[\"getMessages\", {\"accountId\": \"1\"}, \"#0\"]]");
+        httpStepDefs.post("[[\"getMessages\", {\"accountId\": \"1\"}, \"#0\"]]");
     }
 
     @When("^\"([^\"]*)\" ask for messages using unknown arguments$")
@@ -409,12 +404,12 @@ public class GetMessagesMethodStepdefs {
 
     @When("^the user ask for messages using unknown arguments$")
     public void postWithUnknownArguments() throws Exception {
-        post("[[\"getMessages\", {\"WAT\": true}, \"#0\"]]");
+        httpStepDefs.post("[[\"getMessages\", {\"WAT\": true}, \"#0\"]]");
     }
 
     @When("^the user ask for messages using invalid argument$")
     public void postWithInvalidArguments() throws Exception {
-        post("[[\"getMessages\", {\"ids\": null}, \"#0\"]]");
+        httpStepDefs.post("[[\"getMessages\", {\"ids\": null}, \"#0\"]]");
     }
 
     @When("^\"([^\"]*)\" ask for messages using invalid argument$")
@@ -424,7 +419,7 @@ public class GetMessagesMethodStepdefs {
 
     @When("^the user ask for messages$")
     public void post() throws Exception {
-        post("[[\"getMessages\", {\"ids\": []}, \"#0\"]]");
+        httpStepDefs.post("[[\"getMessages\", {\"ids\": []}, \"#0\"]]");
     }
 
     @When("^\"(.*?)\" ask for messages$")
@@ -461,7 +456,7 @@ public class GetMessagesMethodStepdefs {
             .map(MessageId::serialize)
             .map(toJsonString())
             .collect(Collectors.joining(",", "[", "]" ));
-        post("[[\"getMessages\", {\"ids\": " + serializedIds + "}, \"#0\"]]");
+        httpStepDefs.post("[[\"getMessages\", {\"ids\": " + serializedIds + "}, \"#0\"]]");
     }
 
     private Function<? super String, ? extends String> toJsonString() {
@@ -488,7 +483,7 @@ public class GetMessagesMethodStepdefs {
             .map(toJsonString())
             .collect(Collectors.joining(",", "[", "]" ));
 
-        post("[[\"getMessages\", {\"ids\": " + serializedIds + ", \"properties\": " + serializedProperties
+ "}, \"#0\"]]");
+        httpStepDefs.post("[[\"getMessages\", {\"ids\": " + serializedIds + ", \"properties\":
" + serializedProperties + "}, \"#0\"]]");
     }
 
     private Pair<String, String> entryToPair(Map.Entry<String, String> entry)
{
@@ -499,67 +494,55 @@ public class GetMessagesMethodStepdefs {
         return Joiner.on(": ").join(pair);
     }
 
-    private void post(String requestBody) throws Exception {
-        response = Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-            .addHeader("Authorization", userStepdefs.authenticate(userStepdefs.getConnectedUser()).serialize())
-            .addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.getMimeType())
-            .bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
-            .execute()
-            .returnResponse();
-        jsonPath = JsonPath.using(Configuration.defaultConfiguration()
-            .addOptions(Option.SUPPRESS_EXCEPTIONS))
-            .parse(response.getEntity().getContent());
-    }
-
     @Then("^an error \"([^\"]*)\" is returned$")
     public void error(String type) throws Exception {
-        assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
-        assertThat(jsonPath.<String>read(NAME)).isEqualTo("error");
-        assertThat(jsonPath.<String>read(ARGUMENTS + ".type")).isEqualTo(type);
+        assertThat(httpStepDefs.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpStepDefs.jsonPath.<String>read(NAME)).isEqualTo("error");
+        assertThat(httpStepDefs.jsonPath.<String>read(ARGUMENTS + ".type")).isEqualTo(type);
     }
 
     @Then("^no error is returned$")
     public void noError() throws Exception {
-        assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
-        assertThat(jsonPath.<String>read(NAME)).isEqualTo("messages");
+        assertThat(httpStepDefs.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpStepDefs.jsonPath.<String>read(NAME)).isEqualTo("messages");
     }
 
     @Then("^the list of unknown messages is empty$")
     public void assertNotFoundIsEmpty() {
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).isEmpty();
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).isEmpty();
     }
 
     @Then("^the list of messages is empty$")
     public void assertListIsEmpty() {
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".list")).isEmpty();
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".list")).isEmpty();
     }
 
     @Then("^the description is \"(.*?)\"$")
     public void assertDescription(String description) throws Exception {
-        assertThat(jsonPath.<String>read(ARGUMENTS + ".description")).isEqualTo(description);
+        assertThat(httpStepDefs.jsonPath.<String>read(ARGUMENTS + ".description")).isEqualTo(description);
     }
 
     @Then("^the notFound list should contain \"([^\"]*)\"$")
     public void assertNotFoundListContains(String ids) throws Exception {
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).contains(ids);
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).contains(ids);
     }
 
     @Then("^the notFound list should contain the requested message id$")
     public void assertNotFoundListContainsRequestedMessages() throws Exception {
         ImmutableList<String> elements = requestedMessageIds.stream().map(MessageId::serialize).collect(Guavate.toImmutableList());
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).containsExactlyElementsOf(elements);
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".notFound")).containsExactlyElementsOf(elements);
     }
 
 
     @Then("^the list should contain (\\d+) message$")
     public void assertListContains(int numberOfMessages) throws Exception {
-        assertThat(jsonPath.<List<String>>read(ARGUMENTS + ".list")).hasSize(numberOfMessages);
+        assertThat(httpStepDefs.jsonPath.<List<String>>read(ARGUMENTS + ".list")).hasSize(numberOfMessages);
     }
 
     @Then("^the id of the message is \"([^\"]*)\"$")
     public void assertIdOfTheFirstMessage(String messageName) throws Exception {
         MessageId id = messageIdsByName.get(messageName);
-        assertThat(jsonPath.<String>read(FIRST_MESSAGE + ".id")).isEqualTo(id.serialize());
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".id")).isEqualTo(id.serialize());
     }
 
     @Then("^the message is in \"([^\"]*)\" mailboxes")
@@ -573,7 +556,7 @@ public class GetMessagesMethodStepdefs {
                 .serialize()))
             .distinct()
             .collect(Guavate.toImmutableList());
-        assertThat(jsonPath.<JSONArray>read(FIRST_MESSAGE + ".mailboxIds"))
+        assertThat(httpStepDefs.jsonPath.<JSONArray>read(FIRST_MESSAGE + ".mailboxIds"))
             .hasSize(values.size())
             .containsOnlyElementsOf(values);
     }
@@ -591,7 +574,7 @@ public class GetMessagesMethodStepdefs {
                 .serialize()))
             .distinct()
             .collect(Guavate.toImmutableList());
-        assertThat(jsonPath.<JSONArray>read(FIRST_MESSAGE + ".mailboxIds"))
+        assertThat(httpStepDefs.jsonPath.<JSONArray>read(FIRST_MESSAGE + ".mailboxIds"))
             .hasSize(values.size())
             .containsOnlyElementsOf(values);
     }
@@ -599,44 +582,44 @@ public class GetMessagesMethodStepdefs {
     @Then("^the threadId of the message is \"([^\"]*)\"$")
     public void assertThreadIdOfTheFirstMessage(String threadId) throws Exception {
         MessageId id = messageIdsByName.get(threadId);
-        assertThat(jsonPath.<String>read(FIRST_MESSAGE + ".threadId")).isEqualTo(id.serialize());
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".threadId")).isEqualTo(id.serialize());
     }
 
     @Then("^the subject of the message is \"([^\"]*)\"$")
     public void assertSubjectOfTheFirstMessage(String subject) throws Exception {
-        assertThat(jsonPath.<String>read(FIRST_MESSAGE + ".subject")).isEqualTo(subject);
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".subject")).isEqualTo(subject);
     }
 
     @Then("^the textBody of the message is \"([^\"]*)\"$")
     public void assertTextBodyOfTheFirstMessage(String textBody) throws Exception {
-        assertThat(jsonPath.<String>read(FIRST_MESSAGE + ".textBody")).isEqualTo(StringEscapeUtils.unescapeJava(textBody));
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".textBody")).isEqualTo(StringEscapeUtils.unescapeJava(textBody));
     }
 
     @Then("^the htmlBody of the message is \"([^\"]*)\"$")
     public void assertHtmlBodyOfTheFirstMessage(String htmlBody) throws Exception {
-        assertThat(jsonPath.<String>read(FIRST_MESSAGE + ".htmlBody")).isEqualTo(StringEscapeUtils.unescapeJava(htmlBody));
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".htmlBody")).isEqualTo(StringEscapeUtils.unescapeJava(htmlBody));
     }
 
     @Then("^the isUnread of the message is \"([^\"]*)\"$")
     public void assertIsUnreadOfTheFirstMessage(String isUnread) throws Exception {
-        assertThat(jsonPath.<Boolean>read(FIRST_MESSAGE + ".isUnread")).isEqualTo(Boolean.valueOf(isUnread));
+        assertThat(httpStepDefs.jsonPath.<Boolean>read(FIRST_MESSAGE + ".isUnread")).isEqualTo(Boolean.valueOf(isUnread));
     }
 
     @Then("^the preview of the message is \"([^\"]*)\"$")
     public void assertPreviewOfTheFirstMessage(String preview) throws Exception {
-        String actual = jsonPath.<String>read(FIRST_MESSAGE + ".preview").replace("\n",
" ");
+        String actual = httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".preview").replace("\n",
" ");
         assertThat(actual).isEqualToIgnoringWhitespace(StringEscapeUtils.unescapeJava(preview));
     }
 
     @Then("^the preview of the message is not empty$")
     public void assertPreviewOfTheFirstMessageIsNotEmpty() throws Exception {
-        String actual = jsonPath.<String>read(FIRST_MESSAGE + ".preview");
+        String actual = httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".preview");
         assertThat(actual).isNotEmpty();
     }
 
     @Then("^the preview should not contain consecutive spaces or blank characters$")
     public void assertPreviewShouldBeNormalized() throws Exception {
-        String actual = jsonPath.<String>read(FIRST_MESSAGE + ".preview");
+        String actual = httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".preview");
         assertThat(actual).hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH)
             .doesNotMatch("  ")
             .doesNotContain(StringUtils.CR)
@@ -645,37 +628,37 @@ public class GetMessagesMethodStepdefs {
 
     @Then("^the headers of the message contains:$")
     public void assertHeadersOfTheFirstMessage(DataTable headers) throws Exception {
-        assertThat(jsonPath.<Map<String, String>>read(FIRST_MESSAGE + ".headers")).containsAllEntriesOf(headers.asMap(String.class,
String.class));
+        assertThat(httpStepDefs.jsonPath.<Map<String, String>>read(FIRST_MESSAGE
+ ".headers")).containsAllEntriesOf(headers.asMap(String.class, String.class));
     }
 
     @Then("^the date of the message is \"([^\"]*)\"$")
     public void assertDateOfTheFirstMessage(String date) throws Exception {
-        assertThat(jsonPath.<String>read(FIRST_MESSAGE + ".date")).isEqualTo(date);
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".date")).isEqualTo(date);
     }
 
     @Then("^the hasAttachment of the message is \"([^\"]*)\"$")
     public void assertHasAttachmentOfTheFirstMessage(String hasAttachment) throws Exception
{
-        assertThat(jsonPath.<Boolean>read(FIRST_MESSAGE + ".hasAttachment")).isEqualTo(Boolean.valueOf(hasAttachment));
+        assertThat(httpStepDefs.jsonPath.<Boolean>read(FIRST_MESSAGE + ".hasAttachment")).isEqualTo(Boolean.valueOf(hasAttachment));
     }
 
     @Then("^the list of attachments of the message is empty$")
     public void assertAttachmentsOfTheFirstMessageIsEmpty() throws Exception {
-        assertThat(jsonPath.<List<Object>>read(ATTACHMENTS)).isEmpty();
+        assertThat(httpStepDefs.jsonPath.<List<Object>>read(ATTACHMENTS)).isEmpty();
     }
 
     @Then("^the property \"([^\"]*)\" of the message is null$")
     public void assertPropertyIsNull(String property) throws Exception {
-        assertThat(jsonPath.<String>read(FIRST_MESSAGE + "." + property + ".date")).isNull();
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + "." + property
+ ".date")).isNull();
     }
 
     @Then("^the list of attachments of the message contains (\\d+) attachments?$")
     public void assertAttachmentsHasSize(int numberOfAttachments) throws Exception {
-        assertThat(jsonPath.<List<Object>>read(ATTACHMENTS)).hasSize(numberOfAttachments);
+        assertThat(httpStepDefs.jsonPath.<List<Object>>read(ATTACHMENTS)).hasSize(numberOfAttachments);
     }
 
     @Then("^the list of attachments of the message contains only one attachment with cid
\"([^\"]*)\"?$")
     public void assertAttachmentsAndItsCid(String cid) throws Exception {
-        assertThat(jsonPath.<String>read(FIRST_ATTACHMENT + ".cid")).isEqualTo(cid);
+        assertThat(httpStepDefs.jsonPath.<String>read(FIRST_ATTACHMENT + ".cid")).isEqualTo(cid);
     }
 
     @Then("^the first attachment is:$")
@@ -690,28 +673,28 @@ public class GetMessagesMethodStepdefs {
 
     @Then("^the preview of the message contains: (.*)$")
     public void assertPreviewOfMessageShouldBePrintedWithEncoding(List<String> preview)
throws Exception {
-        String actual = jsonPath.<String>read(FIRST_MESSAGE + ".preview");
+        String actual = httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".preview");
         assertThat(actual).contains(preview);
     }
 
     @Then("^the keywords of the message is (.*)$")
     public void assertKeywordsOfMessageShouldDisplay(List<String> keywords) throws
Exception {
-        assertThat(jsonPath.<Map<String, Boolean>>read(FIRST_MESSAGE + ".keywords").keySet())
+        assertThat(httpStepDefs.jsonPath.<Map<String, Boolean>>read(FIRST_MESSAGE
+ ".keywords").keySet())
             .containsOnlyElementsOf(keywords);
     }
 
     @Then("^the message has no keyword$")
     public void assertMessageHasNoKeyword() throws Exception {
-        assertThat(jsonPath.<Map<String, Boolean>>read(FIRST_MESSAGE + ".keywords"))
+        assertThat(httpStepDefs.jsonPath.<Map<String, Boolean>>read(FIRST_MESSAGE
+ ".keywords"))
             .isNullOrEmpty();
     }
 
     private void assertAttachment(String attachment, DataTable attachmentProperties) {
         attachmentProperties.asList(TableRow.class)
-            .forEach(entry -> assertThat(jsonPath.<Object>read(attachment + "."
+ entry.getKey())).isEqualTo(entry.getValue()));
+            .forEach(entry -> assertThat(httpStepDefs.jsonPath.<Object>read(attachment
+ "." + entry.getKey())).isEqualTo(entry.getValue()));
     }
 
     public String getBlobId() {
-        return jsonPath.<String>read(FIRST_MESSAGE + ".blobId");
+        return httpStepDefs.jsonPath.<String>read(FIRST_MESSAGE + ".blobId");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e39e1f75/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/HttpStepDefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/HttpStepDefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/HttpStepDefs.java
new file mode 100644
index 0000000..cbf57d5
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/HttpStepDefs.java
@@ -0,0 +1,56 @@
+/****************************************************************
+ * 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.integration.cucumber;
+
+import javax.inject.Inject;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.fluent.Request;
+
+import com.jayway.jsonpath.Configuration;
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.Option;
+
+public class HttpStepDefs {
+    private final MainStepdefs mainStepdefs;
+    private final UserStepdefs userStepdefs;
+
+    public HttpResponse response;
+    public DocumentContext jsonPath;
+
+    @Inject
+    public HttpStepDefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+        this.userStepdefs = userStepdefs;
+    }
+
+    public void post(String requestBody) throws Exception {
+        response = Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
+            .addHeader("Authorization", userStepdefs.authenticate(userStepdefs.getConnectedUser()).serialize())
+            .addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.getMimeType())
+            .bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON)
+            .execute()
+            .returnResponse();
+        jsonPath = JsonPath.using(Configuration.defaultConfiguration()
+            .addOptions(Option.SUPPRESS_EXCEPTIONS))
+            .parse(response.getEntity().getContent());
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e39e1f75/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
index dfd785d..b83afac 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -29,9 +29,6 @@ import java.util.stream.IntStream;
 import javax.inject.Inject;
 import javax.mail.Flags;
 
-import org.apache.http.HttpResponse;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.entity.ContentType;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -55,11 +52,13 @@ public class SetMailboxesMethodStepdefs {
 
     private final MainStepdefs mainStepdefs;
     private final UserStepdefs userStepdefs;
+    private final HttpStepDefs httpStepDefs;
 
     @Inject
-    private SetMailboxesMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs)
{
+    private SetMailboxesMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs,
HttpStepDefs httpStepDefs) {
         this.mainStepdefs = mainStepdefs;
         this.userStepdefs = userStepdefs;
+        this.httpStepDefs = httpStepDefs;
     }
 
     @Given("^mailbox \"([^\"]*)\" with (\\d+) messages$")
@@ -81,7 +80,6 @@ public class SetMailboxesMethodStepdefs {
 
     @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"")
     public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable
{
-        String username = userStepdefs.getConnectedUser();
         Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", userStepdefs.getConnectedUser(),
actualMailboxName);
         String mailboxId = mailbox.getMailboxId().serialize();
         String requestBody =
@@ -97,11 +95,7 @@ public class SetMailboxesMethodStepdefs {
                     "    \"#0\"" +
                     "  ]" +
                     "]";
-        Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-            .addHeader("Authorization", userStepdefs.authenticate(username).serialize())
-            .bodyString(requestBody, ContentType.APPLICATION_JSON)
-            .execute()
-            .discardContent();
+        httpStepDefs.post(requestBody);
     }
 
     @When("^moving mailbox \"([^\"]*)\" to \"([^\"]*)\"$")
@@ -125,12 +119,7 @@ public class SetMailboxesMethodStepdefs {
                     "    \"#0\"" +
                     "  ]" +
                     "]";
-
-        Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-            .addHeader("Authorization", userStepdefs.authenticate(username).serialize())
-            .bodyString(requestBody, ContentType.APPLICATION_JSON)
-            .execute()
-            .discardContent();
+        httpStepDefs.post(requestBody);
     }
 
     @Then("^mailbox \"([^\"]*)\" contains (\\d+) messages$")
@@ -141,13 +130,12 @@ public class SetMailboxesMethodStepdefs {
         String mailboxId = mailbox.getMailboxId().serialize();
 
         Awaitility.await().atMost(Duration.FIVE_SECONDS).pollDelay(slowPacedPollInterval).pollInterval(slowPacedPollInterval).until(()
-> {
-            HttpResponse response = Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-                    .addHeader("Authorization", userStepdefs.authenticate(username).serialize())
-                    .bodyString("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\""
+ mailboxId + "\"]}}, \"#0\"]]", ContentType.APPLICATION_JSON)
-                    .execute().returnResponse();
+            String requestBody = "[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\""
+ mailboxId + "\"]}}, \"#0\"]]";
+
+            httpStepDefs.post(requestBody);
 
-            assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200);
-            DocumentContext jsonPath = JsonPath.parse(response.getEntity().getContent());
+            assertThat(httpStepDefs.response.getStatusLine().getStatusCode()).isEqualTo(200);
+            DocumentContext jsonPath = JsonPath.parse(httpStepDefs.response.getEntity().getContent());
             assertThat(jsonPath.<String>read(NAME)).isEqualTo("messageList");
 
             return jsonPath.<List<String>>read(ARGUMENTS + ".messageIds").size()
== messageCount;

http://git-wip-us.apache.org/repos/asf/james-project/blob/e39e1f75/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
index 64a0d0b..7676d9a 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
@@ -25,8 +25,6 @@ import java.util.stream.Collectors;
 import javax.inject.Inject;
 import javax.mail.Flags;
 
-import org.apache.http.entity.ContentType;
-import org.apache.http.client.fluent.Request;
 import org.apache.james.jmap.model.Keywords;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
@@ -43,25 +41,26 @@ public class SetMessagesMethodStepdefs {
 
     private final MainStepdefs mainStepdefs;
     private final UserStepdefs userStepdefs;
+    private final HttpStepDefs httpStepDefs;
     private final GetMessagesMethodStepdefs getMessagesMethodStepdefs;
 
     @Inject
-    private SetMessagesMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs,
GetMessagesMethodStepdefs getMessagesMethodStepdefs) {
+    private SetMessagesMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs,
HttpStepDefs httpStepDefs, GetMessagesMethodStepdefs getMessagesMethodStepdefs) {
         this.mainStepdefs = mainStepdefs;
         this.userStepdefs = userStepdefs;
+        this.httpStepDefs = httpStepDefs;
         this.getMessagesMethodStepdefs = getMessagesMethodStepdefs;
     }
 
     @When("^the user move \"([^\"]*)\" to mailbox \"([^\"]*)\"")
     public void moveMessageToMailbox(String message, String mailbox) throws Throwable {
-        String username = userStepdefs.getConnectedUser();
         MessageId messageId = getMessagesMethodStepdefs.getMessageId(message);
         MailboxId mailboxId = mainStepdefs.jmapServer
             .getProbe(MailboxProbeImpl.class)
             .getMailbox(MailboxConstants.USER_NAMESPACE, userStepdefs.getConnectedUser(),
mailbox)
             .getMailboxId();
 
-        String requestBody = "[" +
+        httpStepDefs.post("[" +
             "  [" +
             "    \"setMessages\","+
             "    {" +
@@ -71,12 +70,7 @@ public class SetMessagesMethodStepdefs {
             "    }," +
             "    \"#0\"" +
             "  ]" +
-            "]";
-        Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-            .addHeader("Authorization", userStepdefs.authenticate(username).serialize())
-            .bodyString(requestBody, ContentType.APPLICATION_JSON)
-            .execute()
-            .discardContent();
+            "]");
         mainStepdefs.awaitMethod.run();
     }
 
@@ -92,7 +86,8 @@ public class SetMessagesMethodStepdefs {
             .getMailbox(MailboxConstants.USER_NAMESPACE, userName, destinationMailbox)
             .getMailboxId();
 
-        String requestBody = "[" +
+
+        httpStepDefs.post("[" +
             "  [" +
             "    \"setMessages\","+
             "    {" +
@@ -102,39 +97,29 @@ public class SetMessagesMethodStepdefs {
             "    }," +
             "    \"#0\"" +
             "  ]" +
-            "]";
-        Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-            .addHeader("Authorization", userStepdefs.authenticate(userName).serialize())
-            .bodyString(requestBody, ContentType.APPLICATION_JSON)
-            .execute()
-            .discardContent();
+            "]");
         mainStepdefs.awaitMethod.run();
     }
 
-    @When("^\"([^\"]*)\" set flags on \"([^\"]*)\" to \"([^\"]*)\"")
-    public void setFlags(String username, String message, List<String> keywords) throws
Throwable {
+    @When("^the user set flags on \"([^\"]*)\" to \"([^\"]*)\"")
+    public void setFlags(String message, List<String> keywords) throws Throwable {
         MessageId messageId = getMessagesMethodStepdefs.getMessageId(message);
         String keywordString = keywords
             .stream()
             .map(value -> "\"" + value + "\" : true")
             .collect(Collectors.joining(","));
 
-        Request.Post(mainStepdefs.baseUri().setPath("/jmap").build())
-            .addHeader("Authorization", userStepdefs.authenticate(username).serialize())
-            .bodyString("[" +
-                "  [" +
-                "    \"setMessages\","+
-                "    {" +
-                "      \"update\": { \"" + messageId.serialize() + "\" : {" +
-                "        \"keywords\": {" + keywordString + "}" +
-                "      }}" +
-                "    }," +
-                "    \"#0\"" +
-                "  ]" +
-                "]",
-                ContentType.APPLICATION_JSON)
-            .execute()
-            .discardContent();
+        httpStepDefs.post("[" +
+            "  [" +
+            "    \"setMessages\","+
+            "    {" +
+            "      \"update\": { \"" + messageId.serialize() + "\" : {" +
+            "        \"keywords\": {" + keywordString + "}" +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]");
         mainStepdefs.awaitMethod.run();
     }
 


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