Author: norman
Date: Fri Sep 24 17:11:10 2010
New Revision: 1000976

URL: http://svn.apache.org/viewvc?rev=1000976&view=rev
Log:
start to introduce base test classes which implementations can use to test

Added:
    
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/AbstractSubscriptionManagerTest.java
    
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/MockMailboxSession.java
Modified:
    james/imap/trunk/parent/pom.xml

Added: 
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/AbstractSubscriptionManagerTest.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/AbstractSubscriptionManagerTest.java?rev=1000976&view=auto
==============================================================================
--- 
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/AbstractSubscriptionManagerTest.java
 (added)
+++ 
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/AbstractSubscriptionManagerTest.java
 Fri Sep 24 17:11:10 2010
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.mailbox;
+
+import java.util.Iterator;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Abstract base class to test {...@link SubscriptionManager} implementations
+ * 
+ *
+ */
+public abstract class AbstractSubscriptionManagerTest {
+
+    private final static String USER1 = "test";
+    private final static String MAILBOX1 = "test1";
+    private final static String MAILBOX2 = "test2";
+
+    public abstract SubscriptionManager createSubscriptionManager();
+    
+    @Test
+    public void testSubscriptionManager() throws Exception {
+        SubscriptionManager manager = createSubscriptionManager();
+        MailboxSession session = new MockMailboxSession(USER1);
+        manager.startProcessingRequest(session);
+        
+        Assert.assertTrue(manager.subscriptions(session).isEmpty());
+        
+        manager.subscribe(session, MAILBOX1);
+        Assert.assertEquals(MAILBOX1, 
manager.subscriptions(session).iterator().next());
+        Assert.assertEquals(1, manager.subscriptions(session).size());
+        
+        
+        manager.subscribe(session, MAILBOX1);
+        Assert.assertEquals(MAILBOX1, 
manager.subscriptions(session).iterator().next());
+        Assert.assertEquals(1, manager.subscriptions(session).size());
+        
+        manager.subscribe(session, MAILBOX2);
+        Iterator<String> it = manager.subscriptions(session).iterator();
+        
+        Assert.assertEquals(MAILBOX1, it.next());
+        Assert.assertEquals(MAILBOX2, it.next());
+        Assert.assertFalse(it.hasNext());
+        
+        
+        manager.unsubscribe(session, MAILBOX1);
+        Assert.assertEquals(MAILBOX2, 
manager.subscriptions(session).iterator().next());
+        Assert.assertEquals(1, manager.subscriptions(session).size());
+        
+        manager.unsubscribe(session, MAILBOX1);
+        Assert.assertEquals(MAILBOX2, 
manager.subscriptions(session).iterator().next());
+        Assert.assertEquals(1, manager.subscriptions(session).size());
+        
+        
+        manager.endProcessingRequest(session);
+    }
+}

Added: 
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/MockMailboxSession.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/MockMailboxSession.java?rev=1000976&view=auto
==============================================================================
--- 
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/MockMailboxSession.java
 (added)
+++ 
james/imap/trunk/mailbox/src/test/java/org/apache/james/mailbox/MockMailboxSession.java
 Fri Sep 24 17:11:10 2010
@@ -0,0 +1,95 @@
+/****************************************************************
+ * 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.mailbox;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.SimpleLog;
+
+public class MockMailboxSession implements MailboxSession{
+
+    private User user;
+    private boolean close;
+    private Map<Object, Object> attrs = new HashMap<Object, Object>();
+    private SimpleLog log = new SimpleLog("MockLog");
+    private final static Random RANDOM = new Random();
+
+    private long sessionId = RANDOM.nextLong();
+    
+    public MockMailboxSession(final String username) {
+        this.user = new User() {
+            
+            public String getUserName() {
+                return username;
+            }
+            
+            public String getPassword() {
+                return null;
+            }
+            
+            public List<Locale> getLocalePreferences() {
+                return new ArrayList<Locale>();
+            }
+        };
+    }
+    
+    public void close() {
+        this.close = true;
+    }
+
+    public Map<Object, Object> getAttributes() {
+        return attrs;
+    }
+
+    public Log getLog() {
+        return log;
+    }
+
+    public String getOtherUsersSpace() {
+        return null;
+    }
+
+    public String getPersonalSpace() {
+        return "";
+    }
+
+    public long getSessionId() {
+        return sessionId;
+    }
+
+    public Collection<String> getSharedSpaces() {
+        return new ArrayList<String>();
+    }
+
+    public User getUser() {
+        return user;
+    }
+
+    public boolean isOpen() {
+        return close == false;
+    }
+
+}

Modified: james/imap/trunk/parent/pom.xml
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/parent/pom.xml?rev=1000976&r1=1000975&r2=1000976&view=diff
==============================================================================
--- james/imap/trunk/parent/pom.xml (original)
+++ james/imap/trunk/parent/pom.xml Fri Sep 24 17:11:10 2010
@@ -195,6 +195,13 @@
       </dependency>
       <dependency>
         <groupId>org.apache.james</groupId>
+        <artifactId>apache-james-mailbox-api</artifactId>
+        <version>${project.version}</version>
+        <type>test-jar</type>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.james</groupId>
         <artifactId>apache-james-mailbox-store</artifactId>
         <version>${project.version}</version>
         <type>test-jar</type>



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

Reply via email to