james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [09/11] james-project git commit: JAMES-1746 MailboxManager tests should be done with junit-contracts
Date Wed, 08 Jun 2016 11:36:07 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTests.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTests.java
b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTests.java
new file mode 100644
index 0000000..9a6a4a8
--- /dev/null
+++ b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTests.java
@@ -0,0 +1,157 @@
+/****************************************************************
+ * 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.maildir;
+
+import java.io.IOException;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxManagerTest;
+import org.apache.james.mailbox.acl.GroupMembershipResolver;
+import org.apache.james.mailbox.acl.MailboxACLResolver;
+import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
+import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+import org.xenei.junit.contract.IProducer;
+
+import com.google.common.base.Throwables;
+
+@SuiteClasses({
+    MaildirMailboxManagerTests.DomainUser.class,
+    MaildirMailboxManagerTests.User.class,
+    MaildirMailboxManagerTests.FullUser.class})
+
+public class MaildirMailboxManagerTests {
+
+    public static abstract class MaildirMailboxManagerTest extends MailboxManagerTest {
+        protected StoreMailboxManager createMailboxManager(String configuration, TemporaryFolder
temporaryFolder) throws MailboxException, IOException {
+            MaildirStore store = new MaildirStore(temporaryFolder.newFolder().getPath() +
configuration, new JVMMailboxPathLocker());
+            MaildirMailboxSessionMapperFactory mf = new MaildirMailboxSessionMapperFactory(store);
+            
+            MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
+            GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+            MessageParser messageParser = new MessageParser();
+
+            StoreMailboxManager manager = new StoreMailboxManager(mf, null, new JVMMailboxPathLocker(),
aclResolver, groupMembershipResolver, messageParser);
+            manager.init();
+
+            return manager;
+        }
+
+    }
+
+    @RunWith(ContractSuite.class)
+    @ContractImpl(StoreMailboxManager.class)
+    public static class DomainUser extends MaildirMailboxManagerTest {
+        @Rule public TemporaryFolder tmpFolder = new TemporaryFolder();
+
+        private IProducer<MailboxManager> producer = new IProducer<MailboxManager>()
{
+
+            @Override
+            public StoreMailboxManager newInstance() {
+                try {
+                    tmpFolder.create();
+                    return createMailboxManager("/%domain/%user", tmpFolder);
+                } catch (Exception e) {
+                    throw Throwables.propagate(e);
+                }
+            }
+
+            @Override
+            public void cleanUp() {
+                tmpFolder.delete();
+            }
+        };
+
+        @Contract.Inject
+        public IProducer<MailboxManager> getProducer() {
+            return producer;
+        }
+    }
+    
+    @Ignore
+    @RunWith(ContractSuite.class)
+    @ContractImpl(StoreMailboxManager.class)
+    public static class User extends MaildirMailboxManagerTest {
+        @Rule public TemporaryFolder tmpFolder = new TemporaryFolder();
+
+        private IProducer<MailboxManager> producer = new IProducer<MailboxManager>()
{
+
+            @Override
+            public StoreMailboxManager newInstance() {
+                try {
+                    tmpFolder.create();
+                    return createMailboxManager("/%user", tmpFolder);
+                } catch (Exception e) {
+                    throw Throwables.propagate(e);
+                }
+            }
+
+            @Override
+            public void cleanUp() {
+                tmpFolder.delete();
+            }
+        };
+
+        @Contract.Inject
+        public IProducer<MailboxManager> getProducer() {
+            return producer;
+        }
+    }
+
+    @RunWith(ContractSuite.class)
+    @ContractImpl(StoreMailboxManager.class)
+    public static class FullUser extends MaildirMailboxManagerTest {
+        @Rule public TemporaryFolder tmpFolder = new TemporaryFolder();
+
+        private IProducer<MailboxManager> producer = new IProducer<MailboxManager>()
{
+
+            @Override
+            public StoreMailboxManager newInstance() {
+                try {
+                    tmpFolder.create();
+                    return createMailboxManager("/%fulluser", tmpFolder);
+                } catch (Exception e) {
+                    throw Throwables.propagate(e);
+                }
+            }
+
+            @Override
+            public void cleanUp() {
+                tmpFolder.delete();
+            }
+        };
+
+        @Contract.Inject
+        public IProducer<MailboxManager> getProducer() {
+            return producer;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
deleted file mode 100644
index ea56353..0000000
--- a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirStressTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************
- * 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.maildir;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.james.mailbox.AbstractStressTest;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.acl.GroupMembershipResolver;
-import org.apache.james.mailbox.acl.MailboxACLResolver;
-import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.StoreMailboxManager;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.junit.After;
-import org.junit.Before;
-
-public class MaildirStressTest extends AbstractStressTest {
-
-    private static final String MAILDIR_HOME = "target/Maildir";
-
-    private StoreMailboxManager mailboxManager;
-    
-    @Before
-    public void setUp() throws MailboxException {
-        MaildirStore store = new MaildirStore(MAILDIR_HOME + "/%user", new JVMMailboxPathLocker());
-
-        MaildirMailboxSessionMapperFactory mf = new MaildirMailboxSessionMapperFactory(store);
-        MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
-        MessageParser messageParser = new MessageParser();
-
-        mailboxManager = new StoreMailboxManager(mf, null, new JVMMailboxPathLocker(), aclResolver,
groupMembershipResolver, messageParser);
-        mailboxManager.init();
-
-    }
-    
-    @After
-    public void tearDown() throws IOException {
-        FileUtils.deleteDirectory(new File(MAILDIR_HOME));
-    }
-
-    @Override
-    public void testStessTest() throws InterruptedException, MailboxException {
-        if (OsDetector.isWindows()) {
-            System.out.println("Maildir tests work only on non-windows systems. So skip the
test");
-        } else {
-            super.testStessTest();
-        }
-    }
-
-    @Override
-    protected MailboxManager getMailboxManager() {
-        return mailboxManager;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
index b876f44..7a9d836 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
@@ -16,99 +16,58 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.mailbox.inmemory;
-
-import static org.assertj.core.api.Assertions.assertThat;
 
-import java.util.List;
+package org.apache.james.mailbox.inmemory;
 
-import org.apache.james.mailbox.AbstractMailboxManagerTest;
-import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
-import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.MockAuthenticator;
-import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.LoggerFactory;
+import org.junit.runner.RunWith;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractImpl;
+import org.xenei.junit.contract.ContractSuite;
+import org.xenei.junit.contract.IProducer;
 
-/**
- * InMemoryMailboxManagerTest that extends the MailboxManagerTest.
- */
-public class InMemoryMailboxManagerTest extends AbstractMailboxManagerTest {
+import com.google.common.base.Throwables;
 
-    private MailboxSession session;
+@RunWith(ContractSuite.class)
+@ContractImpl(InMemoryMailboxManager.class)
+public class InMemoryMailboxManagerTest {
 
-    /**
-     * Setup the mailboxManager.
-     * 
-     * @throws Exception
-     */
-    @Before
-    public void setup() throws Exception {
-        createMailboxManager();
+    private IProducer<MailboxManager> producer = new IProducer<MailboxManager>()
{
 
-        session = getMailboxManager().createSystemSession(USER_1, LoggerFactory.getLogger("Test"));
-        getMailboxManager().startProcessingRequest(session);
-    }
-    
-    /**
-     * Close the system session and entityManagerFactory
-     * 
-     * @throws MailboxException 
-     * @throws BadCredentialsException 
-     */
-    @After
-    public void tearDown() throws MailboxException {
-        getMailboxManager().logout(session, true);
-        getMailboxManager().endProcessingRequest(session);
-        getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test")).close();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.james.mailbox.MailboxManagerTest#createMailboxManager()
-     */
-    @Override
-    protected void createMailboxManager() throws MailboxException {
+        @Override
+        public InMemoryMailboxManager newInstance() {
+            MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
+            GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
+            MessageParser messageParser = new MessageParser();
 
-        MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
-        MessageParser messageParser = new MessageParser();
+            InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
+            InMemoryMailboxManager mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory,
new MockAuthenticator(), new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver,
messageParser);
 
-        InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
-        StoreMailboxManager mailboxManager = new InMemoryMailboxManager(mailboxSessionMapperFactory,
new MockAuthenticator(), new JVMMailboxPathLocker(), aclResolver, groupMembershipResolver,
messageParser);
-        mailboxManager.init();
-        
-        setMailboxManager(mailboxManager);
+            try {
+                mailboxManager.init();
+            } catch (MailboxException e) {
+                throw Throwables.propagate(e);
+            }
 
-    }
+            return mailboxManager;
+        }
 
-    @Test
-    public void searchShouldNotReturnResultsFromOtherNamespaces() throws Exception {
-        getMailboxManager().createMailbox(new MailboxPath("#namespace", USER_1, "Other"),
session);
-        getMailboxManager().createMailbox(MailboxPath.inbox(session), session);
-        List<MailboxMetaData> metaDatas = getMailboxManager().search(new MailboxQuery(new
MailboxPath("#private", USER_1, ""), "*", '.'), session);
-        assertThat(metaDatas).hasSize(1);
-        assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
-    }
+        @Override
+        public void cleanUp() {
+        }
+    };
 
-    @Test
-    public void searchShouldNotReturnResultsFromOtherUsers() throws Exception {
-        getMailboxManager().createMailbox(new MailboxPath("#namespace", USER_2, "Other"),
session);
-        getMailboxManager().createMailbox(MailboxPath.inbox(session), session);
-        List<MailboxMetaData> metaDatas = getMailboxManager().search(new MailboxQuery(new
MailboxPath("#private", USER_1, ""), "*", '.'), session);
-        assertThat(metaDatas).hasSize(1);
-        assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
+    @Contract.Inject
+    public IProducer<MailboxManager> getProducer() {
+        return producer;
     }
     
 }


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