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 2016/06/06 11:06:21 UTC

[1/4] james-project git commit: JAMES-1742 Retrieve attachment in download endpoint

Repository: james-project
Updated Branches:
  refs/heads/master 74fd6c223 -> 81d88bf73


JAMES-1742 Retrieve attachment in download endpoint


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

Branch: refs/heads/master
Commit: 81d88bf73d655e698afb7ba436649a5d273a03ab
Parents: 4df388b
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed Jun 1 12:46:37 2016 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Jun 6 13:05:37 2016 +0200

----------------------------------------------------------------------
 .../inmemory/mail/InMemoryAttachmentMapper.java |  3 ++
 .../cucumber/CassandraDownloadCucumberTest.java |  2 +-
 .../cassandra/cucumber/CassandraStepdefs.java   | 21 +++++---
 .../integration/cucumber/DownloadStepdefs.java  | 53 ++++++++++++++++--
 .../resources/cucumber/DownloadEndpoint.feature |  6 +--
 .../test/resources/cucumber/DownloadGet.feature | 16 ++++++
 .../src/test/resources/eml/oneAttachment.eml    | 38 +++++++++++++
 .../cucumber/MemoryDownloadCucumberTest.java    |  2 +-
 .../org/apache/james/jmap/DownloadServlet.java  | 48 +++++++++++++++++
 .../apache/james/jmap/DownloadServletTest.java  | 57 ++++++++++++++++++++
 10 files changed, 229 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
index d4decc9..126fc61 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
@@ -39,6 +39,9 @@ public class InMemoryAttachmentMapper implements AttachmentMapper {
 
     @Override
     public Attachment getAttachment(AttachmentId attachmentId) throws AttachmentNotFoundException {
+        if (!attachmentsById.containsKey(attachmentId)) {
+            throw new AttachmentNotFoundException(attachmentId.getId());
+        }
         return attachmentsById.get(attachmentId);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java
index 1ad24f8..428d9df 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java
@@ -25,7 +25,7 @@ import cucumber.api.CucumberOptions;
 import cucumber.api.junit.Cucumber;
 
 @RunWith(Cucumber.class)
-@CucumberOptions(features="classpath:cucumber/DownloadEndpoint.feature",
+@CucumberOptions(features={"classpath:cucumber/DownloadEndpoint.feature", "classpath:cucumber/DownloadGet.feature"},
                 glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"})
 public class CassandraDownloadCucumberTest {
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
index fa2f77a..0ba38d1 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.jmap.cassandra.cucumber;
 
+import java.util.Arrays;
+
 import javax.inject.Inject;
 
 import org.apache.james.CassandraJamesServerMain;
@@ -29,6 +31,8 @@ import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
 import org.apache.james.modules.CassandraJmapServerModule;
 import org.junit.rules.TemporaryFolder;
 
+import com.github.fge.lambdas.runnable.ThrowingRunnable;
+
 import cucumber.api.java.After;
 import cucumber.api.java.Before;
 import cucumber.runtime.java.guice.ScenarioScoped;
@@ -59,16 +63,21 @@ public class CassandraStepdefs {
 
     @After
     public void tearDown() {
-        tearDown(() -> mainStepdefs.tearDown());
-        tearDown(() -> embeddedElasticSearch.after());
-        tearDown(() -> temporaryFolder.delete());
+        ignoreFailures(() -> mainStepdefs.tearDown(),
+                () -> embeddedElasticSearch.after(),
+                () -> temporaryFolder.delete());
     }
 
-    private void tearDown(Runnable cleaningFunction) {
+    private void ignoreFailures(ThrowingRunnable... cleaners) {
+        Arrays.stream(cleaners)
+            .forEach(this::runSwallowingException);
+    }
+    
+    private void runSwallowingException(Runnable run) {
         try {
-            cleaningFunction.run();
+            run.run();
         } catch (Exception e) {
-            e.printStackTrace();
+            // ignore
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
index e703f23..8b0ce48 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
@@ -20,8 +20,16 @@
 package org.apache.james.jmap.methods.integration.cucumber;
 
 import static com.jayway.restassured.RestAssured.with;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.Date;
 
 import javax.inject.Inject;
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
 
 import com.jayway.restassured.http.ContentType;
 import com.jayway.restassured.response.Response;
@@ -45,9 +53,13 @@ public class DownloadStepdefs {
         this.userStepdefs = userStepdefs;
     }
 
-    @Given("^an unknown current user with username \"([^\"]*)\" and password \"([^\"]*)\"$")
-    public void createUserWithPassword(String username, String password) throws Exception {
-        mainStepdefs.jmapServer.serverProbe().addUser(username, password);
+    @Given("^a message containing an attachment$")
+    public void appendMessageWithAttachment() throws Exception {
+        mainStepdefs.jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, userStepdefs.username, "INBOX");
+        MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, userStepdefs.username, "INBOX");
+
+        mainStepdefs.jmapServer.serverProbe().appendMessage(userStepdefs.username, mailboxPath,
+                ClassLoader.getSystemResourceAsStream("eml/oneAttachment.eml"), new Date(), false, new Flags());
     }
 
     @When("^checking for the availability of the attachment endpoint$")
@@ -85,10 +97,28 @@ public class DownloadStepdefs {
             .get("/download/");
     }
 
+    @When("^getting the attachment with its correct blobId$")
+    public void getDownloadWithKnownBlobId() throws Throwable {
+        response = with()
+                .accept(ContentType.JSON)
+                .contentType(ContentType.JSON)
+                .header("Authorization", userStepdefs.accessToken.serialize())
+                .get("/download/4000c5145f633410b80be368c44e1c394bff9437");
+    }
+
+    @When("^getting the attachment with an unknown blobId$")
+    public void getDownloadWithUnknownBlobId() throws Throwable {
+        response = with()
+                .accept(ContentType.JSON)
+                .contentType(ContentType.JSON)
+                .header("Authorization", userStepdefs.accessToken.serialize())
+                .get("/download/badbadbadbadbadbadbadbadbadbadbadbadbadb");
+    }
+
     @Then("^the user should be authorized$")
-    public void httpOkStatus() throws Exception {
+    public void httpStatusDifferentFromUnauthorized() throws Exception {
         response.then()
-            .statusCode(200);
+            .statusCode(not(401));
     }
 
     @Then("^the user should not be authorized$")
@@ -102,4 +132,17 @@ public class DownloadStepdefs {
         response.then()
             .statusCode(400);
     }
+
+    @Then("^the user should receive that attachment$")
+    public void httpOkStatusAndExpectedContent() throws Throwable {
+        response.then()
+            .statusCode(200)
+            .content(notNullValue());
+    }
+
+    @Then("^the user should receive a not found response$")
+    public void httpNotFoundStatus() throws Throwable {
+        response.then()
+            .statusCode(404);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
index a483d8e..b5f9d3b 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
@@ -10,8 +10,7 @@ Feature: Download endpoint
     When checking for the availability of the attachment endpoint
     Then the user should be authorized
 
-  Scenario: An unknown user should initiate the access to the download endpoint
-    Given an unknown current user with username "unknown@domain.tld" and password "secret"
+  Scenario: An unauthenticated user should initiate the access to the download endpoint
     When checking for the availability of the attachment endpoint
     Then the user should be authorized
 
@@ -20,8 +19,7 @@ Feature: Download endpoint
     When asking for an attachment
     Then the user should be authorized
 
-  Scenario: An unknown user should not have access to the download endpoint
-    Given an unknown current user with username "unknown@domain.tld" and password "secret"
+  Scenario: An unauthenticated user should not have access to the download endpoint
     When asking for an attachment
     Then the user should not be authorized
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
new file mode 100644
index 0000000..cd92d8a
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadGet.feature
@@ -0,0 +1,16 @@
+Feature: Download GET
+  As a James user
+  I want to retrieve my attachments
+
+  Background:
+    Given a domain named "domain.tld"
+    And a current user with username "username@domain.tld" and password "secret"
+
+  Scenario: Getting an attachment previously stored
+    Given a message containing an attachment
+    When getting the attachment with its correct blobId
+    Then the user should receive that attachment
+
+  Scenario: Getting an attachment with an unknown blobId
+    When getting the attachment with an unknown blobId
+    Then the user should receive a not found response

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/oneAttachment.eml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/oneAttachment.eml b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/oneAttachment.eml
new file mode 100644
index 0000000..ca0abe7
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/oneAttachment.eml
@@ -0,0 +1,38 @@
+Mail content:
+To: "=?utf-8?B?UmFuaSBBc3NhZg==?=" <ra...@jri.obm.lng.org>
+Subject: =?utf-8?B?VHIuIDogUGhvdG9zICE=?=
+Importance: Normal
+MIME-Version: 1.0
+Content-Type: multipart/mixed;
+	boundary="----=_Part_0_1330682067197"
+
+------=_Part_0_1330682067197
+Content-Type: multipart/alternative;
+	boundary="----=_Part_2_1330682067197"
+
+------=_Part_2_1330682067197
+Content-Type: text/plain;
+	charset= utf-8
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline
+
+Content of part 1-1
+------=_Part_2_1330682067197
+Content-Type: text/html;
+	charset= utf-8
+Content-Transfer-Encoding: 8bit
+Content-Disposition: inline
+
+<b>Content of part 1-2</b>
+------=_Part_2_1330682067197--
+
+------=_Part_0_1330682067197
+Content-Type: application/octet-stream
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment;
+	filename="gimp.png"
+
+iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAALxklEQVR4Ae2Xe0xUZ97H5X4RiyAXEARURBSYCzNnLjMwwAx3huGOIBcUFJERAUVRq+KlwHABFdu+b9+0766x1W21ttnUtE3rul6aGNtm3XbdWncjaa3VXrZRK6IgfPd3Tp6wOGmyo0v/cOMknxwy5xzO7/P8LueZaWlpaU80TwWeCvy3CcRwXJlUqp39RApIOE4i5hQPxBz30hMpIJIrjktkseMimfzPUyoglilTf/XVl8u1Ik4xrOJEEMu4wSkVEMmVZ6VSTeivFXy0TDZfIlfc0qil0KpIQM59P6UCUk71lVShPD1t2jT7qQ4+Sq32prq/GhfHjSXFSxGvEfMCQ1MsoLzOadT3pArFwBQ3LSdRqK4mJyfcz0xRwaCLRVKcBDEybmxqBRTKH8uXpEOj0/1MD3wuMTHR8T9adY4LoOD3KuPj7xYVGlGYo0e6gUNKoowkpKBmHpXJZO5TKXCrpjwT5pWFSM1IvROrVH0hksujf+laAHYWi8XT+nsKyIlvVKlSeVSu0twtXpI/Yq4rR2lBKoxpamQmK5Gm55CcIAP1wxAvOWUCEk4xVLvchIaVedi8rgq1NSXjqnjdHcrGayK5yhStVPpbLLvE/Xt6Tnf3Wu529XSM9fZ13Wzbse2kJiGhK1ap/ETCqe5lGLNum+trxnZsbca6tcuwJM+AvKw4mNI1yEpVURYUSE2S8wJ3RSKN35QJUJPdM6/IQ8vaCmzdZMbObU2w7G7BhhbzeEFR4e2SsrIRChqnz5zE999/h9HREXz19SDefOt1dPW0Y8e2Frywtx0vDnRg57NrUVdTgJJ8PYpyEpBvjEdOhvahLIg55YOioiKHRxKgjwPBEaHEQzfz/3DH9mb07+nGsbeO4MjRw+jts8DS3or/GdiNnr4ufP6XC/jhh+9w587PuHdvGLdv38SNG9fwwYfvon9vN3Zvb0Td8
 lxUlqSirCgZpSRQnJuIgmwdcikL2elqZKUwAbni0aaQvb19M3HT2dnlloODw5Cdnd0d+rKVRFz48xkm0+i+gX5cv34NP/30I86fP4ePPjqL3n4LOjq24O2338CVK1/i22+v4ssvL+HTTz+B2WzGqlUrcfr0HzCwvw9Na8pRXZaBqtI0VBSnYGmBgUooEYUmHYQyyhDKCClJCl7gus0C9DE5OjkNpefkoXvPPugzjIiMEcN9+vQ7JHKFzvs1tzTdO3P2lBD8wYMHce3aNVBTYk1DPXp62/HHUx/g0qXPSOIyBgcHwX/u37+PiMhIiCViHP7dAbRuqAc/CJbxAktIoJAXSEKRiZURCRhJwJCoAPXcRZsF7B0dL8cq1RgeHgb/+fziX6E1pPCjDJ5e3iOUmcHWzRvHz398ThAoKSnB5b/9HYbUdMwJmUPl04GTJ9/DhQvn8cYbh/D++++D/1y/cYOvZbi6uWHvvj48u7kRgsDSdEGgjARKSOChPiCBpAQFpBx3ymYBWuXR9Zu2gH0wPj6O7KISyNRxiBJLMeMZz/GcXOP4a4cOCAJ5eXmY5eMDL29v6PUJ6O7aQX1xGOfOncLx429h5syZMDc2I05vQJQ0Fq6uriTZifWNy60yYCXAMqDVcmMiTtlrswAZPMgtLsXY2Jgg8PXVb5CYngWpSoMFi6MRsTAS7rSKnZZdeP3IIarv89ixow21tTXoaN9KE6kefdQLJ04cx5kzH0Cp5OA9axYCgoIx08sLCQlxsHS3o646F9XlGSQwuQeSJveAICBTKm49yuaRb+Drco0W6zdTM75zHJW1dVAlGvjXOULDF2ABCQQFz4FcEomdbc3o7qGpQ+za3oQtzWXY3LwUHc9twfPP9+Gd40ephN5GW9tmJCXpsHnLBrq+HS1N1VhRkYnlZemooilUzk+hgokpNPEuyExWUdlx99lb2GaBV+eGh48kJKciVq0VSofqX1j9wDkhCA4Ng0gihb+vF5
 pXF2K9uQgta4qxoWEJNq4l6LihoQRtW5vQRSu9d6AH//vSAI1cCzq7dmNdQxVWVmahhq3+RP3n/6t8cjO1yE5TQ59EDaxQsN8Ctk+hUH50JhqSESONFQKfF0GrToH7+AfAf3YQdIlJcHNzwdrafDTWFaCJRJqJdfVFAvzfTfR9c30xrfYytLbUotlchtXVOULwND6FICuXPLz61uWj1iruUePv4gvbZgGWhv2+fn5DesrCXCob34BAPniBoJBQJOj18KMM1NfkYM2KXGFL0VCbxwsJ0N/Cd2Y6x1+zmrYdq5YZJ1Z+OU2ejGTK6rwg4QX20Phkq59mUPLz/264SBRMAva2Sky8hWka/T4gMPBuVnY2OJUaIXPnYU7YXCQlJ0MsFkMaE05BZdPbNJtW1iRQTytMCH9T0MK5VVVC4ELN8ytPZSNsG6IjQ5C4wAkVWl+UZsYiP1sonYl9kIpWPzpW9gLFMp1wJhyYhM1bCUfqh5dp7A3J5PIHqWnpyDQaIZFKMMvbU3iD0hikwLKEAGt5KFhCWGUKlk2ZdGGrUEQlkqaXC+LBgV4ok7tik8Edr1fOwKbkGajXeaBcH4aclFik6hXC9sE7ICCK4vAhZhAutkj8UlMsopL6jZ2d/acOjo7fBAbPuW/Qax7QHkYoBZIQgqUjQ5guQm3nG3VCqeg0IsSKFmDRwlBERYZBHDUPxvhICvoZdGR54IudEfisg8Nva+aiQTcDpVq/B4qY8Ffo2QuIYCsJVk62C9gRTiyVPkFhYSqxnLuk0qqH83P0FGwmVi3PpbLJp2MeZSSbxGjlSa6yRJjxgsxSNmmWUCZo2gjjMj9LgwpDGMzxbji20h9Xu6JxpV+FI+aF4016z/u1atcPq/P1DTqdOoae7U24E46PI+DMVsCfCHN2do6OWBzdS9vqf3Bq1bAxM4FKJZMalqbQmkq00N6+eU0FGlaV0gurgErJiPLiNHpZJfN7fiqnJNawwrYZJoMYtfF
 eVErT8fG6WbjaGYHBPg6v1EWNdXa2Yeuz6w75+PgEshicHkfAhXiGCCDmEosJGaELCgnpiJJIByUK5YjBED++tDANtctoGq0uw4amGmxaX0vHFSRUhfqVJVhRlYeK0iwSSSaBeCoxJTQablwk40aTYvwvrta6DL9c7DF6eYsPeixtOPjqAbzw4v6hrp7OC+XV5QsfV8CJ2fsRIUQkISXURCpR6enl1b1g0eLP+d8KsQrlqEqjGtHr48ezMmhMFmWiqsyEylIjivNSKPBEJBu0UKoVD0Qy+djC6Oir7h4eA/R/mvw87FdXK13PbsyPHOnt7aAtyQmBQ4dfHe3p7by187ntOXTdPCKDcLZVwIFwI7yIQGLepCxomUQ50Ui0UTD/5+Pr925waOifFi6OuiaKlQ1JOOUYMU6CozGx8uHIqJjr/kFBJ11cXJ6ne7YSZmIpkUJoWxqXv2fp2n133/49d44de1OQOHr0CAIC/Meio6MhkUhA110jNhL21gLWEvaTGtmbmM0kFk3KRCKRRZQR9cQGoo3oIHppJPfTsY/oJtqJbUQLUUeUshVNIJSExMvLK9rT03P+upbGVd09nZfo9/XPJlM2/P390dnZKRAWFsZL8JT+OwG7SRLuxEzCn5VTOBHFRJREPKEn0ggTUcRWtoJRyr4zscwlEXHsXinLbDgbn37sWW7bdm2L9/Pzu+nu7o6NGzeitbWVshEAlokvCPsJARskXFlPeDORYJaRCCYjZuWlYNnREFqGhlCxczJ27WJ279xJgXsRHmyAOLJnnyTAQxkVjvPnz4evry94eWuBX5RgOEwSmU54ErOYzGxiDhHGpMKJCCvC2bkwFvBsFrQ3m3bTWeBO7Fl2jPUErKFy44/p1gK2ijgSzkzGnfBgQcxkAfkwfBk+DG9iJrvWg93ryoJ2nBy41bMPWQvQ7pk/LrMSeCQRe8JhkpATk3JhQblZ4crOOVsFLGwTrAOfDLv3AAErWq0FHldm
 ktQEDlbYM+yseYTnLSOGCDD6H1/ARilrpuD/LyYuMoFDVgJPBqx3/p84YS3wpInonmQBxlOBpwJPBf4JszXhha5WvGwAAAAASUVORK5CYII=
+
+------=_Part_0_1330682067197--
+

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java
index b6a0f3e..3784393 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java
@@ -25,7 +25,7 @@ import cucumber.api.CucumberOptions;
 import cucumber.api.junit.Cucumber;
 
 @RunWith(Cucumber.class)
-@CucumberOptions(features="classpath:cucumber/DownloadEndpoint.feature",
+@CucumberOptions(features={"classpath:cucumber/DownloadEndpoint.feature", "classpath:cucumber/DownloadGet.feature"},
                 glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"})
 public class MemoryDownloadCucumberTest {
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
index d4a7597..e0c1e98 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
@@ -19,18 +19,43 @@
 package org.apache.james.jmap;
 
 import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
+import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
 import static javax.servlet.http.HttpServletResponse.SC_OK;
 
+import java.io.IOException;
+
+import javax.inject.Inject;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.AttachmentNotFoundException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.mail.AttachmentMapper;
+import org.apache.james.mailbox.store.mail.model.Attachment;
+import org.apache.james.mailbox.store.mail.model.AttachmentId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 
 public class DownloadServlet extends HttpServlet {
 
     private static final String ROOT_URL = "/";
+    private static final Logger LOGGER = LoggerFactory.getLogger(DownloadServlet.class);
+
+    private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+
+    @Inject
+    @VisibleForTesting DownloadServlet(MailboxSessionMapperFactory mailboxSessionMapperFactory) {
+        this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+    }
 
     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
@@ -38,7 +63,30 @@ public class DownloadServlet extends HttpServlet {
         if (Strings.isNullOrEmpty(pathInfo) || pathInfo.equals(ROOT_URL)) {
             resp.setStatus(SC_BAD_REQUEST);
         } else {
+            download(getMailboxSession(req), blobIdFrom(pathInfo), resp);
+        }
+    }
+
+    @VisibleForTesting String blobIdFrom(String pathInfo) {
+        return pathInfo.substring(1);
+    }
+
+    @VisibleForTesting void download(MailboxSession mailboxSession, String blobId, HttpServletResponse resp) {
+        try {
+            AttachmentMapper attachmentMapper = mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession);
+            Attachment attachment = attachmentMapper.getAttachment(AttachmentId.from(blobId));
+            IOUtils.copy(attachment.getStream(), resp.getOutputStream());
             resp.setStatus(SC_OK);
+        } catch (AttachmentNotFoundException e) {
+            LOGGER.info(String.format("Attachment '%s' not found", blobId), e);
+            resp.setStatus(SC_NOT_FOUND);
+        } catch (MailboxException | IOException e) {
+            LOGGER.error("Error while downloading", e);
+            resp.setStatus(SC_INTERNAL_SERVER_ERROR);
         }
     }
+
+    private MailboxSession getMailboxSession(HttpServletRequest req) {
+        return (MailboxSession) req.getAttribute(AuthenticationFilter.MAILBOX_SESSION);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/81d88bf7/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
new file mode 100644
index 0000000..ccf4992
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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 org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.junit.Test;
+
+public class DownloadServletTest {
+
+    @Test
+    public void blobIdFromShouldSkipTheFirstCharacter() {
+        String blobId = new DownloadServlet(null).blobIdFrom("1234");
+        assertThat(blobId).isEqualTo("234");
+    }
+
+    @Test
+    public void downloadMayFailWhenUnableToCreateAttachmentMapper() throws Exception {
+        MailboxSession mailboxSession = mock(MailboxSession.class);
+        MailboxSessionMapperFactory mailboxSessionMapperFactory = mock(MailboxSessionMapperFactory.class);
+        when(mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession))
+            .thenThrow(new MailboxException());
+
+        DownloadServlet testee = new DownloadServlet(mailboxSessionMapperFactory);
+
+        String blobId = null;
+        HttpServletResponse resp = mock(HttpServletResponse.class);
+        testee.download(mailboxSession, blobId, resp);
+
+        verify(resp).setStatus(500);
+    }
+}


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


[3/4] james-project git commit: JAMES-1742 Introduce the JMAP download endpoint

Posted by ad...@apache.org.
JAMES-1742 Introduce the JMAP download endpoint


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

Branch: refs/heads/master
Commit: 4df388be2d7b867f472b7c094070e21eb397cd8f
Parents: 3848954
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed May 25 16:26:24 2016 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Jun 6 13:05:37 2016 +0200

----------------------------------------------------------------------
 .../apache/james/http/jetty/Configuration.java  |  20 ++-
 .../james/http/jetty/ConfigurationTest.java     |  49 +++++-
 server/pom.xml                                  |   6 +-
 .../cassandra-jmap-integration-testing/pom.xml  |   4 +-
 ...CassandraSetMailboxesMethodCucumberTest.java |  31 ----
 .../CassandraSetMailboxesMethodStepdefs.java    |  60 -------
 .../cucumber/CassandraDownloadCucumberTest.java |  31 ++++
 ...CassandraSetMailboxesMethodCucumberTest.java |  31 ++++
 .../cassandra/cucumber/CassandraStepdefs.java   |  74 ++++++++
 .../jmap-integration-testing-common/pom.xml     |   5 +
 .../integration/SetMailboxesMethodStepdefs.java | 174 -------------------
 .../integration/cucumber/DownloadStepdefs.java  | 105 +++++++++++
 .../integration/cucumber/MainStepdefs.java      |  48 +++++
 .../cucumber/SetMailboxesMethodStepdefs.java    | 150 ++++++++++++++++
 .../integration/cucumber/UserStepdefs.java      |  54 ++++++
 .../resources/cucumber/DownloadEndpoint.feature |  31 ++++
 .../memory-jmap-integration-testing/pom.xml     |   2 +-
 .../MemorySetMailboxesMethodCucumberTest.java   |  31 ----
 .../MemorySetMailboxesMethodStepdefs.java       |  54 ------
 .../cucumber/MemoryDownloadCucumberTest.java    |  31 ++++
 .../MemorySetMailboxesMethodCucumberTest.java   |  31 ++++
 .../jmap/memory/cucumber/MemoryStepdefs.java    |  60 +++++++
 .../org/apache/james/jmap/DownloadServlet.java  |  44 +++++
 .../java/org/apache/james/jmap/JMAPServer.java  |   7 +-
 24 files changed, 773 insertions(+), 360 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
----------------------------------------------------------------------
diff --git a/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java b/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
index 362a1a2..f638e9f 100644
--- a/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
+++ b/server/container/jetty/src/main/java/org/apache/james/http/jetty/Configuration.java
@@ -43,6 +43,7 @@ public class Configuration {
     public static class Builder {
         
         private static final Range<Integer> VALID_PORT_RANGE = Range.closed(1, 65535);
+        private static final String TEMPLATE_LEVEL1 = "/*";
 
         private final ImmutableMap.Builder<String, Object> mappings;
         private final ImmutableListMultimap.Builder<String, Object> filters;
@@ -104,15 +105,28 @@ public class Configuration {
         }
         
         public ServletBinder serve(String mappingUrl) {
-            Preconditions.checkNotNull(mappingUrl);
-            Preconditions.checkArgument(!mappingUrl.trim().isEmpty());
+            urlPreconditions(mappingUrl);
             return new ServletBinder(mappingUrl);
         }
         
+        public ServletBinder serveAsOneLevelTemplate(String mappingUrl) {
+            urlPreconditions(mappingUrl);
+            return new ServletBinder(mappingUrl + TEMPLATE_LEVEL1);
+        }
+        
         public FilterBinder filter(String mappingUrl) {
+            urlPreconditions(mappingUrl);
+            return new FilterBinder(mappingUrl);
+        }
+        
+        public FilterBinder filterAsOneLevelTemplate(String mappingUrl) {
+            urlPreconditions(mappingUrl);
+            return new FilterBinder(mappingUrl + TEMPLATE_LEVEL1);
+        }
+
+        private void urlPreconditions(String mappingUrl) {
             Preconditions.checkNotNull(mappingUrl);
             Preconditions.checkArgument(!mappingUrl.trim().isEmpty());
-            return new FilterBinder(mappingUrl);
         }
 
         public Builder port(int port) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java b/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
index 1cc00bb..3311873 100644
--- a/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
+++ b/server/container/jetty/src/test/java/org/apache/james/http/jetty/ConfigurationTest.java
@@ -54,12 +54,15 @@ public class ConfigurationTest {
                 .and(anotherFilter).only()
                 .filter("/456")
                 .with(spyFilter).only()
+                .serveAsOneLevelTemplate("/level")
+                .with(Ok200.class)
                 .build();
         assertThat(testee.getPort()).isPresent().contains(2000);
         assertThat(testee.getMappings())
-            .hasSize(2)
+            .hasSize(3)
             .containsEntry("/abc", Ok200.class)
-            .containsEntry("/def", bad400);
+            .containsEntry("/def", bad400)
+            .containsEntry("/level/*", Ok200.class);
         assertThat(testee.getFilters().asMap())
             .hasSize(2)
             .containsEntry("/123", ImmutableList.of(CoolFilter.class, anotherFilter))
@@ -121,6 +124,21 @@ public class ConfigurationTest {
         assertThatThrownBy(() -> Configuration.builder().serve("/").with((Class<? extends Servlet>)null)).isInstanceOf(NullPointerException.class);
     }
     
+    @Test
+    public void shouldNotAllowNullServletAsOneLevelTemplateMappingUrl() {
+        assertThatThrownBy(() -> Configuration.builder().serveAsOneLevelTemplate(null)).isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void shouldNotAllowEmptyServletAsOneLevelTemplateMappingUrl() {
+        assertThatThrownBy(() -> Configuration.builder().serveAsOneLevelTemplate("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+
+    @Test
+    public void shouldNotAllowWhitespaceOnlyServletAsOneLevelTemplateMappingUrl() {
+        assertThatThrownBy(() -> Configuration.builder().serveAsOneLevelTemplate("    ")).isInstanceOf(IllegalArgumentException.class);
+    }
 
     @Test
     public void shouldNotAllowNullFilterMappingUrl() {
@@ -148,4 +166,31 @@ public class ConfigurationTest {
     public void shouldNotAllowNullFilterClassname() {
         assertThatThrownBy(() -> Configuration.builder().filter("/").with((Class<? extends Filter>)null)).isInstanceOf(NullPointerException.class);
     }
+
+    @Test
+    public void shouldNotAllowNullFilterAsOneLevelTemplateMappingUrl() {
+        assertThatThrownBy(() -> Configuration.builder().filterAsOneLevelTemplate(null)).isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void shouldNotAllowEmptyFilterAsOneLevelTemplateMappingUrl() {
+        assertThatThrownBy(() -> Configuration.builder().filterAsOneLevelTemplate("")).isInstanceOf(IllegalArgumentException.class);
+    }
+
+
+    @Test
+    public void shouldNotAllowWhitespaceOnlyFilterAsOneLevelTemplateMappingUrl() {
+        assertThatThrownBy(() -> Configuration.builder().filterAsOneLevelTemplate("    ")).isInstanceOf(IllegalArgumentException.class);
+    }
+    
+
+    @Test
+    public void shouldNotAllowNullFilterAsOneLevelTemplate() {
+        assertThatThrownBy(() -> Configuration.builder().filterAsOneLevelTemplate("/").with((Filter)null)).isInstanceOf(NullPointerException.class);
+    }
+    
+    @Test
+    public void shouldNotAllowNullFilterClassnameAsOneLevelTemplate() {
+        assertThatThrownBy(() -> Configuration.builder().filterAsOneLevelTemplate("/").with((Class<? extends Filter>)null)).isInstanceOf(NullPointerException.class);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 037263f..6f582bb 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -1428,6 +1428,11 @@
             </dependency>
             <dependency>
                 <groupId>info.cukes</groupId>
+                <artifactId>cucumber-guice</artifactId>
+                <version>${cucumber.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>info.cukes</groupId>
                 <artifactId>cucumber-java</artifactId>
                 <version>${cucumber.version}</version>
             </dependency>
@@ -1440,7 +1445,6 @@
                 <groupId>info.cukes</groupId>
                 <artifactId>cucumber-picocontainer</artifactId>
                 <version>${cucumber.version}</version>
-                <scope>test</scope>
             </dependency>
             <dependency>
                 <groupId>com.github.fge</groupId>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
index 19b7410..e832966 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
@@ -189,12 +189,12 @@
                 </dependency>
                 <dependency>
                     <groupId>info.cukes</groupId>
-                    <artifactId>cucumber-junit</artifactId>
+                    <artifactId>cucumber-guice</artifactId>
                     <scope>test</scope>
                 </dependency>
                 <dependency>
                     <groupId>info.cukes</groupId>
-                    <artifactId>cucumber-picocontainer</artifactId>
+                    <artifactId>cucumber-junit</artifactId>
                     <scope>test</scope>
                 </dependency>
                 <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java
deleted file mode 100644
index a859fa9..0000000
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/****************************************************************
- * 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.cassandra;
-
-import org.junit.runner.RunWith;
-
-import cucumber.api.CucumberOptions;
-import cucumber.api.junit.Cucumber;
-
-@RunWith(Cucumber.class)
-@CucumberOptions(features="classpath:cucumber/MailboxModification.feature",
-                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra"})
-public class CassandraSetMailboxesMethodCucumberTest {
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java
deleted file mode 100644
index fe80ae9..0000000
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************
- * 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.cassandra;
-
-import org.apache.james.CassandraJamesServerMain;
-import org.apache.james.GuiceJamesServer;
-import org.apache.james.backends.cassandra.EmbeddedCassandra;
-import org.apache.james.jmap.methods.integration.SetMailboxesMethodStepdefs;
-import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
-import org.apache.james.modules.CassandraJmapServerModule;
-import org.junit.rules.TemporaryFolder;
-
-import cucumber.api.java.After;
-import cucumber.api.java.Before;
-
-public class CassandraSetMailboxesMethodStepdefs {
-    private final SetMailboxesMethodStepdefs mainStepdefs;
-    private TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
-    private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer();
-
-    public CassandraSetMailboxesMethodStepdefs(SetMailboxesMethodStepdefs mainStepdefs) {
-        this.mainStepdefs = mainStepdefs;
-    }
-
-    @Before
-    public void init() throws Exception {
-        temporaryFolder.create();
-        embeddedElasticSearch.before();
-        mainStepdefs.jmapServer = new GuiceJamesServer()
-                .combineWith(CassandraJamesServerMain.cassandraServerModule)
-                .overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra));
-        mainStepdefs.awaitMethod = () -> embeddedElasticSearch.awaitForElasticSearch();
-        mainStepdefs.init();
-    }
-
-    @After
-    public void tearDown() {
-        mainStepdefs.tearDown();
-        embeddedElasticSearch.after();
-        temporaryFolder.delete();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java
new file mode 100644
index 0000000..1ad24f8
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraDownloadCucumberTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.cassandra.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/DownloadEndpoint.feature",
+                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"})
+public class CassandraDownloadCucumberTest {
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java
new file mode 100644
index 0000000..6e1ee33
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.cassandra.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/MailboxModification.feature",
+                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"})
+public class CassandraSetMailboxesMethodCucumberTest {
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
new file mode 100644
index 0000000..fa2f77a
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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.cassandra.cucumber;
+
+import javax.inject.Inject;
+
+import org.apache.james.CassandraJamesServerMain;
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.backends.cassandra.EmbeddedCassandra;
+import org.apache.james.jmap.methods.integration.cucumber.MainStepdefs;
+import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
+import org.apache.james.modules.CassandraJmapServerModule;
+import org.junit.rules.TemporaryFolder;
+
+import cucumber.api.java.After;
+import cucumber.api.java.Before;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class CassandraStepdefs {
+
+    private final MainStepdefs mainStepdefs;
+    private TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
+    private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer();
+
+    @Inject
+    private CassandraStepdefs(MainStepdefs mainStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+    }
+
+    @Before
+    public void init() throws Exception {
+        temporaryFolder.create();
+        embeddedElasticSearch.before();
+        mainStepdefs.jmapServer = new GuiceJamesServer()
+                .combineWith(CassandraJamesServerMain.cassandraServerModule)
+                .overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra));
+        mainStepdefs.awaitMethod = () -> embeddedElasticSearch.awaitForElasticSearch();
+        mainStepdefs.init();
+    }
+
+    @After
+    public void tearDown() {
+        tearDown(() -> mainStepdefs.tearDown());
+        tearDown(() -> embeddedElasticSearch.after());
+        tearDown(() -> temporaryFolder.delete());
+    }
+
+    private void tearDown(Runnable cleaningFunction) {
+        try {
+            cleaningFunction.run();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
index 7adbda6..408e7a2 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
@@ -171,6 +171,11 @@
                 </dependency>
                 <dependency>
                     <groupId>info.cukes</groupId>
+                    <artifactId>cucumber-guice</artifactId>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>info.cukes</groupId>
                     <artifactId>cucumber-java</artifactId>
                     <scope>test</scope>
                 </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java
deleted file mode 100644
index 6b6fa58..0000000
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/****************************************************************
- * 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;
-
-import static com.jayway.restassured.RestAssured.given;
-import static com.jayway.restassured.RestAssured.with;
-import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
-import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasSize;
-
-import java.io.ByteArrayInputStream;
-import java.util.Date;
-import java.util.stream.IntStream;
-
-import javax.mail.Flags;
-
-import org.apache.james.GuiceJamesServer;
-import org.apache.james.jmap.JmapAuthentication;
-import org.apache.james.jmap.api.access.AccessToken;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-
-import com.github.fge.lambdas.Throwing;
-import com.google.common.base.Charsets;
-import com.jayway.restassured.RestAssured;
-import com.jayway.restassured.http.ContentType;
-
-import cucumber.api.java.en.Given;
-import cucumber.api.java.en.Then;
-import cucumber.api.java.en.When;
-
-public class SetMailboxesMethodStepdefs {
-    private static final String NAME = "[0][0]";
-    private static final String ARGUMENTS = "[0][1]";
-
-    public GuiceJamesServer jmapServer;
-    public Runnable awaitMethod = () -> {};
-
-    private AccessToken accessToken;
-    private String username;
-
-    public void init() throws Exception {
-        jmapServer.start();
-        RestAssured.port = jmapServer.getJmapPort();
-        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
-        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
-    }
-    
-    public void tearDown() {
-        jmapServer.stop();
-    }
-    
-
-    @Given("^a domain named \"([^\"]*)\"$")
-    public void createDomain(String domain) throws Throwable {
-        jmapServer.serverProbe().addDomain(domain);
-    }
-
-    @Given("^a current user with username \"([^\"]*)\" and password \"([^\"]*)\"$")
-    public void createUserWithPasswordAndAuthenticate(String username, String password) throws Throwable {
-        this.username = username;
-        jmapServer.serverProbe().addUser(username, password);
-        accessToken = JmapAuthentication.authenticateJamesUser(username, password);
-    }
-
-    @Given("^mailbox \"([^\"]*)\" with (\\d+) messages$")
-    public void mailboxWithMessages(String mailboxName, int messageCount) throws Throwable {
-        jmapServer.serverProbe().createMailbox("#private", username, mailboxName);
-        MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, username, mailboxName);
-        IntStream
-            .range(0, messageCount)
-            .forEach(Throwing.intConsumer(i -> appendMessage(mailboxPath, i)));
-        awaitMethod.run();
-    }
-
-    private void appendMessage(MailboxPath mailboxPath, int i) throws MailboxException {
-        String content = "Subject: test" + i + "\r\n\r\n"
-                + "testBody" + i;
-        jmapServer.serverProbe().appendMessage(username, mailboxPath,
-                new ByteArrayInputStream(content.getBytes()), new Date(), false, new Flags());
-    }
-
-    @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"")
-    public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable {
-        Mailbox mailbox = jmapServer.serverProbe().getMailbox("#private", username, actualMailboxName);
-        String mailboxId = mailbox.getMailboxId().serialize();
-        String requestBody =
-                "[" +
-                    "  [ \"setMailboxes\"," +
-                    "    {" +
-                    "      \"update\": {" +
-                    "        \"" + mailboxId + "\" : {" +
-                    "          \"name\" : \"" + newMailboxName + "\"" +
-                    "        }" +
-                    "      }" +
-                    "    }," +
-                    "    \"#0\"" +
-                    "  ]" +
-                    "]";
-
-        with()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
-            .header("Authorization", this.accessToken.serialize())
-            .body(requestBody)
-            .post("/jmap");
-    }
-
-    @When("^moving mailbox \"([^\"]*)\" to \"([^\"]*)\"$")
-    public void movingMailbox(String actualMailboxPath, String newParentMailboxPath) throws Throwable {
-        Mailbox mailbox = jmapServer.serverProbe().getMailbox("#private", username, actualMailboxPath);
-        String mailboxId = mailbox.getMailboxId().serialize();
-        Mailbox parent = jmapServer.serverProbe().getMailbox("#private", username, newParentMailboxPath);
-        String parentId = parent.getMailboxId().serialize();
-
-        String requestBody =
-                "[" +
-                    "  [ \"setMailboxes\"," +
-                    "    {" +
-                    "      \"update\": {" +
-                    "        \"" + mailboxId + "\" : {" +
-                    "          \"parentId\" : \"" + parentId + "\"" +
-                    "        }" +
-                    "      }" +
-                    "    }," +
-                    "    \"#0\"" +
-                    "  ]" +
-                    "]";
-
-        with()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
-            .header("Authorization", this.accessToken.serialize())
-            .body(requestBody)
-            .post("/jmap");
-    }
-
-    @Then("^mailbox \"([^\"]*)\" contains (\\d+) messages$")
-    public void mailboxContainsMessages(String mailboxName, int messageCount) throws Throwable {
-        Mailbox mailbox = jmapServer.serverProbe().getMailbox("#private", username, mailboxName);
-        String mailboxId = mailbox.getMailboxId().serialize();
-        given()
-            .accept(ContentType.JSON)
-            .contentType(ContentType.JSON)
-            .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId + "\"]}}, \"#0\"]]")
-        .when()
-            .post("/jmap")
-        .then()
-            .statusCode(200)
-            .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", hasSize(messageCount));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
new file mode 100644
index 0000000..e703f23
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/DownloadStepdefs.java
@@ -0,0 +1,105 @@
+/****************************************************************
+ * 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 static com.jayway.restassured.RestAssured.with;
+
+import javax.inject.Inject;
+
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.response.Response;
+import com.jayway.restassured.specification.RequestSpecification;
+
+import cucumber.api.java.en.Given;
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class DownloadStepdefs {
+
+    private final UserStepdefs userStepdefs;
+    private final MainStepdefs mainStepdefs;
+    private Response response;
+
+    @Inject
+    private DownloadStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+        this.userStepdefs = userStepdefs;
+    }
+
+    @Given("^an unknown current user with username \"([^\"]*)\" and password \"([^\"]*)\"$")
+    public void createUserWithPassword(String username, String password) throws Exception {
+        mainStepdefs.jmapServer.serverProbe().addUser(username, password);
+    }
+
+    @When("^checking for the availability of the attachment endpoint$")
+    public void optionDownload() throws Throwable {
+        RequestSpecification requestSpecification = with()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON);
+
+        if (userStepdefs.accessToken != null) {
+            requestSpecification.header("Authorization", userStepdefs.accessToken.serialize());
+        }
+
+        response = requestSpecification.options("/download/myBlob");
+    }
+
+    @When("^asking for an attachment$")
+    public void getDownload() throws Exception {
+        RequestSpecification requestSpecification = with()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON);
+
+        if (userStepdefs.accessToken != null) {
+            requestSpecification.header("Authorization", userStepdefs.accessToken.serialize());
+        }
+
+        response = requestSpecification.get("/download/myBlob");
+    }
+
+    @When("^asking for an attachment without blobId parameter$")
+    public void getDownloadWithoutBlobId() throws Throwable {
+        response = with()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .header("Authorization", userStepdefs.accessToken.serialize())
+            .get("/download/");
+    }
+
+    @Then("^the user should be authorized$")
+    public void httpOkStatus() throws Exception {
+        response.then()
+            .statusCode(200);
+    }
+
+    @Then("^the user should not be authorized$")
+    public void httpUnauthorizedStatus() throws Exception {
+        response.then()
+            .statusCode(401);
+    }
+
+    @Then("^the user should receive a bad request response$")
+    public void httpBadRequestStatus() throws Throwable {
+        response.then()
+            .statusCode(400);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
new file mode 100644
index 0000000..d7ed5c9
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MainStepdefs.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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 static com.jayway.restassured.config.EncoderConfig.encoderConfig;
+import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+
+import org.apache.james.GuiceJamesServer;
+
+import com.google.common.base.Charsets;
+import com.jayway.restassured.RestAssured;
+
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class MainStepdefs {
+
+    public GuiceJamesServer jmapServer;
+    public Runnable awaitMethod = () -> {};
+
+    public void init() throws Exception {
+        jmapServer.start();
+        RestAssured.port = jmapServer.getJmapPort();
+        RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8));
+        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
+    }
+    
+    public void tearDown() {
+        jmapServer.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/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
new file mode 100644
index 0000000..52d0214
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -0,0 +1,150 @@
+/****************************************************************
+ * 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 static com.jayway.restassured.RestAssured.given;
+import static com.jayway.restassured.RestAssured.with;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+
+import java.io.ByteArrayInputStream;
+import java.util.Date;
+import java.util.stream.IntStream;
+
+import javax.inject.Inject;
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+
+import com.github.fge.lambdas.Throwing;
+import com.jayway.restassured.http.ContentType;
+
+import cucumber.api.java.en.Given;
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class SetMailboxesMethodStepdefs {
+
+    private static final String NAME = "[0][0]";
+    private static final String ARGUMENTS = "[0][1]";
+
+    private final MainStepdefs mainStepdefs;
+    private final UserStepdefs userStepdefs;
+
+    @Inject
+    private SetMailboxesMethodStepdefs(MainStepdefs mainStepdefs, UserStepdefs userStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+        this.userStepdefs = userStepdefs;
+    }
+
+    @Given("^mailbox \"([^\"]*)\" with (\\d+) messages$")
+    public void mailboxWithMessages(String mailboxName, int messageCount) throws Throwable {
+        mainStepdefs.jmapServer.serverProbe().createMailbox("#private", userStepdefs.username, mailboxName);
+        MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, userStepdefs.username, mailboxName);
+        IntStream
+            .range(0, messageCount)
+            .forEach(Throwing.intConsumer(i -> appendMessage(mailboxPath, i)));
+        mainStepdefs.awaitMethod.run();
+    }
+
+    private void appendMessage(MailboxPath mailboxPath, int i) throws MailboxException {
+        String content = "Subject: test" + i + "\r\n\r\n"
+                + "testBody" + i;
+        mainStepdefs.jmapServer.serverProbe().appendMessage(userStepdefs.username, mailboxPath,
+                new ByteArrayInputStream(content.getBytes()), new Date(), false, new Flags());
+    }
+
+    @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"")
+    public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable {
+        Mailbox mailbox = mainStepdefs.jmapServer.serverProbe().getMailbox("#private", userStepdefs.username, actualMailboxName);
+        String mailboxId = mailbox.getMailboxId().serialize();
+        String requestBody =
+                "[" +
+                    "  [ \"setMailboxes\"," +
+                    "    {" +
+                    "      \"update\": {" +
+                    "        \"" + mailboxId + "\" : {" +
+                    "          \"name\" : \"" + newMailboxName + "\"" +
+                    "        }" +
+                    "      }" +
+                    "    }," +
+                    "    \"#0\"" +
+                    "  ]" +
+                    "]";
+
+        with()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .header("Authorization", userStepdefs.accessToken.serialize())
+            .body(requestBody)
+            .post("/jmap");
+    }
+
+    @When("^moving mailbox \"([^\"]*)\" to \"([^\"]*)\"$")
+    public void movingMailbox(String actualMailboxPath, String newParentMailboxPath) throws Throwable {
+        Mailbox mailbox = mainStepdefs.jmapServer.serverProbe().getMailbox("#private", userStepdefs.username, actualMailboxPath);
+        String mailboxId = mailbox.getMailboxId().serialize();
+        Mailbox parent = mainStepdefs.jmapServer.serverProbe().getMailbox("#private", userStepdefs.username, newParentMailboxPath);
+        String parentId = parent.getMailboxId().serialize();
+
+        String requestBody =
+                "[" +
+                    "  [ \"setMailboxes\"," +
+                    "    {" +
+                    "      \"update\": {" +
+                    "        \"" + mailboxId + "\" : {" +
+                    "          \"parentId\" : \"" + parentId + "\"" +
+                    "        }" +
+                    "      }" +
+                    "    }," +
+                    "    \"#0\"" +
+                    "  ]" +
+                    "]";
+
+        with()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .header("Authorization", userStepdefs.accessToken.serialize())
+            .body(requestBody)
+            .post("/jmap");
+    }
+
+    @Then("^mailbox \"([^\"]*)\" contains (\\d+) messages$")
+    public void mailboxContainsMessages(String mailboxName, int messageCount) throws Throwable {
+        Mailbox mailbox = mainStepdefs.jmapServer.serverProbe().getMailbox("#private", userStepdefs.username, mailboxName);
+        String mailboxId = mailbox.getMailboxId().serialize();
+        given()
+            .accept(ContentType.JSON)
+            .contentType(ContentType.JSON)
+            .header("Authorization", userStepdefs.accessToken.serialize())
+            .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId + "\"]}}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("messageList"))
+            .body(ARGUMENTS + ".messageIds", hasSize(messageCount));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
new file mode 100644
index 0000000..01f0496
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/UserStepdefs.java
@@ -0,0 +1,54 @@
+/****************************************************************
+ * 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.james.jmap.JmapAuthentication;
+import org.apache.james.jmap.api.access.AccessToken;
+
+import cucumber.api.java.en.Given;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class UserStepdefs {
+
+    private final MainStepdefs mainStepdefs;
+    protected String username;
+    protected AccessToken accessToken;
+
+    @Inject
+    private UserStepdefs(MainStepdefs mainStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+    }
+
+    @Given("^a domain named \"([^\"]*)\"$")
+    public void createDomain(String domain) throws Throwable {
+        mainStepdefs.jmapServer.serverProbe().addDomain(domain);
+    }
+
+    @Given("^a current user with username \"([^\"]*)\" and password \"([^\"]*)\"$")
+    public void createUserWithPasswordAndAuthenticate(String username, String password) throws Throwable {
+        this.username = username;
+        mainStepdefs.jmapServer.serverProbe().addUser(username, password);
+        accessToken = JmapAuthentication.authenticateJamesUser(username, password);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
new file mode 100644
index 0000000..a483d8e
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/DownloadEndpoint.feature
@@ -0,0 +1,31 @@
+Feature: Download endpoint
+  As a James user
+  I want to access to the download endpoint
+
+  Background:
+    Given a domain named "domain.tld"
+
+  Scenario: A known user should initiate the access to the download endpoint
+    Given a current user with username "username@domain.tld" and password "secret"
+    When checking for the availability of the attachment endpoint
+    Then the user should be authorized
+
+  Scenario: An unknown user should initiate the access to the download endpoint
+    Given an unknown current user with username "unknown@domain.tld" and password "secret"
+    When checking for the availability of the attachment endpoint
+    Then the user should be authorized
+
+  Scenario: A known user should have access to the download endpoint
+    Given a current user with username "username@domain.tld" and password "secret"
+    When asking for an attachment
+    Then the user should be authorized
+
+  Scenario: An unknown user should not have access to the download endpoint
+    Given an unknown current user with username "unknown@domain.tld" and password "secret"
+    When asking for an attachment
+    Then the user should not be authorized
+
+  Scenario: A known user should not have access to the download endpoint without a blobId
+    Given a current user with username "username@domain.tld" and password "secret"
+    When asking for an attachment without blobId parameter
+    Then the user should receive a bad request response

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
index 4254a7e..5a078e4 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
@@ -182,7 +182,7 @@
                 </dependency>
                 <dependency>
                     <groupId>info.cukes</groupId>
-                    <artifactId>cucumber-picocontainer</artifactId>
+                    <artifactId>cucumber-guice</artifactId>
                     <scope>test</scope>
                 </dependency>
                 <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java
deleted file mode 100644
index a856c0b..0000000
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/****************************************************************
- * 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.memory;
-
-import org.junit.runner.RunWith;
-
-import cucumber.api.CucumberOptions;
-import cucumber.api.junit.Cucumber;
-
-@RunWith(Cucumber.class)
-@CucumberOptions(features="classpath:cucumber/MailboxModification.feature",
-                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory"})
-public class MemorySetMailboxesMethodCucumberTest {
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java
deleted file mode 100644
index cbdca46..0000000
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************
- * 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.memory;
-
-import org.apache.james.GuiceJamesServer;
-import org.apache.james.MemoryJamesServerMain;
-import org.apache.james.jmap.methods.integration.SetMailboxesMethodStepdefs;
-import org.apache.james.jmap.servers.MemoryJmapServerModule;
-import org.junit.rules.TemporaryFolder;
-
-import cucumber.api.java.After;
-import cucumber.api.java.Before;
-
-public class MemorySetMailboxesMethodStepdefs {
-    private final SetMailboxesMethodStepdefs mainStepdefs;
-    private final TemporaryFolder temporaryFolder;
-
-    public MemorySetMailboxesMethodStepdefs(SetMailboxesMethodStepdefs mainStepdefs) {
-        this.mainStepdefs = mainStepdefs;
-        this.temporaryFolder = new TemporaryFolder();
-    }
-
-    @Before
-    public void init() throws Exception {
-        temporaryFolder.create();
-        mainStepdefs.jmapServer = new GuiceJamesServer()
-                .combineWith(MemoryJamesServerMain.inMemoryServerModule)
-                .overrideWith(new MemoryJmapServerModule(temporaryFolder));
-        mainStepdefs.init();
-    }
-
-    @After
-    public void tearDown() {
-        mainStepdefs.tearDown();
-        temporaryFolder.delete();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java
new file mode 100644
index 0000000..b6a0f3e
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryDownloadCucumberTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.memory.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/DownloadEndpoint.feature",
+                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"})
+public class MemoryDownloadCucumberTest {
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java
new file mode 100644
index 0000000..52b25fd
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.memory.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features="classpath:cucumber/MailboxModification.feature",
+                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"})
+public class MemorySetMailboxesMethodCucumberTest {
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
new file mode 100644
index 0000000..2aa16b1
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * 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.memory.cucumber;
+
+import javax.inject.Inject;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.jmap.methods.integration.cucumber.MainStepdefs;
+import org.apache.james.jmap.servers.MemoryJmapServerModule;
+import org.junit.rules.TemporaryFolder;
+
+import cucumber.api.java.After;
+import cucumber.api.java.Before;
+import cucumber.runtime.java.guice.ScenarioScoped;
+
+@ScenarioScoped
+public class MemoryStepdefs {
+
+    private final MainStepdefs mainStepdefs;
+    private final TemporaryFolder temporaryFolder;
+
+    @Inject
+    private MemoryStepdefs(MainStepdefs mainStepdefs) {
+        this.mainStepdefs = mainStepdefs;
+        this.temporaryFolder = new TemporaryFolder();
+    }
+
+    @Before
+    public void init() throws Exception {
+        temporaryFolder.create();
+        mainStepdefs.jmapServer = new GuiceJamesServer()
+                .combineWith(MemoryJamesServerMain.inMemoryServerModule)
+                .overrideWith(new MemoryJmapServerModule(temporaryFolder));
+        mainStepdefs.init();
+    }
+
+    @After
+    public void tearDown() {
+        mainStepdefs.tearDown();
+        temporaryFolder.delete();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
new file mode 100644
index 0000000..d4a7597
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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 javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.google.common.base.Strings;
+
+public class DownloadServlet extends HttpServlet {
+
+    private static final String ROOT_URL = "/";
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
+        String pathInfo = req.getPathInfo();
+        if (Strings.isNullOrEmpty(pathInfo) || pathInfo.equals(ROOT_URL)) {
+            resp.setStatus(SC_BAD_REQUEST);
+        } else {
+            resp.setStatus(SC_OK);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/4df388be/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
index c3b0665..5161412 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
@@ -39,7 +39,7 @@ public class JMAPServer implements Configurable {
 
     @Inject
     private JMAPServer(JMAPConfiguration jmapConfiguration,
-                       AuthenticationServlet authenticationServlet, JMAPServlet jmapServlet,
+                       AuthenticationServlet authenticationServlet, JMAPServlet jmapServlet, DownloadServlet downloadServlet,
                        AuthenticationFilter authenticationFilter, FirstUserConnectionFilter firstUserConnectionFilter) {
 
         server = JettyHttpServer.create(
@@ -55,6 +55,11 @@ public class JMAPServer implements Configurable {
                             .with(new AllowAllCrossOriginRequests(bypass(authenticationFilter).on("OPTIONS").only()))
                             .and(firstUserConnectionFilter)
                             .only()
+                        .serveAsOneLevelTemplate(JMAPUrls.DOWNLOAD)
+                            .with(downloadServlet)
+                        .filterAsOneLevelTemplate(JMAPUrls.DOWNLOAD)
+                            .with(new AllowAllCrossOriginRequests(bypass(authenticationFilter).on("OPTIONS").only()))
+                            .only()
                         .build());
     }
 


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


[4/4] james-project git commit: JAMES-1742 Introduce JMAP URLs constants

Posted by ad...@apache.org.
JAMES-1742 Introduce JMAP URLs constants


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

Branch: refs/heads/master
Commit: c20adf87c2ea607e8e510e1e7368613e1916f211
Parents: 74fd6c2
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed May 25 11:35:33 2016 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Jun 6 13:05:37 2016 +0200

----------------------------------------------------------------------
 .../james/jmap/AuthenticationServlet.java       |  4 +--
 .../java/org/apache/james/jmap/JMAPServer.java  |  8 +++---
 .../java/org/apache/james/jmap/JMAPUrls.java    | 26 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c20adf87/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
index 2984a7d..ed4b11e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
@@ -179,7 +179,7 @@ public class AuthenticationServlet extends HttpServlet {
         AccessTokenResponse response = AccessTokenResponse
             .builder()
             .accessToken(accessTokenManager.grantAccessToken(username))
-            .api("/jmap")
+            .api(JMAPUrls.JMAP)
             .eventSource("/notImplemented")
             .upload("/notImplemented")
             .download("/notImplemented")
@@ -192,7 +192,7 @@ public class AuthenticationServlet extends HttpServlet {
         resp.setStatus(HttpServletResponse.SC_OK);
         EndPointsResponse response = EndPointsResponse
             .builder()
-            .api("/jmap")
+            .api(JMAPUrls.JMAP)
             .eventSource("/notImplemented")
             .upload("/notImplemented")
             .download("/notImplemented")

http://git-wip-us.apache.org/repos/asf/james-project/blob/c20adf87/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
index 17ac730..c3b0665 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPServer.java
@@ -44,14 +44,14 @@ public class JMAPServer implements Configurable {
 
         server = JettyHttpServer.create(
                 configurationBuilderFor(jmapConfiguration)
-                        .serve("/authentication")
+                        .serve(JMAPUrls.AUTHENTICATION)
                             .with(authenticationServlet)
-                        .filter("/authentication")
+                        .filter(JMAPUrls.AUTHENTICATION)
                             .with(new AllowAllCrossOriginRequests(bypass(authenticationFilter).on("POST").and("OPTIONS").only()))
                             .only()
-                        .serve("/jmap")
+                        .serve(JMAPUrls.JMAP)
                             .with(jmapServlet)
-                        .filter("/jmap")
+                        .filter(JMAPUrls.JMAP)
                             .with(new AllowAllCrossOriginRequests(bypass(authenticationFilter).on("OPTIONS").only()))
                             .and(firstUserConnectionFilter)
                             .only()

http://git-wip-us.apache.org/repos/asf/james-project/blob/c20adf87/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
new file mode 100644
index 0000000..719bd49
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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;
+
+public interface JMAPUrls {
+
+    String JMAP = "/jmap";
+    String AUTHENTICATION = "/authentication";
+}


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


[2/4] james-project git commit: JAMES-1742 Return the downloadUrl when authenticated

Posted by ad...@apache.org.
JAMES-1742 Return the downloadUrl when authenticated


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

Branch: refs/heads/master
Commit: 38489542461172784fa54bc583d598e774ef428a
Parents: c20adf8
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed May 25 16:25:18 2016 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Jun 6 13:05:37 2016 +0200

----------------------------------------------------------------------
 .../test/java/org/apache/james/jmap/JMAPAuthenticationTest.java  | 4 ++--
 .../main/java/org/apache/james/jmap/AuthenticationServlet.java   | 4 ++--
 .../jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java       | 1 +
 3 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/38489542/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JMAPAuthenticationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JMAPAuthenticationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JMAPAuthenticationTest.java
index 4671d6c..c6d71b3 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JMAPAuthenticationTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JMAPAuthenticationTest.java
@@ -284,7 +284,7 @@ public abstract class JMAPAuthenticationTest {
             .body("api", equalTo("/jmap"))
             .body("eventSource", both(isA(String.class)).and(notNullValue()))
             .body("upload", both(isA(String.class)).and(notNullValue()))
-            .body("download", both(isA(String.class)).and(notNullValue()));
+            .body("download", equalTo("/download"));
     }
     
     @Test
@@ -320,7 +320,7 @@ public abstract class JMAPAuthenticationTest {
             .body("api", equalTo("/jmap"))
             .body("eventSource", both(isA(String.class)).and(notNullValue()))
             .body("upload", both(isA(String.class)).and(notNullValue()))
-            .body("download", both(isA(String.class)).and(notNullValue()));
+            .body("download", equalTo("/download"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/38489542/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
index ed4b11e..a8ce762 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/AuthenticationServlet.java
@@ -182,7 +182,7 @@ public class AuthenticationServlet extends HttpServlet {
             .api(JMAPUrls.JMAP)
             .eventSource("/notImplemented")
             .upload("/notImplemented")
-            .download("/notImplemented")
+            .download(JMAPUrls.DOWNLOAD)
             .build();
         mapper.writeValue(resp.getOutputStream(), response);
     }
@@ -195,7 +195,7 @@ public class AuthenticationServlet extends HttpServlet {
             .api(JMAPUrls.JMAP)
             .eventSource("/notImplemented")
             .upload("/notImplemented")
-            .download("/notImplemented")
+            .download(JMAPUrls.DOWNLOAD)
             .build();
         mapper.writeValue(resp.getOutputStream(), response);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/38489542/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
index 719bd49..9d96ccd 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPUrls.java
@@ -23,4 +23,5 @@ public interface JMAPUrls {
 
     String JMAP = "/jmap";
     String AUTHENTICATION = "/authentication";
+    String DOWNLOAD = "/download";
 }


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