james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [james-project] 10/11: JAMES-2713 Add integration test for Purge API
Date Thu, 18 Apr 2019 07:00:25 GMT
This is an automated email from the ASF dual-hosted git repository.

aduprat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit ae48fba707fd43de180ce57fab4f2735bf723358
Author: datph <dphamhoang@linagora.com>
AuthorDate: Thu Apr 11 18:27:25 2019 +0700

    JAMES-2713 Add integration test for Purge API
---
 .../CassandraDeletedMessageVaultTest.java          |   6 +-
 .../integration/DeletedMessagesVaultTest.java      | 110 ++++++++++++++++++++-
 ...FileMailRepositoryDeletedMessagesVaultTest.java |   6 +-
 .../memory/MemoryDeletedMessagesVaultTest.java     |   6 +-
 .../rabbitmq/RabbitMQDeletedMessagesVaultTest.java |   6 +-
 5 files changed, 122 insertions(+), 12 deletions(-)

diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraDeletedMessageVaultTest.java
b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraDeletedMessageVaultTest.java
index 9cbc0ec..b3c0a99 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraDeletedMessageVaultTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraDeletedMessageVaultTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.cassandra;
 
 import java.io.IOException;
+import java.time.Clock;
 
 import org.apache.james.CassandraJmapTestRule;
 import org.apache.james.DockerCassandraRule;
@@ -43,7 +44,7 @@ public class CassandraDeletedMessageVaultTest extends DeletedMessagesVaultTest
{
     public CassandraJmapTestRule rule = CassandraJmapTestRule.defaultTestRule();
     
     @Override
-    protected GuiceJamesServer createJmapServer(FileSystem fileSystem) throws IOException
{
+    protected GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws
IOException {
         return rule.jmapServer(cassandra.getModule(),
             binder -> binder.bind(PreDeletionHooksConfiguration.class)
                 .toInstance(PreDeletionHooksConfiguration.forHooks(
@@ -51,7 +52,8 @@ public class CassandraDeletedMessageVaultTest extends DeletedMessagesVaultTest
{
             binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION),
             binder -> binder.bind(MailRepositoryDeletedMessageVault.Configuration.class)
                 .toInstance(new MailRepositoryDeletedMessageVault.Configuration(MailRepositoryUrl.from("cassandra://var/deletedMessages/user"))),
-            binder -> binder.bind(FileSystem.class).toInstance(fileSystem));
+            binder -> binder.bind(FileSystem.class).toInstance(fileSystem),
+            binder -> binder.bind(Clock.class).toInstance(clock));
     }
 
     @Override
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
index 8ab9e11..7962379 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
@@ -40,6 +40,9 @@ import static org.hamcrest.Matchers.is;
 
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.time.Clock;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -59,6 +62,7 @@ import org.apache.james.server.core.filesystem.FileSystemImpl;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.IMAPMessageReader;
 import org.apache.james.utils.JmapGuiceProbe;
+import org.apache.james.utils.UpdatableTickingClock;
 import org.apache.james.utils.WebAdminGuiceProbe;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.awaitility.Duration;
@@ -110,6 +114,8 @@ public abstract class DeletedMessagesVaultTest {
         }
     }
 
+    private static final Instant NOW = Instant.now();
+    private static final Instant ONE_DAY_AFTER_ONE_YEAR_EXPIRATION = NOW.plus(366, ChronoUnit.DAYS);
     private static final String FIRST_SUBJECT = "first subject";
     private static final String SECOND_SUBJECT = "second subject";
     private static final String HOMER = "homer@" + DOMAIN;
@@ -130,7 +136,7 @@ public abstract class DeletedMessagesVaultTest {
 
     private MailboxId otherMailboxId;
 
-    protected abstract GuiceJamesServer createJmapServer(FileSystem fileSystem) throws IOException;
+    protected abstract GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock)
throws IOException;
 
     protected abstract void awaitSearchUpToDate();
 
@@ -143,12 +149,14 @@ public abstract class DeletedMessagesVaultTest {
     private AccessToken bartAccessToken;
     private GuiceJamesServer jmapServer;
     private RequestSpecification webAdminApi;
+    private UpdatableTickingClock clock;
     private FileSystem fileSystem;
 
     @Before
     public void setup() throws Throwable {
+        clock = new UpdatableTickingClock(NOW);
         fileSystem = new FileSystemImpl(new JamesServerResourceLoader(tempFolder.getRoot().getPath()));
-        jmapServer = createJmapServer(fileSystem);
+        jmapServer = createJmapServer(fileSystem, clock);
         jmapServer.start();
         MailboxProbe mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
         DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);
@@ -602,6 +610,84 @@ public abstract class DeletedMessagesVaultTest {
         }
     }
 
+    @Test
+    public void vaultPurgeShouldMakeExportProduceEmptyZipWhenAllMessagesAreExpired() throws
Exception {
+        bartSendMessageToHomer();
+        bartSendMessageToHomer();
+        bartSendMessageToHomer();
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 3);
+
+        homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 0);
+
+        clock.setInstant(ONE_DAY_AFTER_ONE_YEAR_EXPIRATION);
+        purgeVault();
+
+        String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART,
bartAccessToken);
+        try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
+            zipAssert.hasNoEntry();
+        }
+    }
+
+    @Test
+    public void vaultPurgeShouldMakeExportProduceAZipWhenOneMessageIsNotExpired() throws
Exception {
+        bartSendMessageToHomer();
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 1);
+
+        homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 0);
+
+        bartSendMessageToHomer();
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 1);
+
+        String messageIdOfNotExpiredMessage = listMessageIdsForAccount(homerAccessToken).get(0);
+
+        clock.setInstant(ONE_DAY_AFTER_ONE_YEAR_EXPIRATION);
+        homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 0);
+
+        purgeVault();
+
+        String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART,
bartAccessToken);
+        try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
+            zipAssert.hasEntriesSize(1)
+                .allSatisfies(entry -> entry.hasName(messageIdOfNotExpiredMessage + ".eml"));
+        }
+    }
+
+    @Test
+    public void vaultPurgeShouldMakeExportProduceZipWhenAllMessagesAreNotExpired() throws
Exception {
+        bartSendMessageToHomer();
+        bartSendMessageToHomer();
+        bartSendMessageToHomer();
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 3);
+
+        homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 0);
+
+        purgeVault();
+
+        String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART,
bartAccessToken);
+        try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
+            zipAssert.hasEntriesSize(3);
+        }
+    }
+
+    @Test
+    public void vaultPurgeShouldNotAppendMessageToTheUserMailbox() {
+        bartSendMessageToHomer();
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 1);
+
+        homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
+        WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size()
== 0);
+
+        clock.setInstant(ONE_DAY_AFTER_ONE_YEAR_EXPIRATION);
+        purgeVault();
+
+        assertThat(listMessageIdsForAccount(homerAccessToken))
+            .hasSize(0);
+    }
+
     private String exportAndGetFileLocationFromLastMail(ExportRequest exportRequest, AccessToken
shareeAccessToken) {
         int currentNumberOfMessages = listMessageIdsForAccount(shareeAccessToken).size();
         exportVaultContent(exportRequest);
@@ -739,14 +825,30 @@ public abstract class DeletedMessagesVaultTest {
     private void exportVaultContent(ExportRequest exportRequest) {
         String taskId =
             webAdminApi.with()
+                .queryParam("action", "export")
+                .queryParam("exportTo", exportRequest.sharee)
                 .body(exportRequest.matchingQuery)
-                .post("/deletedMessages/users/" + exportRequest.userExportFrom + "?action=export&exportTo="
+ exportRequest.sharee)
+                .post("/deletedMessages/users/" + exportRequest.userExportFrom)
             .jsonPath()
                 .get("taskId");
 
-        webAdminApi.given()
+        webAdminApi.with()
                 .get("/tasks/" + taskId + "/await")
             .then()
                 .body("status", is("completed"));
     }
+
+    private void purgeVault() {
+        String taskId =
+            webAdminApi.with()
+                .queryParam("scope", "expired")
+                .delete("/deletedMessages")
+            .jsonPath()
+                .get("taskId");
+
+        webAdminApi.with()
+            .get("/tasks/" + taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+    }
 }
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/FileMailRepositoryDeletedMessagesVaultTest.java
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/FileMailRepositoryDeletedMessagesVaultTest.java
index 4656d9d..92a6abc 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/FileMailRepositoryDeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/FileMailRepositoryDeletedMessagesVaultTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.memory;
 
 import java.io.IOException;
+import java.time.Clock;
 
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.MemoryJmapTestRule;
@@ -44,7 +45,7 @@ public class FileMailRepositoryDeletedMessagesVaultTest extends DeletedMessagesV
     }
 
     @Override
-    protected GuiceJamesServer createJmapServer(FileSystem fileSystem) throws IOException
{
+    protected GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws
IOException {
         return memoryJmap.jmapServer(
             binder -> binder.bind(PreDeletionHooksConfiguration.class)
                 .toInstance(PreDeletionHooksConfiguration.forHooks(
@@ -52,6 +53,7 @@ public class FileMailRepositoryDeletedMessagesVaultTest extends DeletedMessagesV
             binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION),
             binder -> binder.bind(MailRepositoryDeletedMessageVault.Configuration.class)
                 .toInstance(new MailRepositoryDeletedMessageVault.Configuration(MailRepositoryUrl.from("file://var/deletedMessages/user"))),
-            binder -> binder.bind(FileSystem.class).toInstance(fileSystem));
+            binder -> binder.bind(FileSystem.class).toInstance(fileSystem),
+            binder -> binder.bind(Clock.class).toInstance(clock));
     }
 }
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryDeletedMessagesVaultTest.java
b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryDeletedMessagesVaultTest.java
index 62360ad..b74fd4d 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryDeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryDeletedMessagesVaultTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.memory;
 
 import java.io.IOException;
+import java.time.Clock;
 
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.MemoryJmapTestRule;
@@ -38,7 +39,7 @@ public class MemoryDeletedMessagesVaultTest extends DeletedMessagesVaultTest
{
     public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
 
     @Override
-    protected GuiceJamesServer createJmapServer(FileSystem fileSystem) throws IOException
{
+    protected GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws
IOException {
         return memoryJmap.jmapServer(
             binder -> binder.bind(PreDeletionHooksConfiguration.class)
                 .toInstance(PreDeletionHooksConfiguration.forHooks(
@@ -46,7 +47,8 @@ public class MemoryDeletedMessagesVaultTest extends DeletedMessagesVaultTest
{
             binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION),
             binder -> binder.bind(MailRepositoryDeletedMessageVault.Configuration.class)
                 .toInstance(new MailRepositoryDeletedMessageVault.Configuration(MailRepositoryUrl.from("memory://var/deletedMessages/user"))),
-            binder -> binder.bind(FileSystem.class).toInstance(fileSystem));
+            binder -> binder.bind(FileSystem.class).toInstance(fileSystem),
+            binder -> binder.bind(Clock.class).toInstance(clock));
     }
 
     @Override
diff --git a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQDeletedMessagesVaultTest.java
b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQDeletedMessagesVaultTest.java
index 45cc6f3..e171517 100644
--- a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQDeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQDeletedMessagesVaultTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.rabbitmq;
 
 import java.io.IOException;
+import java.time.Clock;
 
 import org.apache.james.CassandraRabbitMQAwsS3JmapTestRule;
 import org.apache.james.DockerCassandraRule;
@@ -43,7 +44,7 @@ public class RabbitMQDeletedMessagesVaultTest extends DeletedMessagesVaultTest
{
     public CassandraRabbitMQAwsS3JmapTestRule rule = CassandraRabbitMQAwsS3JmapTestRule.defaultTestRule();
 
     @Override
-    protected GuiceJamesServer createJmapServer(FileSystem fileSystem) throws IOException
{
+    protected GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws
IOException {
         return rule.jmapServer(cassandra.getModule(),
             binder -> binder.bind(PreDeletionHooksConfiguration.class)
                 .toInstance(PreDeletionHooksConfiguration.forHooks(
@@ -51,7 +52,8 @@ public class RabbitMQDeletedMessagesVaultTest extends DeletedMessagesVaultTest
{
             binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION),
             binder -> binder.bind(MailRepositoryDeletedMessageVault.Configuration.class)
                 .toInstance(new MailRepositoryDeletedMessageVault.Configuration(MailRepositoryUrl.from("cassandra://var/deletedMessages/user"))),
-            binder -> binder.bind(FileSystem.class).toInstance(fileSystem));
+            binder -> binder.bind(FileSystem.class).toInstance(fileSystem),
+            binder -> binder.bind(Clock.class).toInstance(clock));
     }
 
     @Override


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


Mime
View raw message