You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2009/06/03 13:18:47 UTC

svn commit: r781341 - in /james/imap/trunk: build-tools/ deployment/ deployment/src/test/java/org/apache/james/imap/functional/inmemory/ jpa/src/main/java/org/apache/james/imap/jpa/ memory/src/main/java/org/apache/james/imap/inmemory/ parent/ store/src...

Author: rdonkin
Date: Wed Jun  3 11:18:46 2009
New Revision: 781341

URL: http://svn.apache.org/viewvc?rev=781341&view=rev
Log:
IMAP-95 Set up basic integration testing machinary. https://issues.apache.org/jira/browse/IMAP-95

Added:
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/AuthenticatedStateTest.java   (with props)
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java   (with props)
Modified:
    james/imap/trunk/build-tools/common-build.xml
    james/imap/trunk/deployment/pom.xml
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailbox.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
    james/imap/trunk/parent/pom.xml
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java

Modified: james/imap/trunk/build-tools/common-build.xml
URL: http://svn.apache.org/viewvc/james/imap/trunk/build-tools/common-build.xml?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/build-tools/common-build.xml (original)
+++ james/imap/trunk/build-tools/common-build.xml Wed Jun  3 11:18:46 2009
@@ -268,6 +268,7 @@
                 	<include name="${jars-prefix}seda-${version}.jar" />
                 	<include name="${jars-prefix}torque-${version}.jar" />
                 	<include name="${jars-prefix}jpa-${version}.jar" />
+                	<include name="${jars-prefix}memory-${version}.jar" />
                 </fileset>
             </path> 
             

Modified: james/imap/trunk/deployment/pom.xml
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/pom.xml?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/deployment/pom.xml (original)
+++ james/imap/trunk/deployment/pom.xml Wed Jun  3 11:18:46 2009
@@ -68,6 +68,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-memory</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-seda</artifactId>
     </dependency>
 	<dependency>

Added: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/AuthenticatedStateTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/AuthenticatedStateTest.java?rev=781341&view=auto
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/AuthenticatedStateTest.java (added)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/AuthenticatedStateTest.java Wed Jun  3 11:18:46 2009
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.imap.functional.inmemory;
+
+import org.apache.james.imap.functional.suite.AuthenticatedState;
+
+public class AuthenticatedStateTest extends
+        AuthenticatedState {
+    public AuthenticatedStateTest() throws Exception {
+        super(InMemoryHostSystem.build());
+    }
+}

Propchange: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/AuthenticatedStateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java?rev=781341&view=auto
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java (added)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java Wed Jun  3 11:18:46 2009
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.imap.functional.inmemory;
+
+import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
+import org.apache.james.imap.functional.ImapHostSystem;
+import org.apache.james.imap.functional.jpa.user.InMemoryUserManager;
+import org.apache.james.imap.inmemory.InMemoryMailboxManager;
+import org.apache.james.imap.inmemory.InMemorySubscriptionManager;
+import org.apache.james.imap.main.DefaultImapDecoderFactory;
+import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.imap.store.StoreMailboxManager;
+import org.apache.james.test.functional.HostSystem;
+
+public class InMemoryHostSystem extends ImapHostSystem {
+
+    private final StoreMailboxManager mailboxManager;
+    private final InMemoryUserManager userManager; 
+    
+    static HostSystem build() throws Exception {        
+        InMemoryHostSystem host =  new InMemoryHostSystem();
+        return host;
+    }
+    
+    private InMemoryHostSystem() {
+        userManager = new InMemoryUserManager();
+        mailboxManager = new InMemoryMailboxManager(userManager, new InMemorySubscriptionManager());
+        final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory();
+        defaultImapProcessorFactory.configure(mailboxManager);
+        configure(new DefaultImapDecoderFactory().buildImapDecoder(),
+                new DefaultImapEncoderFactory().buildImapEncoder(),
+                defaultImapProcessorFactory.buildImapProcessor());
+    }
+    
+    @Override
+    public boolean addUser(String user, String password) throws Exception {
+        userManager.addUser(user, password);
+        return true;
+    }
+
+    @Override
+    protected void resetData() throws Exception {
+        mailboxManager.deleteEverything();
+    }
+
+}

Propchange: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java Wed Jun  3 11:18:46 2009
@@ -55,7 +55,7 @@
     
     @Override
     protected void doCreate(String namespaceName) throws MailboxException {
-        Mailbox mailbox = new org.apache.james.imap.jpa.mail.model.JPAMailbox(namespaceName, Math.abs(random.nextInt()));
+        Mailbox mailbox = new org.apache.james.imap.jpa.mail.model.JPAMailbox(namespaceName, randomUidValidity());
         final MailboxMapper mapper = createMailboxMapper();
         mapper.begin();
         mapper.save(mailbox);

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailbox.java?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailbox.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailbox.java Wed Jun  3 11:18:46 2009
@@ -35,7 +35,7 @@
     
     public InMemoryMailbox(final long id, final String name, final long uidValidity) {
         super();
-        this.nextUid = new AtomicLong(1);
+        this.nextUid = new AtomicLong(0);
         this.id = id;
         this.name = name;
         this.uidValidity = uidValidity;

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java Wed Jun  3 11:18:46 2009
@@ -56,7 +56,7 @@
 
     @Override
     protected void doCreate(String namespaceName) throws StorageException {
-        InMemoryMailbox mailbox = new InMemoryMailbox(random.nextLong(), namespaceName, random.nextInt());
+        InMemoryMailbox mailbox = new InMemoryMailbox(randomId(), namespaceName, randomUidValidity());
         save(mailbox);
     }
 

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java Wed Jun  3 11:18:46 2009
@@ -20,7 +20,10 @@
 package org.apache.james.imap.inmemory;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -40,6 +43,14 @@
 
 public class InMemoryStoreMailbox extends StoreMailbox implements MessageMapper {
     
+    private final class MailboxMembershipComparator implements Comparator<MailboxMembership> {
+        public int compare(MailboxMembership o1, MailboxMembership o2) {
+            final long uid = o1.getUid();
+            final long otherUid = o2.getUid();
+            return uid < otherUid ? -1 : uid == otherUid ? 0 : 1;
+        }
+    }
+
     private static final int INITIAL_SIZE = 256;
     private Map<Long, MailboxMembership> membershipByUid;
     private InMemoryMailbox mailbox;
@@ -106,13 +117,53 @@
         membershipByUid.remove(message.getUid());
     }
 
+    @SuppressWarnings("unchecked")
     public List<MailboxMembership> findInMailbox(MessageRange set) throws StorageException {
-        return null;
+        final List<MailboxMembership> results;
+        final MessageRange.Type type = set.getType();
+        switch (type) {
+            case ALL:
+                results = new ArrayList<MailboxMembership>(membershipByUid.values());
+                break;
+            case FROM:
+                results = new ArrayList<MailboxMembership>(membershipByUid.values());
+                for (final Iterator<MailboxMembership> it=results.iterator();it.hasNext();) {
+                   if (it.next().getUid()< set.getUidFrom()) {
+                       it.remove(); 
+                   }
+                }
+                break;
+            case RANGE:
+                results = new ArrayList<MailboxMembership>(membershipByUid.values());
+                for (final Iterator<MailboxMembership> it=results.iterator();it.hasNext();) {
+                   final long uid = it.next().getUid();
+                if (uid<set.getUidFrom() || uid>set.getUidTo()) {
+                       it.remove(); 
+                   }
+                }
+                break;
+            case ONE:
+                results  = new ArrayList<MailboxMembership>(1);
+                final MailboxMembership member = membershipByUid.get(set.getUidFrom());
+                if (member != null) {
+                    results.add(member);
+                }
+                break;
+            default:
+                results = Collections.EMPTY_LIST;
+                break;
+        }
+        return results;
     }
 
     public List<MailboxMembership> findMarkedForDeletionInMailbox(MessageRange set) throws StorageException {
-        // TODO Auto-generated method stub
-        return null;
+        final List<MailboxMembership> results = findInMailbox(set);
+        for(final Iterator<MailboxMembership> it=results.iterator();it.hasNext();) {
+            if (!it.next().isDeleted()) {
+                it.remove();
+            }
+        }
+        return results;
     }
 
     public List<MailboxMembership> findRecentMessagesInMailbox() throws StorageException {
@@ -128,22 +179,19 @@
     public List<MailboxMembership> findUnseenMessagesInMailboxOrderByUid() throws StorageException {
         final List<MailboxMembership> results = new ArrayList<MailboxMembership>();
         for(MailboxMembership member:membershipByUid.values()) {
-            if (member.isRecent()) {
+            if (!member.isSeen()) {
                 results.add(member);
             }
         }
+        Collections.sort(results, new MailboxMembershipComparator());
         return results;
     }
 
     public void save(MailboxMembership message) throws StorageException {
-        // TODO Auto-generated method stub
-        
+        membershipByUid.put(message.getUid(), message);
     }
 
     public List<MailboxMembership> searchMailbox(SearchQuery query) throws StorageException {
-        // TODO Auto-generated method stub
-        return null;
+        return new ArrayList<MailboxMembership>(membershipByUid.values());
     }
-
-
 }

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java Wed Jun  3 11:18:46 2009
@@ -230,4 +230,30 @@
         final long otherUid = getUid();
         return uid < otherUid ? -1 : uid == otherUid ? 0 : 1;
     }
+
+    /**
+     * Representation suitable for logging and debugging.
+     *
+     * @return a <code>String</code> representation 
+     * of this object.
+     */
+    public String toString()
+    {
+        return super.toString() + "["
+            + "uid = " + this.uid + " "
+            + "mailboxId = " + this.mailboxId + " "
+            + "size = " + this.size + " "
+            + "answered = " + this.answered + " "
+            + "deleted = " + this.deleted + " "
+            + "draft = " + this.draft + " "
+            + "flagged = " + this.flagged + " "
+            + "recent = " + this.recent + " "
+            + "seen = " + this.seen + " "
+            + "internalDate = " + this.internalDate + " "
+            + "subType = " + this.subType + " "
+            + "mediaType = " + this.mediaType + " "
+            + " ]";
+    }
+    
+    
 }

Modified: james/imap/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/james/imap/trunk/parent/pom.xml?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/parent/pom.xml (original)
+++ james/imap/trunk/parent/pom.xml Wed Jun  3 11:18:46 2009
@@ -314,6 +314,11 @@
       <groupId>org.apache.james</groupId>
       <artifactId>apache-james-imap-jpa</artifactId>
       <version>0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-memory</artifactId>
+      <version>0.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java?rev=781341&r1=781340&r2=781341&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java Wed Jun  3 11:18:46 2009
@@ -53,7 +53,7 @@
     
     public static final char SQL_WILDCARD_CHAR = '%';
 
-    protected final static Random random = new Random();
+    private final static Random random = new Random();
 
     private final Map<String, StoreMailbox> mailboxes;
 
@@ -204,6 +204,10 @@
         }
     }
 
+    protected int randomUidValidity() {
+        return Math.abs(random.nextInt());
+    }
+    
     /**
      * Changes the name of the mailbox instance in the cache.
      * @param from not null
@@ -307,7 +311,12 @@
 
     @SuppressWarnings("unchecked")
     private SimpleMailboxSession createSession(String userName, Log log) {
-        return new SimpleMailboxSession(random.nextLong(), userName, log, delimiter, Collections.EMPTY_LIST);
+        return new SimpleMailboxSession(randomId(), userName, log, delimiter, Collections.EMPTY_LIST);
+    }
+
+
+    protected long randomId() {
+        return random.nextLong();
     }
 
     public String resolve(final String userName, String mailboxPath) {



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