james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [6/7] james-project git commit: JAMES-1925 Rely on event to ensure addition to Outbox when sending a message
Date Thu, 09 Feb 2017 13:01:21 GMT
JAMES-1925 Rely on event to ensure addition to Outbox when sending a message

Otherwise test are failing because too fast


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

Branch: refs/heads/master
Commit: 0e104c2c509dfe62aec30876adca6b40398ffa13
Parents: c10cfae
Author: Benoit Tellier <btellier@linagora.com>
Authored: Wed Feb 8 10:02:27 2017 +0700
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Thu Feb 9 09:44:51 2017 +0100

----------------------------------------------------------------------
 .../org/apache/james/utils/JmapGuiceProbe.java  |  5 ++
 .../integration/SetMessagesMethodTest.java      | 49 ++++++++++++++------
 2 files changed, 41 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0e104c2c/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
index 05e1646..627d1c6 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/JmapGuiceProbe.java
@@ -28,6 +28,7 @@ import org.apache.james.jmap.api.vacation.AccountId;
 import org.apache.james.jmap.api.vacation.Vacation;
 import org.apache.james.jmap.api.vacation.VacationPatch;
 import org.apache.james.jmap.api.vacation.VacationRepository;
+import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
@@ -58,6 +59,10 @@ public class JmapGuiceProbe implements GuiceProbe {
         return jmapServer.getPort();
     }
 
+    public void addMailboxListener(MailboxListener listener) throws MailboxException {
+        mailboxManager.addGlobalListener(listener, mailboxManager.createSystemSession("jmap",
LOGGER));
+    }
+
     public void modifyVacation(AccountId accountId, VacationPatch vacationPatch) {
         vacationRepository.modifyVacation(accountId, vacationPatch).join();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0e104c2c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 1fd27ad..7b34308 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -57,12 +57,14 @@ import org.apache.james.jmap.DefaultMailboxes;
 import org.apache.james.jmap.HttpJmapAuthentication;
 import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.jmap.model.mailbox.Role;
+import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.Attachment;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.util.ZeroedInputStream;
 import org.hamcrest.Matcher;
@@ -74,6 +76,7 @@ import org.junit.Test;
 
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 import com.google.common.io.ByteStreams;
 import com.jayway.awaitility.Awaitility;
 import com.jayway.awaitility.Duration;
@@ -856,6 +859,7 @@ public abstract class SetMessagesMethodTest {
         String fromAddress = USERNAME;
         String messageSubject = "Thank you for joining example.com!";
         String outboxId = getOutboxId(accessToken);
+
         String requestBody = "[" +
             "  [" +
             "    \"setMessages\","+
@@ -872,6 +876,24 @@ public abstract class SetMessagesMethodTest {
             "  ]" +
             "]";
 
+        List<MailboxListener.Event> events = Lists.newArrayList();
+        jmapServer.getJmapProbe().addMailboxListener(new MailboxListener() {
+            @Override
+            public ListenerType getType() {
+                return ListenerType.ONCE;
+            }
+
+            @Override
+            public ExecutionMode getExecutionMode() {
+                return ExecutionMode.SYNCHRONOUS;
+            }
+
+            @Override
+            public void event(Event event) {
+                events.add(event);
+            }
+        });
+
         String messageId = with()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
@@ -882,19 +904,20 @@ public abstract class SetMessagesMethodTest {
             .body()
             .<String>path(ARGUMENTS + ".created."+ messageCreationId +".id");
 
-        // Then
-        given()
-            .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]")
-        .when()
-            .post("/jmap")
-        .then()
-            .log().ifValidationFails()
-            .body(NAME, equalTo("messages"))
-            .body(ARGUMENTS + ".list", hasSize(1))
-            .body(ARGUMENTS + ".list[0].subject", equalTo(messageSubject))
-            .body(ARGUMENTS + ".list[0].mailboxIds", contains(outboxId))
-            ;
+
+
+        calmlyAwait.atMost(5, TimeUnit.SECONDS).until(() -> events.stream()
+            .anyMatch(event -> isAddedToOutboxEvent(messageId, event)));
+    }
+
+    private boolean isAddedToOutboxEvent(String messageId, MailboxListener.Event event) {
+        if (!(event instanceof EventFactory.AddedImpl)) {
+            return false;
+        }
+        EventFactory.AddedImpl added = (EventFactory.AddedImpl) event;
+        return added.getMailboxPath().equals(new MailboxPath(MailboxConstants.USER_NAMESPACE,
USERNAME, DefaultMailboxes.OUTBOX))
+            && added.getUids().size() == 1
+            && added.getMetaData(added.getUids().get(0)).getMessageId().serialize().equals(messageId);
     }
 
     @Test


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