JAMES-2556 Add tests for multi-path repository reprocessing

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

Branch: refs/heads/master
Commit: 6cf97c9d5bbe32c77e4923767f9cc547a6c9e784
Parents: 9d1d697
Author: Benoit Tellier <btell...@linagora.com>
Authored: Wed Oct 10 10:08:38 2018 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Wed Oct 10 15:46:19 2018 +0700

----------------------------------------------------------------------
 .../routes/MailRepositoriesRoutesTest.java      | 120 +++++++++++++++++++
 .../src/test/resources/mailrepositorystore.xml  |   5 +
 2 files changed, 125 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6cf97c9d/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
 
b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
index 4ea84f7..7294348 100644
--- 
a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
+++ 
b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -83,6 +83,7 @@ import org.apache.mailet.base.test.FakeMail;
 import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.collect.Sets;
@@ -95,6 +96,7 @@ import io.restassured.parsing.Parser;
 public class MailRepositoriesRoutesTest {
 
     private static final MailRepositoryUrl URL_MY_REPO = 
MailRepositoryUrl.from("memory://myRepo");
+    private static final MailRepositoryUrl URL_MY_REPO_OTHER = 
MailRepositoryUrl.from("other://myRepo");
     private static final MailRepositoryPath PATH_MY_REPO = 
MailRepositoryPath.from("myRepo");
     private static final String PATH_ESCAPED_MY_REPO = "myRepo";
     private static final String MY_REPO_MAILS = "myRepo/mails";
@@ -1045,6 +1047,36 @@ public class MailRepositoriesRoutesTest {
     }
 
     @Test
+    public void 
reprocessingAllTaskShouldNotFailWhenSeveralRepositoriesWithSamePath() throws 
Exception {
+        MailRepository mailRepository = 
mailRepositoryStore.create(URL_MY_REPO);
+        mailRepositoryStore.create(URL_MY_REPO_OTHER);
+        String name1 = "name1";
+        String name2 = "name2";
+        mailRepository.store(FakeMail.builder()
+            .name(name1)
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name(name2)
+            .build());
+
+        String transport = "transport";
+        String taskId = with()
+            .param("action", "reprocess")
+            .param("queue", CUSTOM_QUEUE)
+            .param("processor", transport)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
+            .jsonPath()
+            .get("taskId");
+
+        given()
+            .basePath(TasksRoutes.BASE)
+            .when()
+            .get(taskId + "/await")
+            .then()
+            .body("status", is("completed"));
+    }
+
+    @Test
     public void reprocessingAllTaskShouldClearMailRepository() throws 
Exception {
         MailRepository mailRepository = 
mailRepositoryStore.create(URL_MY_REPO);
         String name1 = "name1";
@@ -1073,6 +1105,36 @@ public class MailRepositoriesRoutesTest {
     }
 
     @Test
+    public void 
reprocessingAllTaskShouldClearBothMailRepositoriesWhenSamePath() throws 
Exception {
+        MailRepository mailRepository1 = 
mailRepositoryStore.create(URL_MY_REPO);
+        MailRepository mailRepository2 = 
mailRepositoryStore.create(URL_MY_REPO_OTHER);
+        String name1 = "name1";
+        String name2 = "name2";
+        mailRepository1.store(FakeMail.builder()
+            .name(name1)
+            .build());
+        mailRepository2.store(FakeMail.builder()
+            .name(name2)
+            .build());
+
+        String transport = "transport";
+        String taskId = with()
+            .param("action", "reprocess")
+            .param("queue", CUSTOM_QUEUE)
+            .param("processor", transport)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
+            .jsonPath()
+            .get("taskId");
+
+        with()
+            .basePath(TasksRoutes.BASE)
+            .get(taskId + "/await");
+
+        assertThat(mailRepository1.list()).isEmpty();
+        assertThat(mailRepository2.list()).isEmpty();
+    }
+
+    @Test
     public void reprocessingAllTaskShouldEnqueueMailsOnDefaultQueue() throws 
Exception {
         MailRepository mailRepository = 
mailRepositoryStore.create(URL_MY_REPO);
         mailRepository.store(FakeMail.builder()
@@ -1099,6 +1161,33 @@ public class MailRepositoriesRoutesTest {
     }
 
     @Test
+    public void 
reprocessingAllTaskShouldEnqueueMailsOfBothRepositoriesOnDefaultQueueWhenSamePath()
 throws Exception {
+        MailRepository mailRepository1 = 
mailRepositoryStore.create(URL_MY_REPO);
+        MailRepository mailRepository2 = 
mailRepositoryStore.create(URL_MY_REPO_OTHER);
+        mailRepository1.store(FakeMail.builder()
+            .name(NAME_1)
+            .build());
+        mailRepository2.store(FakeMail.builder()
+            .name(NAME_2)
+            .build());
+
+        String taskId = with()
+            .param("action", "reprocess")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
+            .jsonPath()
+            .get("taskId");
+
+        with()
+            .basePath(TasksRoutes.BASE)
+            .get(taskId + "/await");
+
+        assertThat(spoolQueue.browse())
+            .extracting(ManageableMailQueue.MailQueueItemView::getMail)
+            .extracting(Mail::getName)
+            .containsOnly(NAME_1, NAME_2);
+    }
+
+    @Test
     public void 
reprocessingAllTaskShouldPreserveStateWhenProcessorIsNotSpecified() throws 
Exception {
         MailRepository mailRepository = 
mailRepositoryStore.create(URL_MY_REPO);
         String state1 = "state1";
@@ -1311,6 +1400,37 @@ public class MailRepositoriesRoutesTest {
             .body("completedDate", is(notNullValue()));
     }
 
+    @Ignore
+    @Test
+    public void 
reprocessingOneTaskShouldNotFailWhenSeveralRepositoryWithSamePath() throws 
Exception {
+        MailRepository mailRepository = 
mailRepositoryStore.create(URL_MY_REPO);
+        mailRepositoryStore.create(URL_MY_REPO_OTHER);
+        String name1 = "name1";
+        String name2 = "name2";
+        mailRepository.store(FakeMail.builder()
+            .name(name1)
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name(name2)
+            .build());
+
+        String transport = "transport";
+        String taskId = with()
+            .param("action", "reprocess")
+            .param("queue", CUSTOM_QUEUE)
+            .param("processor", transport)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .jsonPath()
+            .get("taskId");
+
+        given()
+            .basePath(TasksRoutes.BASE)
+        .when()
+            .get(taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+    }
+
     @Test
     public void reprocessingOneTaskShouldRemoveMailFromRepository() throws 
Exception {
         MailRepository mailRepository = 
mailRepositoryStore.create(URL_MY_REPO);

http://git-wip-us.apache.org/repos/asf/james-project/blob/6cf97c9d/server/protocols/webadmin/webadmin-mailrepository/src/test/resources/mailrepositorystore.xml
----------------------------------------------------------------------
diff --git 
a/server/protocols/webadmin/webadmin-mailrepository/src/test/resources/mailrepositorystore.xml
 
b/server/protocols/webadmin/webadmin-mailrepository/src/test/resources/mailrepositorystore.xml
index ed3e003..4cf1428 100644
--- 
a/server/protocols/webadmin/webadmin-mailrepository/src/test/resources/mailrepositorystore.xml
+++ 
b/server/protocols/webadmin/webadmin-mailrepository/src/test/resources/mailrepositorystore.xml
@@ -26,5 +26,10 @@
                 <protocol>memory</protocol>
             </protocols>
         </mailrepository>
+        <mailrepository 
class="org.apache.james.mailrepository.memory.MemoryMailRepository">
+            <protocols>
+                <protocol>other</protocol>
+            </protocols>
+        </mailrepository>
     </mailrepositories>
 </mailrepositorystore>


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

Reply via email to