Repository: james-project
Updated Branches:
  refs/heads/master 6494482df -> 813af4ae1


JAMES-1690 Provide a utility for sending mails


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

Branch: refs/heads/master
Commit: 813af4ae1645ce1db469da5484b69df9910b7d9e
Parents: 6494482
Author: Antoine Duprat <antdup...@gmail.com>
Authored: Tue Feb 16 11:48:05 2016 +0100
Committer: Antoine Duprat <adup...@linagora.com>
Committed: Wed Feb 24 13:59:02 2016 +0100

----------------------------------------------------------------------
 .../org/apache/james/jmap/JMAPCommonModule.java |   4 +
 server/pom.xml                                  |   7 ++
 server/protocols/jmap/pom.xml                   |   6 ++
 .../org/apache/james/jmap/utils/MailSpool.java  |  43 ++++++++
 .../apache/james/jmap/utils/MailSpoolTest.java  | 106 +++++++++++++++++++
 5 files changed, 166 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/813af4ae/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
 
b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
index b0137ad..3d8854a 100644
--- 
a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
+++ 
b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
@@ -30,11 +30,13 @@ import org.apache.james.jmap.crypto.SignatureHandler;
 import org.apache.james.jmap.crypto.SignedContinuationTokenManager;
 import org.apache.james.jmap.memory.access.MemoryAccessTokenRepository;
 import org.apache.james.jmap.utils.DefaultZonedDateTimeProvider;
+import org.apache.james.jmap.utils.MailSpool;
 import org.apache.james.jmap.utils.ZonedDateTimeProvider;
 
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
+import com.google.inject.Singleton;
 import com.google.inject.name.Names;
 
 public class JMAPCommonModule extends AbstractModule {
@@ -50,6 +52,8 @@ public class JMAPCommonModule extends AbstractModule {
         
bindConstant().annotatedWith(Names.named(AccessTokenRepository.TOKEN_EXPIRATION_IN_MS)).to(DEFAULT_TOKEN_EXPIRATION_IN_MS);
         
bind(AccessTokenRepository.class).to(MemoryAccessTokenRepository.class);
         bind(AccessTokenManager.class).to(AccessTokenManagerImpl.class);
+
+        bind(MailSpool.class).in(Singleton.class);
     }
 
     @Provides

http://git-wip-us.apache.org/repos/asf/james-project/blob/813af4ae/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 893e249..7be6792 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -349,6 +349,13 @@
                 </exclusions>
             </dependency>
             <dependency>
+                <groupId>org.apache.james</groupId>
+                <artifactId>apache-mailet-base</artifactId>
+                <version>${mailet.version}</version>
+                <type>test-jar</type>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
                 <groupId>org.apache.geronimo.specs</groupId>
                 <artifactId>geronimo-jms_1.1_spec</artifactId>
                 <version>${geronimo-jms-spec.version}</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/813af4ae/server/protocols/jmap/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml
index a1f9f21..13b1f4a 100644
--- a/server/protocols/jmap/pom.xml
+++ b/server/protocols/jmap/pom.xml
@@ -167,6 +167,12 @@
                 </dependency>
                 <dependency>
                     <groupId>org.apache.james</groupId>
+                    <artifactId>apache-mailet-base</artifactId>
+                    <scope>test</scope>
+                    <type>test-jar</type>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.james</groupId>
                     <artifactId>james-server-core</artifactId>
                 </dependency>
                 <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/813af4ae/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java
new file mode 100644
index 0000000..340d188
--- /dev/null
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailSpool.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.utils;
+
+import javax.inject.Inject;
+
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.mailet.Mail;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class MailSpool {
+
+    private final MailQueue queue;
+
+    @Inject
+    @VisibleForTesting MailSpool(MailQueueFactory queueFactory) {
+        queue = queueFactory.getQueue(MailQueueFactory.SPOOL);
+    }
+
+    public void send(Mail mail) throws MailQueueException {
+        queue.enQueue(mail);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/813af4ae/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java
new file mode 100644
index 0000000..359e649
--- /dev/null
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailSpoolTest.java
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.james.queue.api.MailQueue;
+import org.apache.james.queue.api.MailQueue.MailQueueException;
+import org.apache.james.queue.api.MailQueue.MailQueueItem;
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.test.FakeMail;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MailSpoolTest {
+
+    private MailSpool mailSpool;
+    private MailQueue myQueue;
+
+    @Before
+    public void setup() {
+        myQueue = new MyQueue();
+
+        mailSpool = new MailSpool(new MailQueueFactory() {
+
+            @Override
+            public MailQueue getQueue(String name) {
+                return myQueue;
+            }
+        });
+    }
+
+    @Test
+    public void sendShouldEnQueueTheMail() throws Exception {
+        FakeMail mail = new FakeMail();
+
+        mailSpool.send(mail);
+
+        assertThat(myQueue.deQueue())
+            .isNotNull()
+            .extracting(MailQueueItem::getMail)
+            .containsExactly(mail);
+    }
+
+    private static class MyQueue implements MailQueue {
+
+        private ConcurrentLinkedQueue<Mail> queue;
+
+        public MyQueue() {
+            queue = new ConcurrentLinkedQueue<Mail>();
+        }
+
+        @Override
+        public void enQueue(Mail mail) throws MailQueueException {
+            queue.add(mail);
+        }
+
+        @Override
+        public void enQueue(Mail mail, long delay, TimeUnit unit) throws 
MailQueueException {
+        }
+
+        @Override
+        public MailQueueItem deQueue() throws MailQueueException {
+            return new MyMailQueueItem(queue.poll());
+        }
+    }
+
+    private static class MyMailQueueItem implements MailQueueItem {
+
+        private final Mail mail;
+
+        public MyMailQueueItem(Mail mail) {
+            this.mail = mail;
+        }
+
+        @Override
+        public Mail getMail() {
+            return mail;
+        }
+
+        @Override
+        public void done(boolean success) throws MailQueueException {
+        }
+    }
+}


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