Repository: james-project
Updated Branches:
  refs/heads/master 872d85b57 -> 55018ee80


JAMES-1708 Use MOVE Capability in JMAP


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

Branch: refs/heads/master
Commit: 55018ee80fd73b4006eea77ed5755d23d62e8a6c
Parents: 872d85b
Author: Raphael Ouazana <[email protected]>
Authored: Fri Mar 11 15:33:14 2016 +0100
Committer: Matthieu Baechler <[email protected]>
Committed: Mon Mar 21 21:42:22 2016 +0100

----------------------------------------------------------------------
 server/container/cassandra-guice/pom.xml        |  5 +
 .../java/org/apache/james/jmap/JMAPModule.java  | 23 ++++-
 .../james/JamesCapabilitiesServerTest.java      | 99 ++++++++++++++++++++
 .../james/jmap/send/PostDequeueDecorator.java   |  5 +-
 4 files changed, 127 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/55018ee8/server/container/cassandra-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/cassandra-guice/pom.xml 
b/server/container/cassandra-guice/pom.xml
index 09b76d4..f35d980 100644
--- a/server/container/cassandra-guice/pom.xml
+++ b/server/container/cassandra-guice/pom.xml
@@ -427,6 +427,11 @@
                     <scope>test</scope>
                 </dependency>
                 <dependency>
+                    <groupId>org.mockito</groupId>
+                    <artifactId>mockito-core</artifactId>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
                     <groupId>org.elasticsearch</groupId>
                     <artifactId>elasticsearch</artifactId>
                     <version>1.5.2</version>

http://git-wip-us.apache.org/repos/asf/james-project/blob/55018ee8/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
 
b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
index c25ffa9..4a61f45 100644
--- 
a/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ 
b/server/container/cassandra-guice/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -28,10 +28,12 @@ import 
org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.io.FileUtils;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.jmap.methods.RequestHandler;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.utils.ConfigurationPerformer;
 import org.apache.james.utils.ConfigurationProvider;
 
 import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
 import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
 import com.google.inject.Provides;
@@ -46,7 +48,9 @@ public class JMAPModule extends AbstractModule {
         install(new JMAPCommonModule());
         install(new MethodsModule());
         bind(RequestHandler.class).in(Singleton.class);
-        Multibinder.newSetBinder(binder(), 
ConfigurationPerformer.class).addBinding().to(MailetConfigurationPrecondition.class);
+        Multibinder<ConfigurationPerformer> preconditions = 
Multibinder.newSetBinder(binder(), ConfigurationPerformer.class);
+        preconditions.addBinding().to(MailetConfigurationPrecondition.class);
+        preconditions.addBinding().to(MoveCapabilityPrecondition.class);
     }
 
     @Provides
@@ -96,4 +100,21 @@ public class JMAPModule extends AbstractModule {
             }
         }
     }
+
+    @Singleton
+    public static class MoveCapabilityPrecondition implements 
ConfigurationPerformer {
+
+        private final MailboxManager mailboxManager;
+
+        @Inject
+        public MoveCapabilityPrecondition(MailboxManager mailboxManager) {
+            this.mailboxManager = mailboxManager;
+        }
+
+        @Override
+        public void initModule() throws Exception {
+            
Preconditions.checkArgument(mailboxManager.getSupportedCapabilities().contains(MailboxManager.Capabilities.Move),
+                    "MOVE support in MailboxManager is required by JMAP 
Module");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/55018ee8/server/container/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git 
a/server/container/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
 
b/server/container/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
new file mode 100644
index 0000000..6652b97
--- /dev/null
+++ 
b/server/container/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -0,0 +1,99 @@
+/****************************************************************
+ * 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;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.backends.cassandra.CassandraCluster;
+import org.apache.james.backends.cassandra.components.CassandraModule;
+import org.apache.james.jmap.methods.GetMessageListMethod;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
+import org.apache.james.modules.TestElasticSearchModule;
+import org.apache.james.modules.TestFilesystemModule;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TemporaryFolder;
+
+import com.google.common.collect.ImmutableList;
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.google.inject.util.Modules;
+
+public class JamesCapabilitiesServerTest {
+
+    private CassandraJamesServer server;
+    private TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private EmbeddedElasticSearch embeddedElasticSearch = new 
EmbeddedElasticSearch();
+
+    @Rule
+    public RuleChain chain = 
RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
+
+    private Module createModule(MailboxManager mailboxManager) {
+        return Modules.override(CassandraJamesServerMain.defaultModule)
+                .with(new TestElasticSearchModule(embeddedElasticSearch),
+                        new TestFilesystemModule(temporaryFolder),
+                        new 
TestJMAPServerModule(GetMessageListMethod.DEFAULT_MAXIMUM_LIMIT),
+                        new AbstractModule() {
+                    
+                    @Override
+                    protected void configure() {
+                        bind(MailboxManager.class).toInstance(mailboxManager);
+                    }
+                    
+                    @Provides
+                    @Singleton
+                    com.datastax.driver.core.Session 
provideSession(CassandraModule cassandraModule) {
+                        CassandraCluster cassandra = 
CassandraCluster.create(cassandraModule);
+                        return cassandra.getConf();
+                    }
+
+                });
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void startShouldFailWhenNoMoveCapability() throws Exception {
+        MailboxManager mailboxManager = mock(MailboxManager.class);
+        when(mailboxManager.getSupportedCapabilities())
+            .thenReturn(ImmutableList.of(MailboxManager.Capabilities.Basic));
+        server = new CassandraJamesServer(createModule(mailboxManager));
+        
+        server.start();
+        
+        // In case of non-failure
+        server.stop();
+    }
+
+    @Test
+    public void startShouldSucceedWhenMoveCapability() throws Exception {
+        MailboxManager mailboxManager = mock(MailboxManager.class);
+        when(mailboxManager.getSupportedCapabilities())
+            .thenReturn(ImmutableList.of(MailboxManager.Capabilities.Move));
+        server = new CassandraJamesServer(createModule(mailboxManager));
+        
+        server.start();
+        
+        server.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/55018ee8/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
index 6722ef7..38e49f0 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
@@ -127,10 +127,7 @@ public class PostDequeueDecorator<Id extends MailboxId> 
extends MailQueueItemDec
         ensureMailboxPathIsOutbox(outboxMailboxPath);
         MailboxPath sentMailboxPath = getSentMailboxPath(mailboxSession);
         
-        // MOVE is not implemented, so COPY and DELETE
-        mailboxManager.copyMessages(MessageRange.one(mailboxMessage.getUid()), 
outboxMailboxPath, sentMailboxPath, mailboxSession);
-        Mailbox<Id> outboxMailbox = 
mailboxMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(outboxMailboxPath);
-        
messageMapperFactory.getMessageMapper(mailboxSession).delete(outboxMailbox, 
mailboxMessage);
+        mailboxManager.moveMessages(MessageRange.one(mailboxMessage.getUid()), 
outboxMailboxPath, sentMailboxPath, mailboxSession);
     }
 
     private void ensureMailboxPathIsOutbox(MailboxPath outboxMailboxPath) 
throws MailShouldBeInOutboxException {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to