JAMES-1746 MailboxManager tests should be done with junit-contracts

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

Branch: refs/heads/master
Commit: 728b0375d18f617a0d9d72667b2e41a6edc16310
Parents: e2a1708
Author: Benoit Tellier <btell...@linagora.com>
Authored: Tue Jun 7 15:55:48 2016 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Wed Jun 8 17:09:29 2016 +0700

----------------------------------------------------------------------
 mailbox/api/pom.xml                             |   5 +
 .../mailbox/AbstractMailboxManagerTest.java     | 219 -----------------
 .../james/mailbox/AbstractStressTest.java       | 135 -----------
 .../james/mailbox/MailboxManagerStressTest.java | 153 ++++++++++++
 .../james/mailbox/MailboxManagerTest.java       | 234 +++++++++++++++++++
 .../cassandra/CassandraMailboxManagerTest.java  |  89 +++----
 mailbox/hbase/pom.xml                           |   5 +
 .../mailbox/hbase/HBaseMailboxManagerTest.java  | 133 +++++------
 mailbox/jcr/pom.xml                             |  10 +
 .../mailbox/jcr/JCRMailboxManagerTest.java      | 116 +++++----
 .../apache/james/mailbox/jcr/JCRStressTest.java |  88 -------
 mailbox/jpa/pom.xml                             |  10 +
 .../mailbox/jpa/JPAMailboxManagerTest.java      | 131 +++++------
 .../apache/james/mailbox/jpa/JPAStressTest.java | 120 ----------
 mailbox/maildir/pom.xml                         |  10 +
 .../maildir/MaildirMailboxManagerTest.java      |  97 --------
 .../maildir/MaildirMailboxManagerTests.java     | 157 +++++++++++++
 .../mailbox/maildir/MaildirStressTest.java      |  77 ------
 .../inmemory/InMemoryMailboxManagerTest.java    | 107 +++------
 19 files changed, 839 insertions(+), 1057 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/api/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/api/pom.xml b/mailbox/api/pom.xml
index c892d7e..12999c6 100644
--- a/mailbox/api/pom.xml
+++ b/mailbox/api/pom.xml
@@ -65,6 +65,11 @@
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.xenei</groupId>
+            <artifactId>junit-contracts</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
deleted file mode 100644
index 66b0179..0000000
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
+++ /dev/null
@@ -1,219 +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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.Date;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.exception.BadCredentialsException;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.mock.MockMailboxManager;
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.junit.After;
-import org.junit.Test;
-import org.slf4j.LoggerFactory;
-
-/**
- * Test the {@link StoreMailboxManager} methods that 
- * are not covered by the protocol-tester suite.
- * 
- * This class needs to be extended by the different mailbox 
- * implementations which are responsible to setup and 
- * implement the test methods.
- * 
- */
-public abstract class AbstractMailboxManagerTest {
-    
-    public final static String USER_1 = "USER_1";
-    public final static String USER_2 = "USER_2";
-
-    /**
-     * The mailboxManager that needs to get instanciated
-     * by the mailbox implementations.
-     */
-    protected MailboxManager mailboxManager;
-    private MailboxSession session;
-    
-    @After
-    public void teardown() throws MailboxException {
-        getMailboxManager().logout(session, false);
-        getMailboxManager().endProcessingRequest(session);
-    }
-    
-    @Test 
-    public void createUser1SystemSessionShouldReturnValidSession() throws 
UnsupportedEncodingException, MailboxException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        
-        assertThat(session.getUser().getUserName()).isEqualTo(USER_1);
-    }
-
-    @Test
-    public void user1ShouldNotHaveAnInbox() throws 
UnsupportedEncodingException, MailboxException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-        
-        MailboxPath inbox = MailboxPath.inbox(session);
-        assertThat(getMailboxManager().mailboxExists(inbox, 
session)).isFalse();
-    }
-    
-    @Test
-    public void user1ShouldBeAbleToCreateInbox() throws MailboxException, 
UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-     
-        MailboxPath inbox = MailboxPath.inbox(session);
-        getMailboxManager().createMailbox(inbox, session);
-        
-        assertThat(getMailboxManager().mailboxExists(inbox, session)).isTrue();
-    }
-
-    @Test(expected=MailboxException.class)
-    public void user1ShouldNotBeAbleToCreateInboxTwice() throws 
MailboxException, UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-        MailboxPath inbox = MailboxPath.inbox(session);
-        getMailboxManager().createMailbox(inbox, session);
-        getMailboxManager().createMailbox(inbox, session);
-    }
-
-    @Test
-    public void user1ShouldNotHaveTestSubmailbox() throws MailboxException, 
UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-
-        MailboxPath inbox = MailboxPath.inbox(session);
-        getMailboxManager().createMailbox(inbox, session);
-        
-        assertThat(getMailboxManager().mailboxExists(new MailboxPath(inbox, 
"INBOX.Test"), session)).isFalse();
-    }
-    
-    @Test
-    public void user1ShouldBeAbleToCreateTestSubmailbox() throws 
MailboxException, UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-        MailboxPath inbox = MailboxPath.inbox(session);
-        getMailboxManager().createMailbox(inbox, session);
-        
-        MailboxPath inboxSubMailbox = new MailboxPath(inbox, "INBOX.Test");
-        getMailboxManager().createMailbox(inboxSubMailbox, session);
-        
-        assertThat(getMailboxManager().mailboxExists(inboxSubMailbox, 
session)).isTrue();
-    }
-    
-    @Test
-    public void user1ShouldBeAbleToDeleteInbox() throws MailboxException, 
UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-     
-        MailboxPath inbox = MailboxPath.inbox(session);
-        getMailboxManager().createMailbox(inbox, session);
-        MailboxPath inboxSubMailbox = new MailboxPath(inbox, "INBOX.Test");
-        getMailboxManager().createMailbox(inboxSubMailbox, session);
-        
-        getMailboxManager().deleteMailbox(inbox, session);
-        
-        assertThat(getMailboxManager().mailboxExists(inbox, 
session)).isFalse();
-        assertThat(getMailboxManager().mailboxExists(inboxSubMailbox, 
session)).isTrue();
-    }
-    
-    @Test
-    public void user1ShouldBeAbleToDeleteSubmailbox() throws MailboxException, 
UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-     
-        MailboxPath inbox = MailboxPath.inbox(session);
-        getMailboxManager().createMailbox(inbox, session);
-        MailboxPath inboxSubMailbox = new MailboxPath(inbox, "INBOX.Test");
-        getMailboxManager().createMailbox(inboxSubMailbox, session);
-        
-        getMailboxManager().deleteMailbox(inboxSubMailbox, session);
-        
-        assertThat(getMailboxManager().mailboxExists(inbox, session)).isTrue();
-        assertThat(getMailboxManager().mailboxExists(inboxSubMailbox, 
session)).isFalse();
-    }
-
-    @Test
-    public void closingSessionShouldWork() throws BadCredentialsException, 
MailboxException, UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
-        getMailboxManager().startProcessingRequest(session);
-
-        getMailboxManager().logout(session, false);
-        getMailboxManager().endProcessingRequest(session);
-        
-        assertThat(session.isOpen()).isFalse();
-    }
-
-    @Test
-    public void listShouldReturnMailboxes() throws MailboxException, 
UnsupportedEncodingException {
-        setMailboxManager(new 
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
-        session = getMailboxManager().createSystemSession("manager", 
LoggerFactory.getLogger("testList"));
-        getMailboxManager().startProcessingRequest(session);
-        
-        
assertThat(getMailboxManager().list(session)).hasSize(MockMailboxManager.EXPECTED_MAILBOXES_COUNT);
-    }
-
-    @Test
-    public void user2ShouldBeAbleToCreateRootlessFolder() throws 
BadCredentialsException, MailboxException {
-        session = getMailboxManager().createSystemSession(USER_2, 
LoggerFactory.getLogger("Test"));
-        MailboxPath trash = new MailboxPath(MailboxConstants.USER_NAMESPACE, 
USER_2, "Trash");
-        getMailboxManager().createMailbox(trash, session);
-        
-        assertThat(getMailboxManager().mailboxExists(trash, session)).isTrue();
-    }
-    
-    @Test
-    public void user2ShouldBeAbleToCreateNestedFoldersWithoutTheirParents() 
throws BadCredentialsException, MailboxException {
-        session = getMailboxManager().createSystemSession(USER_2, 
LoggerFactory.getLogger("Test"));
-        MailboxPath nestedFolder = new 
MailboxPath(MailboxConstants.USER_NAMESPACE, USER_2, "INBOX.testfolder");
-        getMailboxManager().createMailbox(nestedFolder, session);
-        
-        assertThat(getMailboxManager().mailboxExists(nestedFolder, 
session)).isTrue();
-        getMailboxManager().getMailbox(MailboxPath.inbox(session), 
session).appendMessage(new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags());
-    }
-    
-    protected abstract void createMailboxManager() throws MailboxException, 
IOException;
-    
-    protected void setMailboxManager(MailboxManager mailboxManager) {
-        this.mailboxManager = mailboxManager;
-    }
-
-    protected MailboxManager getMailboxManager() {
-        if (mailboxManager == null) {
-            throw new IllegalStateException("Please setMailboxManager with a 
non null value before requesting getMailboxManager()");
-        }
-        return mailboxManager;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractStressTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractStressTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractStressTest.java
deleted file mode 100644
index 6886a67..0000000
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/AbstractStressTest.java
+++ /dev/null
@@ -1,135 +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;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.junit.Test;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractStressTest {
-
-    private final static int APPEND_OPERATIONS = 200;
-
-
-    protected abstract MailboxManager getMailboxManager();
-
-    @Test
-    public void testStessTest() throws InterruptedException, MailboxException {
-
-        final CountDownLatch latch = new CountDownLatch(APPEND_OPERATIONS);
-        final ExecutorService pool = 
Executors.newFixedThreadPool(APPEND_OPERATIONS / 2);
-        final List<Long> uList = new ArrayList<Long>();
-        final String username = "username";
-        MailboxSession session = 
getMailboxManager().createSystemSession(username, 
LoggerFactory.getLogger("Test"));
-        getMailboxManager().startProcessingRequest(session);
-        final MailboxPath path = new 
MailboxPath(MailboxConstants.USER_NAMESPACE, username, "INBOX");
-        getMailboxManager().createMailbox(path, session);
-        getMailboxManager().addListener(path, new MailboxListener() {
-
-            @Override
-            public ListenerType getType() {
-                return ListenerType.MAILBOX;
-            }
-
-            @Override
-            public ExecutionMode getExecutionMode() {
-                return ExecutionMode.SYNCHRONOUS;
-            }
-
-            @Override
-            public void event(Event event) {
-                long u = ((Added) event).getUids().get(0);
-                uList.add(u);
-            }
-        }, session);
-        getMailboxManager().endProcessingRequest(session);
-        getMailboxManager().logout(session, false);
-
-        final AtomicBoolean fail = new AtomicBoolean(false);
-        final ConcurrentHashMap<Long, Object> uids = new 
ConcurrentHashMap<Long, Object>();
-
-        // fire of 1000 append operations
-        for (int i = 0; i < APPEND_OPERATIONS; i++) {
-            pool.execute(new Runnable() {
-
-                public void run() {
-                    if (fail.get()) {
-                        latch.countDown();
-                        return;
-                    }
-
-
-                    try {
-                        MailboxSession session = 
getMailboxManager().createSystemSession(username, 
LoggerFactory.getLogger("Test"));
-
-                        getMailboxManager().startProcessingRequest(session);
-                        MessageManager m = 
getMailboxManager().getMailbox(path, session);
-                        Long uid = m.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), 
session, false, new Flags());
-
-                        System.out.println("Append message with uid=" + uid);
-                        if (uids.put(uid, new Object()) != null) {
-                            fail.set(true);
-                        }
-                        getMailboxManager().endProcessingRequest(session);
-                        getMailboxManager().logout(session, false);
-                    } catch (MailboxException e) {
-                        e.printStackTrace();
-                        fail.set(true);
-                    } finally {
-                        latch.countDown();
-                    }
-
-
-                }
-            });
-        }
-
-        latch.await();
-
-        // check if the uids were higher on each append. See MAILBOX-131
-        long last = 0;
-        for (Long uid : uList) {
-            if (uid <= last) {
-                fail(uid + "->" + last);
-            } else {
-                last = uid;
-            }
-
-        }
-        assertFalse("Unable to append all messages", fail.get());
-        pool.shutdown();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
new file mode 100644
index 0000000..6f7986a
--- /dev/null
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
@@ -0,0 +1,153 @@
+/****************************************************************
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.junit.After;
+import org.slf4j.LoggerFactory;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractTest;
+import org.xenei.junit.contract.IProducer;
+
+import com.google.common.collect.ImmutableSet;
+
+@Contract(MailboxManager.class)
+public class MailboxManagerStressTest<T extends MailboxManager> {
+
+    private final static int APPEND_OPERATIONS = 200;
+
+    private IProducer<T> producer;
+    private MailboxManager mailboxManager;
+
+    @Contract.Inject
+    public final void setProducer(IProducer<T> producer) throws 
MailboxException {
+        this.producer = producer;
+        this.mailboxManager = producer.newInstance();
+    }
+
+    @After
+    public void tearDown() {
+        producer.cleanUp();
+    }
+
+    @ContractTest
+    public void testStressTest() throws InterruptedException, MailboxException 
{
+
+        final CountDownLatch latch = new CountDownLatch(APPEND_OPERATIONS);
+        final ExecutorService pool = 
Executors.newFixedThreadPool(APPEND_OPERATIONS / 2);
+        final List<Long> uList = new ArrayList<Long>();
+        final String username = "username";
+        MailboxSession session = mailboxManager.createSystemSession(username, 
LoggerFactory.getLogger("Test"));
+        mailboxManager.startProcessingRequest(session);
+        final MailboxPath path = new 
MailboxPath(MailboxConstants.USER_NAMESPACE, username, "INBOX");
+        mailboxManager.createMailbox(path, session);
+        mailboxManager.addListener(path, new MailboxListener() {
+
+            @Override
+            public ListenerType getType() {
+                return ListenerType.MAILBOX;
+            }
+
+            @Override
+            public ExecutionMode getExecutionMode() {
+                return ExecutionMode.SYNCHRONOUS;
+            }
+
+            @Override
+            public void event(Event event) {
+                long u = ((Added) event).getUids().get(0);
+                uList.add(u);
+            }
+        }, session);
+        mailboxManager.endProcessingRequest(session);
+        mailboxManager.logout(session, false);
+
+        final AtomicBoolean fail = new AtomicBoolean(false);
+        final ConcurrentHashMap<Long, Object> uids = new 
ConcurrentHashMap<Long, Object>();
+
+        // fire of 1000 append operations
+        for (int i = 0; i < APPEND_OPERATIONS; i++) {
+            pool.execute(new Runnable() {
+
+                public void run() {
+                    if (fail.get()) {
+                        latch.countDown();
+                        return;
+                    }
+
+
+                    try {
+                        MailboxSession session = 
mailboxManager.createSystemSession(username, LoggerFactory.getLogger("Test"));
+
+                        mailboxManager.startProcessingRequest(session);
+                        MessageManager m = mailboxManager.getMailbox(path, 
session);
+                        Long uid = m.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), 
session, false, new Flags());
+
+                        System.out.println("Append message with uid=" + uid);
+                        if (uids.put(uid, new Object()) != null) {
+                            fail.set(true);
+                        }
+                        mailboxManager.endProcessingRequest(session);
+                        mailboxManager.logout(session, false);
+                    } catch (MailboxException e) {
+                        e.printStackTrace();
+                        fail.set(true);
+                    } finally {
+                        latch.countDown();
+                    }
+
+
+                }
+            });
+        }
+
+        latch.await();
+
+        // check if the uids were higher on each append. See MAILBOX-131
+        long last = 0;
+        for (Long uid : uList) {
+            if (uid <= last) {
+                fail(uid + "->" + last);
+            } else {
+                last = uid;
+            }
+
+        }
+        assertFalse("Unable to append all messages", fail.get());
+        pool.shutdown();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
new file mode 100644
index 0000000..6c9e741
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -0,0 +1,234 @@
+/****************************************************************
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.exception.BadCredentialsException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.mock.MockMailboxManager;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.model.MailboxMetaData;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxQuery;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
+import org.slf4j.LoggerFactory;
+import org.xenei.junit.contract.Contract;
+import org.xenei.junit.contract.ContractTest;
+import org.xenei.junit.contract.IProducer;
+
+/**
+ * Test the {@link StoreMailboxManager} methods that 
+ * are not covered by the protocol-tester suite.
+ * 
+ * This class needs to be extended by the different mailbox 
+ * implementations which are responsible to setup and 
+ * implement the test methods.
+ * 
+ */
+@Contract(MailboxManager.class)
+public class MailboxManagerTest<T extends MailboxManager> {
+    
+    public final static String USER_1 = "USER_1";
+    public final static String USER_2 = "USER_2";
+
+    @Rule
+    public ExpectedException expected = ExpectedException.none();
+
+    private IProducer<T> producer;
+    private MailboxManager mailboxManager;
+    private MailboxSession session;
+
+    @Contract.Inject
+    public final void setProducer(IProducer<T> producer) throws Exception {
+        this.producer = producer;
+        this.mailboxManager = new 
MockMailboxManager(producer.newInstance()).getMockMailboxManager();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        mailboxManager.logout(session, false);
+        mailboxManager.endProcessingRequest(session);
+
+        producer.cleanUp();
+    }
+    
+    @ContractTest
+    public void createUser1SystemSessionShouldReturnValidSession() throws 
UnsupportedEncodingException, MailboxException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        
+        assertThat(session.getUser().getUserName()).isEqualTo(USER_1);
+    }
+
+    @ContractTest
+    public void user1ShouldNotHaveAnInbox() throws 
UnsupportedEncodingException, MailboxException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+        
+        MailboxPath inbox = MailboxPath.inbox(session);
+        assertThat(mailboxManager.mailboxExists(inbox, session)).isFalse();
+    }
+    
+    @ContractTest
+    public void user1ShouldBeAbleToCreateInbox() throws MailboxException, 
UnsupportedEncodingException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+     
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        
+        assertThat(mailboxManager.mailboxExists(inbox, session)).isTrue();
+    }
+
+    @ContractTest
+    public void user1ShouldNotBeAbleToCreateInboxTwice() throws 
MailboxException, UnsupportedEncodingException {
+        expected.expect(MailboxException.class);
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        mailboxManager.createMailbox(inbox, session);
+    }
+
+    @ContractTest
+    public void user1ShouldNotHaveTestSubmailbox() throws MailboxException, 
UnsupportedEncodingException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        
+        assertThat(mailboxManager.mailboxExists(new MailboxPath(inbox, 
"INBOX.Test"), session)).isFalse();
+    }
+    
+    @ContractTest
+    public void user1ShouldBeAbleToCreateTestSubmailbox() throws 
MailboxException, UnsupportedEncodingException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        
+        MailboxPath inboxSubMailbox = new MailboxPath(inbox, "INBOX.Test");
+        mailboxManager.createMailbox(inboxSubMailbox, session);
+        
+        assertThat(mailboxManager.mailboxExists(inboxSubMailbox, 
session)).isTrue();
+    }
+    
+    @ContractTest
+    public void user1ShouldBeAbleToDeleteInbox() throws MailboxException, 
UnsupportedEncodingException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+     
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        MailboxPath inboxSubMailbox = new MailboxPath(inbox, "INBOX.Test");
+        mailboxManager.createMailbox(inboxSubMailbox, session);
+        
+        mailboxManager.deleteMailbox(inbox, session);
+        
+        assertThat(mailboxManager.mailboxExists(inbox, session)).isFalse();
+        assertThat(mailboxManager.mailboxExists(inboxSubMailbox, 
session)).isTrue();
+    }
+    
+    @ContractTest
+    public void user1ShouldBeAbleToDeleteSubmailbox() throws MailboxException, 
UnsupportedEncodingException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+     
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        MailboxPath inboxSubMailbox = new MailboxPath(inbox, "INBOX.Test");
+        mailboxManager.createMailbox(inboxSubMailbox, session);
+        
+        mailboxManager.deleteMailbox(inboxSubMailbox, session);
+        
+        assertThat(mailboxManager.mailboxExists(inbox, session)).isTrue();
+        assertThat(mailboxManager.mailboxExists(inboxSubMailbox, 
session)).isFalse();
+    }
+
+    @ContractTest
+    public void closingSessionShouldWork() throws BadCredentialsException, 
MailboxException, UnsupportedEncodingException {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.startProcessingRequest(session);
+
+        mailboxManager.logout(session, false);
+        mailboxManager.endProcessingRequest(session);
+        
+        assertThat(session.isOpen()).isFalse();
+    }
+
+    @ContractTest
+    public void listShouldReturnMailboxes() throws MailboxException, 
UnsupportedEncodingException {
+        session = mailboxManager.createSystemSession("manager", 
LoggerFactory.getLogger("testList"));
+        mailboxManager.startProcessingRequest(session);
+        
+        
assertThat(mailboxManager.list(session)).hasSize(MockMailboxManager.EXPECTED_MAILBOXES_COUNT);
+    }
+
+    @ContractTest
+    public void user2ShouldBeAbleToCreateRootlessFolder() throws 
BadCredentialsException, MailboxException {
+        session = mailboxManager.createSystemSession(USER_2, 
LoggerFactory.getLogger("Test"));
+        MailboxPath trash = new MailboxPath(MailboxConstants.USER_NAMESPACE, 
USER_2, "Trash");
+        mailboxManager.createMailbox(trash, session);
+        
+        assertThat(mailboxManager.mailboxExists(trash, session)).isTrue();
+    }
+    
+    @ContractTest
+    public void user2ShouldBeAbleToCreateNestedFoldersWithoutTheirParents() 
throws BadCredentialsException, MailboxException {
+        session = mailboxManager.createSystemSession(USER_2, 
LoggerFactory.getLogger("Test"));
+        MailboxPath nestedFolder = new 
MailboxPath(MailboxConstants.USER_NAMESPACE, USER_2, "INBOX.testfolder");
+        mailboxManager.createMailbox(nestedFolder, session);
+        
+        assertThat(mailboxManager.mailboxExists(nestedFolder, 
session)).isTrue();
+        mailboxManager.getMailbox(MailboxPath.inbox(session), 
session).appendMessage(new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags());
+    }
+
+    @ContractTest
+    public void searchShouldNotReturnResultsFromOtherNamespaces() throws 
Exception {
+        
Assume.assumeTrue(mailboxManager.getSupportedMailboxCapabilities().contains(MailboxManager.MailboxCapabilities.Namespace));
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.createMailbox(new MailboxPath("#namespace", USER_1, 
"Other"), session);
+        mailboxManager.createMailbox(MailboxPath.inbox(session), session);
+        List<MailboxMetaData> metaDatas = mailboxManager.search(new 
MailboxQuery(new MailboxPath("#private", USER_1, ""), "*", '.'), session);
+        assertThat(metaDatas).hasSize(1);
+        
assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
+    }
+
+    @ContractTest
+    public void searchShouldNotReturnResultsFromOtherUsers() throws Exception {
+        session = mailboxManager.createSystemSession(USER_1, 
LoggerFactory.getLogger("Mock"));
+        mailboxManager.createMailbox(new MailboxPath("#namespace", USER_2, 
"Other"), session);
+        mailboxManager.createMailbox(MailboxPath.inbox(session), session);
+        List<MailboxMetaData> metaDatas = mailboxManager.search(new 
MailboxQuery(new MailboxPath("#private", USER_1, ""), "*", '.'), session);
+        assertThat(metaDatas).hasSize(1);
+        
assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
index ad61efe..e22595f 100644
--- 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxManagerTest.java
@@ -20,8 +20,7 @@ package org.apache.james.mailbox.cassandra;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
-import org.apache.james.mailbox.AbstractMailboxManagerTest;
-import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider;
 import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
@@ -32,19 +31,24 @@ import 
org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraSubscriptionModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraUidModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraModSeqModule;
-import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.NoMailboxPathLocker;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.junit.After;
-import org.junit.Before;
-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;
+
+import com.google.common.base.Throwables;
 
 /**
  * CassandraMailboxManagerTest that extends the StoreMailboxManagerTest.
  * 
  */
-public class CassandraMailboxManagerTest extends AbstractMailboxManagerTest {
+@RunWith(ContractSuite.class)
+@ContractImpl(CassandraMailboxManager.class)
+public class CassandraMailboxManagerTest {
 
     private static final CassandraCluster CASSANDRA = 
CassandraCluster.create(new CassandraModuleComposite(
         new CassandraAclModule(),
@@ -56,56 +60,37 @@ public class CassandraMailboxManagerTest extends 
AbstractMailboxManagerTest {
         new CassandraSubscriptionModule(),
         new CassandraAttachmentModule()));
 
-    /**
-     * Setup the mailboxManager.
-     * 
-     * @throws Exception
-     */
-    @Before
-    public void setup() throws Exception {
-        CASSANDRA.ensureAllTables();
-        CASSANDRA.clearAllTables();
-        createMailboxManager();
-    }
+    private IProducer<MailboxManager> producer = new 
IProducer<MailboxManager>() {
 
-    /**
-     * Close the system session and entityManagerFactory
-     * 
-     * @throws MailboxException
-     * @throws BadCredentialsException
-     */
-    @After
-    public void tearDown() throws Exception {
-        deleteAllMailboxes();
-        MailboxSession session = 
getMailboxManager().createSystemSession("test", 
LoggerFactory.getLogger("Test"));
-        session.close();
-    }
+        @Override
+        public CassandraMailboxManager newInstance() {
+            CASSANDRA.ensureAllTables();
+            CassandraUidProvider uidProvider = new 
CassandraUidProvider(CASSANDRA.getConf());
+            CassandraModSeqProvider modSeqProvider = new 
CassandraModSeqProvider(CASSANDRA.getConf());
+            CassandraMailboxSessionMapperFactory mapperFactory = new 
CassandraMailboxSessionMapperFactory(uidProvider,
+                modSeqProvider,
+                CASSANDRA.getConf(),
+                CASSANDRA.getTypesProvider());
 
-    /*
-     * (non-Javadoc)i deve
-     * 
-     * @see org.apache.james.mailbox.MailboxManagerTest#createMailboxManager()
-     */
-    @Override
-    protected void createMailboxManager() throws MailboxException {
-        final CassandraUidProvider uidProvider = new 
CassandraUidProvider(CASSANDRA.getConf());
-        final CassandraModSeqProvider modSeqProvider = new 
CassandraModSeqProvider(CASSANDRA.getConf());
-        final CassandraMailboxSessionMapperFactory mapperFactory = new 
CassandraMailboxSessionMapperFactory(uidProvider,
-            modSeqProvider,
-            CASSANDRA.getConf(),
-            CASSANDRA.getTypesProvider());
+            CassandraMailboxManager manager = new 
CassandraMailboxManager(mapperFactory, null, new NoMailboxPathLocker(), new 
MessageParser());
+            try {
+                manager.init();
+            } catch (MailboxException e) {
+                throw Throwables.propagate(e);
+            }
 
-        final CassandraMailboxManager manager = new 
CassandraMailboxManager(mapperFactory, null, new NoMailboxPathLocker(), new 
MessageParser());
-        manager.init();
+            return manager;
+        }
 
-        setMailboxManager(manager);
+        @Override
+        public void cleanUp() {
+            CASSANDRA.clearAllTables();
+        }
+    };
 
-        deleteAllMailboxes();
+    @Contract.Inject
+    public IProducer<MailboxManager> getProducer() {
+        return producer;
     }
 
-    private void deleteAllMailboxes() throws BadCredentialsException, 
MailboxException {
-        MailboxSession session = 
getMailboxManager().createSystemSession("test", 
LoggerFactory.getLogger("Test"));
-        CASSANDRA.clearAllTables();
-        session.close();
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/hbase/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/hbase/pom.xml b/mailbox/hbase/pom.xml
index ca49c51..f173594 100644
--- a/mailbox/hbase/pom.xml
+++ b/mailbox/hbase/pom.xml
@@ -133,6 +133,11 @@
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.xenei</groupId>
+            <artifactId>junit-contracts</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <profiles>

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
 
b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
index c4cdaeb..ae06d58 100644
--- 
a/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
+++ 
b/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxManagerTest.java
@@ -18,99 +18,86 @@
  ****************************************************************/
 package org.apache.james.mailbox.hbase;
 
-import java.io.IOException;
-import org.apache.james.mailbox.AbstractMailboxManagerTest;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.acl.GroupMembershipResolver;
-import org.apache.james.mailbox.acl.MailboxACLResolver;
+import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOXES;
+import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOXES_TABLE;
+import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOX_CF;
+import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES;
+import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES_META_CF;
+import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES_TABLE;
+import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGE_DATA_BODY_CF;
+import static 
org.apache.james.mailbox.hbase.HBaseNames.MESSAGE_DATA_HEADERS_CF;
+import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTIONS;
+import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTIONS_TABLE;
+import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTION_CF;
+
+import org.apache.james.mailbox.MailboxManager;
 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 static org.apache.james.mailbox.hbase.HBaseNames.*;
 import org.apache.james.mailbox.hbase.mail.HBaseModSeqProvider;
 import org.apache.james.mailbox.hbase.mail.HBaseUidProvider;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.junit.After;
-import org.junit.Before;
-import org.slf4j.LoggerFactory;
-
-/**
- * HBaseMailboxManagerTest that extends the StoreMailboxManagerTest.
- *
- */
-public class HBaseMailboxManagerTest extends AbstractMailboxManagerTest {
+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;
 
-    private static final HBaseClusterSingleton CLUSTER = 
HBaseClusterSingleton.build();
+import com.google.common.base.Throwables;
 
-    /**
-     * Setup the mailboxManager.
+@RunWith(ContractSuite.class)
+@ContractImpl(HBaseMailboxManager.class)
+public class HBaseMailboxManagerTest {
 
-     * @throws Exception
-     */
-    @Before
-    public void setup() throws Exception {
-        ensureTables();
-        clearTables();
-        createMailboxManager();
-    }
-
-    private void ensureTables() throws IOException {
-        CLUSTER.ensureTable(MAILBOXES_TABLE, new byte[][]{MAILBOX_CF});
-        CLUSTER.ensureTable(MESSAGES_TABLE,
-                new byte[][]{MESSAGES_META_CF, MESSAGE_DATA_HEADERS_CF, 
MESSAGE_DATA_BODY_CF});
-        CLUSTER.ensureTable(SUBSCRIPTIONS_TABLE, new 
byte[][]{SUBSCRIPTION_CF});
-    }
+    private static final HBaseClusterSingleton CLUSTER = 
HBaseClusterSingleton.build();
 
-    private void clearTables() {
-        CLUSTER.clearTable(MAILBOXES);
-        CLUSTER.clearTable(MESSAGES);
-        CLUSTER.clearTable(SUBSCRIPTIONS);
-    }
+    private IProducer<MailboxManager> producer = new 
IProducer<MailboxManager>() {
 
-    /**
-     * Close the system session and entityManagerFactory
-     *
-     * @throws MailboxException
-     * @throws BadCredentialsException
-     */
-    @After
-    public void tearDown() throws Exception {
-        deleteAllMailboxes();
-        MailboxSession session = 
getMailboxManager().createSystemSession("test", 
LoggerFactory.getLogger("Test"));
-        session.close();
-    }
+        @Override
+        public HBaseMailboxManager newInstance() {
+            ensureTables();
 
-    /* (non-Javadoc)i deve
-     * @see org.apache.james.mailbox.MailboxManagerTest#createMailboxManager()
-     */
-    @Override
-    protected void createMailboxManager() throws MailboxException {
-        final HBaseUidProvider uidProvider = new 
HBaseUidProvider(CLUSTER.getConf());
-        final HBaseModSeqProvider modSeqProvider = new 
HBaseModSeqProvider(CLUSTER.getConf());
-        final HBaseMailboxSessionMapperFactory mapperFactory = new 
HBaseMailboxSessionMapperFactory(CLUSTER.getConf(),
+            HBaseUidProvider uidProvider = new 
HBaseUidProvider(CLUSTER.getConf());
+            HBaseModSeqProvider modSeqProvider = new 
HBaseModSeqProvider(CLUSTER.getConf());
+            HBaseMailboxSessionMapperFactory mapperFactory = new 
HBaseMailboxSessionMapperFactory(CLUSTER.getConf(),
                 uidProvider, modSeqProvider);
 
-        final MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        final GroupMembershipResolver groupMembershipResolver = new 
SimpleGroupMembershipResolver();
-        final MessageParser messageParser = new MessageParser();
+            HBaseMailboxManager manager = new 
HBaseMailboxManager(mapperFactory,
+                null,
+                new UnionMailboxACLResolver(),
+                new SimpleGroupMembershipResolver(),
+                new MessageParser());
 
-        final HBaseMailboxManager manager = new 
HBaseMailboxManager(mapperFactory, null, aclResolver,
-                groupMembershipResolver, messageParser);
-        manager.init();
+            try {
+                manager.init();
+            } catch (MailboxException e) {
+                throw Throwables.propagate(e);
+            }
 
-        setMailboxManager(manager);
+            return manager;
+        }
 
-        deleteAllMailboxes();
+        @Override
+        public void cleanUp() {
+            CLUSTER.clearTable(MAILBOXES);
+            CLUSTER.clearTable(MESSAGES);
+            CLUSTER.clearTable(SUBSCRIPTIONS);
+        }
+    };
+
+    @Contract.Inject
+    public IProducer<MailboxManager> getProducer() {
+        return producer;
     }
 
-    private void deleteAllMailboxes() throws BadCredentialsException, 
MailboxException {
-        MailboxSession session = 
getMailboxManager().createSystemSession("test", 
LoggerFactory.getLogger("Test"));
+    private void ensureTables() {
         try {
-            ((HBaseMailboxManager) mailboxManager).deleteEverything(session);
-        } catch (MailboxException e) {
-            e.printStackTrace();
+            CLUSTER.ensureTable(MAILBOXES_TABLE, new byte[][]{MAILBOX_CF});
+            CLUSTER.ensureTable(MESSAGES_TABLE,
+                new byte[][]{MESSAGES_META_CF, MESSAGE_DATA_HEADERS_CF, 
MESSAGE_DATA_BODY_CF});
+            CLUSTER.ensureTable(SUBSCRIPTIONS_TABLE, new 
byte[][]{SUBSCRIPTION_CF});
+        } catch (Exception e) {
+            throw Throwables.propagate(e);
         }
-        session.close();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/jcr/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/jcr/pom.xml b/mailbox/jcr/pom.xml
index 7a27bb0..e6a0c24 100644
--- a/mailbox/jcr/pom.xml
+++ b/mailbox/jcr/pom.xml
@@ -104,5 +104,15 @@
             <version>${assertj-1.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.xenei</groupId>
+            <artifactId>junit-contracts</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
 
b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
index 9abeb32..e5a725b 100644
--- 
a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
+++ 
b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.jcr;
 import static org.junit.Assert.fail;
 
 import java.io.File;
+import java.io.IOException;
 
 import javax.jcr.RepositoryException;
 
@@ -28,8 +29,8 @@ import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.ConfigurationException;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
-import org.apache.james.mailbox.AbstractMailboxManagerTest;
-import org.apache.james.mailbox.MailboxSession;
+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;
@@ -39,66 +40,79 @@ import org.apache.james.mailbox.jcr.mail.JCRModSeqProvider;
 import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.junit.After;
-import org.junit.Before;
-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;
 import org.xml.sax.InputSource;
 
-/**
- * JCRMailboxManagerTest that extends the StoreMailboxManagerTest.
- */
-public class JCRMailboxManagerTest extends AbstractMailboxManagerTest {
+import com.google.common.base.Throwables;
 
-    private static final String JACKRABBIT_HOME = "target/jackrabbit";
+@RunWith(ContractSuite.class)
+@ContractImpl(JCRMailboxManager.class)
+public class JCRMailboxManagerTest extends MailboxManagerTest {
 
-    public static final String META_DATA_DIRECTORY = "target/user-meta-data";
+    private static final String JACKRABBIT_HOME = "target/jackrabbit";
 
     private static RepositoryImpl repository;
 
-    @Before
-    public void setup() throws Exception {
-        createMailboxManager();
-    }
+    private IProducer<MailboxManager> producer = new 
IProducer<MailboxManager>() {
 
-    @After
-    public void tearDown() throws Exception {
-        MailboxSession session = 
getMailboxManager().createSystemSession("test", 
LoggerFactory.getLogger("Test"));
-        session.close();
-        repository.shutdown();
-        FileUtils.forceDelete(new File(JACKRABBIT_HOME));
-    }
+        @Override
+        public JCRMailboxManager newInstance() {
+            String user = "user";
+            String pass = "pass";
+            String workspace = null;
+            RepositoryConfig config;
+            try {
+                config = RepositoryConfig.create(new 
InputSource(JCRMailboxManagerTest.class.getClassLoader().getResourceAsStream("test-repository.xml")),
 JACKRABBIT_HOME);
+                repository = RepositoryImpl.create(config);
+            } catch (ConfigurationException e) {
+                e.printStackTrace();
+                fail();
+            } catch (RepositoryException e) {
+                e.printStackTrace();
+                fail();
+            }
+
+            // Register imap cnd file
+            JCRUtils.registerCnd(repository, workspace, user, pass);
+            MailboxSessionJCRRepository sessionRepos = new 
GlobalMailboxSessionJCRRepository(repository, workspace, user, pass);
+            JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
+            JCRUidProvider uidProvider = new JCRUidProvider(locker, 
sessionRepos);
+            JCRModSeqProvider modSeqProvider = new JCRModSeqProvider(locker, 
sessionRepos);
+            JCRMailboxSessionMapperFactory mf = new 
JCRMailboxSessionMapperFactory(sessionRepos, uidProvider, modSeqProvider);
+
+            MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
+            GroupMembershipResolver groupMembershipResolver = new 
SimpleGroupMembershipResolver();
+            MessageParser messageParser = new MessageParser();
+
+            JCRMailboxManager manager = new JCRMailboxManager(mf, null, 
locker, aclResolver, groupMembershipResolver, messageParser);
+
+            try {
+                manager.init();
+            } catch (MailboxException e) {
+                throw Throwables.propagate(e);
+            }
+
+            return manager;
+        }
 
-    protected void createMailboxManager() throws MailboxException {
-        String user = "user";
-        String pass = "pass";
-        String workspace = null;
-        RepositoryConfig config;
-        try {
-            config = RepositoryConfig.create(new 
InputSource(JCRMailboxManagerTest.class.getClassLoader().getResourceAsStream("test-repository.xml")),
 JACKRABBIT_HOME);
-            repository = RepositoryImpl.create(config);
-        } catch (ConfigurationException e) {
-            e.printStackTrace();
-            fail();
-        } catch (RepositoryException e) {
-            e.printStackTrace();
-            fail();
+        @Override
+        public void cleanUp() {
+            repository.shutdown();
+            try {
+                FileUtils.forceDelete(new File(JACKRABBIT_HOME));
+            } catch (IOException e) {
+                throw Throwables.propagate(e);
+            }
         }
+    };
 
-        // Register imap cnd file
-        JCRUtils.registerCnd(repository, workspace, user, pass);
-        MailboxSessionJCRRepository sessionRepos = new 
GlobalMailboxSessionJCRRepository(repository, workspace, user, pass);
-        JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
-        JCRUidProvider uidProvider = new JCRUidProvider(locker, sessionRepos);
-        JCRModSeqProvider modSeqProvider = new JCRModSeqProvider(locker, 
sessionRepos);
-        JCRMailboxSessionMapperFactory mf = new 
JCRMailboxSessionMapperFactory(sessionRepos, uidProvider, modSeqProvider);
-
-        MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        GroupMembershipResolver groupMembershipResolver = new 
SimpleGroupMembershipResolver();
-        MessageParser messageParser = new MessageParser();
-
-        JCRMailboxManager manager = new JCRMailboxManager(mf, null, locker, 
aclResolver, groupMembershipResolver, messageParser);
-        manager.init();
-        setMailboxManager(manager);
+    @Contract.Inject
+    public IProducer<MailboxManager> getProducer() {
+        return producer;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java 
b/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
deleted file mode 100644
index 50bd955..0000000
--- a/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
+++ /dev/null
@@ -1,88 +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.jcr;
-
-import java.io.File;
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.core.RepositoryImpl;
-import org.apache.jackrabbit.core.config.RepositoryConfig;
-import org.apache.james.mailbox.AbstractStressTest;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-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.jcr.mail.JCRModSeqProvider;
-import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.junit.After;
-import org.junit.Before;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.InputSource;
-
-public class JCRStressTest extends AbstractStressTest {
-
-    private JCRMailboxManager mailboxManager;
-    private RepositoryImpl repository;
-    private static final String JACKRABBIT_HOME = "target/jackrabbit";
-
-    @Before
-    public void setUp() throws RepositoryException, MailboxException {
-        String user = "user";
-        String pass = "pass";
-        String workspace = null;
-        RepositoryConfig config = RepositoryConfig.create(new 
InputSource(this.getClass().getClassLoader().getResourceAsStream("test-repository.xml")),
 JACKRABBIT_HOME);
-        repository = RepositoryImpl.create(config);
-
-        // Register imap cnd file
-        JCRUtils.registerCnd(repository, workspace, user, pass);
-        MailboxSessionJCRRepository sessionRepos = new 
GlobalMailboxSessionJCRRepository(repository, workspace, user, pass);
-        JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
-        JCRUidProvider uidProvider = new JCRUidProvider(locker, sessionRepos);
-        JCRModSeqProvider modSeqProvider = new JCRModSeqProvider(locker, 
sessionRepos);
-        JCRMailboxSessionMapperFactory mf = new 
JCRMailboxSessionMapperFactory(sessionRepos, uidProvider, modSeqProvider);
-        MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        GroupMembershipResolver groupMembershipResolver = new 
SimpleGroupMembershipResolver();
-        MessageParser messageParser = new MessageParser();
-
-        mailboxManager = new JCRMailboxManager(mf, null, locker, aclResolver, 
groupMembershipResolver, messageParser);
-        mailboxManager.init();
-    }
-
-    @After
-    public void tearDown() throws IOException {
-        MailboxSession session = mailboxManager.createSystemSession("test", 
LoggerFactory.getLogger(JCRStressTest.class));
-        session.close();
-        repository.shutdown();
-        FileUtils.forceDelete(new File(JACKRABBIT_HOME));
-    }
-
-    @Override
-    protected MailboxManager getMailboxManager() {
-        return mailboxManager;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/jpa/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/jpa/pom.xml b/mailbox/jpa/pom.xml
index 1495cd8..b2627ea 100644
--- a/mailbox/jpa/pom.xml
+++ b/mailbox/jpa/pom.xml
@@ -80,6 +80,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
             <scope>test</scope>
@@ -95,6 +100,11 @@
             <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.xenei</groupId>
+            <artifactId>junit-contracts</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
 
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
index aa7ab42..fb43b12 100644
--- 
a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
+++ 
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
@@ -22,13 +22,12 @@ import java.util.HashMap;
 
 import javax.persistence.EntityManagerFactory;
 
-import org.apache.james.mailbox.AbstractMailboxManagerTest;
+import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 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.jpa.mail.JPAModSeqProvider;
 import org.apache.james.mailbox.jpa.mail.JPAUidProvider;
@@ -42,89 +41,79 @@ import 
org.apache.james.mailbox.jpa.user.model.JPASubscription;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.runner.RunWith;
 import org.slf4j.LoggerFactory;
+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;
+
+@RunWith(ContractSuite.class)
+@ContractImpl(OpenJPAMailboxManager.class)
+public class JPAMailboxManagerTest {
 
-/**
- * JPAMailboxManagerTest that extends the StoreMailboxManagerTest.
- */
-public class JPAMailboxManagerTest extends AbstractMailboxManagerTest {
-    
     /**
      * The entity manager factory.
      */
     private static EntityManagerFactory entityManagerFactory;
-    
-    /**
-     * Setup the mailboxManager.
-     * 
-     * @throws Exception
-     */
-    @Before
-    public void setup() throws Exception {
-        createMailboxManager();
-    }
-    
-    /**
-     * Close the system session and entityManagerFactory
-     * 
-     * @throws MailboxException 
-     * @throws BadCredentialsException 
-     */
-    @After
-    public void tearDown() throws BadCredentialsException, MailboxException {
-        deleteAllMailboxes();
-        MailboxSession session = 
getMailboxManager().createSystemSession("test", 
LoggerFactory.getLogger("Test"));
-        session.close();
-        entityManagerFactory.close();
-    }
 
-    /* (non-Javadoc)
-     * @see org.apache.james.mailbox.MailboxManagerTest#createMailboxManager()
-     */
-    @Override
-    protected void createMailboxManager() throws MailboxException {
-        
-        HashMap<String, String> properties = new HashMap<String, String>();
-        properties.put("openjpa.ConnectionDriverName", "org.h2.Driver");
-        properties.put("openjpa.ConnectionURL", 
"jdbc:h2:mem:imap;DB_CLOSE_DELAY=-1");
-        properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN");
-        properties.put("openjpa.ConnectionFactoryProperties", 
"PrettyPrint=true, PrettyPrintLineLength=72");
-        properties.put("openjpa.jdbc.SynchronizeMappings", 
"buildSchema(ForeignKeys=true)");
-        properties.put("openjpa.MetaDataFactory", "jpa(Types=" +
+    private IProducer<MailboxManager> producer = new 
IProducer<MailboxManager>() {
+
+        private OpenJPAMailboxManager openJPAMailboxManager;
+
+        @Override
+        public OpenJPAMailboxManager newInstance() {
+            HashMap<String, String> properties = new HashMap<String, String>();
+            properties.put("openjpa.ConnectionDriverName", "org.h2.Driver");
+            properties.put("openjpa.ConnectionURL", 
"jdbc:h2:mem:imap;DB_CLOSE_DELAY=-1");
+            properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN");
+            properties.put("openjpa.ConnectionFactoryProperties", 
"PrettyPrint=true, PrettyPrintLineLength=72");
+            properties.put("openjpa.jdbc.SynchronizeMappings", 
"buildSchema(ForeignKeys=true)");
+            properties.put("openjpa.MetaDataFactory", "jpa(Types=" +
                 JPAMailbox.class.getName() + ";" +
                 AbstractJPAMailboxMessage.class.getName() + ";" +
                 JPAMailboxMessage.class.getName() + ";" +
                 JPAProperty.class.getName() + ";" +
                 JPAUserFlag.class.getName() + ";" +
                 JPASubscription.class.getName() + ")");
-       
-        entityManagerFactory = 
OpenJPAPersistence.getEntityManagerFactory(properties);
-        JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
-        JPAMailboxSessionMapperFactory mf = new 
JPAMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(locker, 
entityManagerFactory), new JPAModSeqProvider(locker, entityManagerFactory));
-
-        MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        GroupMembershipResolver groupMembershipResolver = new 
SimpleGroupMembershipResolver();
-        MessageParser messageParser = new MessageParser();
-
-        JPAMailboxManager mailboxManager = new OpenJPAMailboxManager(mf, null, 
aclResolver, groupMembershipResolver, messageParser);
-        mailboxManager.init();
-
-        setMailboxManager(mailboxManager);
-        
-        deleteAllMailboxes();
-        
-    }
-    
-    private void deleteAllMailboxes() throws BadCredentialsException, 
MailboxException {
-        MailboxSession session = 
getMailboxManager().createSystemSession("test", 
LoggerFactory.getLogger("Test"));
-        try {
-            ((OpenJPAMailboxManager) mailboxManager).deleteEverything(session);
-        } catch (MailboxException e) {
-            e.printStackTrace();
+
+            entityManagerFactory = 
OpenJPAPersistence.getEntityManagerFactory(properties);
+            JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
+            JPAMailboxSessionMapperFactory mf = new 
JPAMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(locker, 
entityManagerFactory), new JPAModSeqProvider(locker, entityManagerFactory));
+
+            MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
+            GroupMembershipResolver groupMembershipResolver = new 
SimpleGroupMembershipResolver();
+            MessageParser messageParser = new MessageParser();
+
+            openJPAMailboxManager = new OpenJPAMailboxManager(mf, null, 
aclResolver, groupMembershipResolver, messageParser);
+
+            try {
+                openJPAMailboxManager.init();
+            } catch (MailboxException e) {
+                throw Throwables.propagate(e);
+            }
+
+            return openJPAMailboxManager;
         }
-        session.close();
+
+        @Override
+        public void cleanUp() {
+            MailboxSession session = 
openJPAMailboxManager.createSystemSession("test", 
LoggerFactory.getLogger("Test"));
+            try {
+                openJPAMailboxManager.deleteEverything(session);
+            } catch (MailboxException e) {
+                e.printStackTrace();
+            }
+            session.close();
+            entityManagerFactory.close();
+        }
+    };
+
+    @Contract.Inject
+    public IProducer<MailboxManager> getProducer() {
+        return producer;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java 
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
deleted file mode 100644
index 7eab4ea..0000000
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAStressTest.java
+++ /dev/null
@@ -1,120 +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.jpa;
-
-import java.util.HashMap;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.james.mailbox.AbstractStressTest;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-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.jpa.mail.JPAModSeqProvider;
-import org.apache.james.mailbox.jpa.mail.JPAUidProvider;
-import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
-import org.apache.james.mailbox.jpa.mail.model.JPAProperty;
-import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
-import 
org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage;
-import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage;
-import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
-import org.apache.james.mailbox.jpa.user.model.JPASubscription;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
-import org.junit.After;
-import org.junit.Before;
-import org.slf4j.LoggerFactory;
-
-/**
- * Proof of bug https://issues.apache.org/jira/browse/IMAP-137
- */
-public class JPAStressTest extends AbstractStressTest {
-    
-    private OpenJPAMailboxManager mailboxManager;
-    
-    private long locktimeout = 60000;
-    
-    private EntityManagerFactory entityManagerFactory;
-    
-    @Before
-    public void setUp() throws MailboxException {
-        
-        HashMap<String, String> properties = new HashMap<String, String>();
-        properties.put("openjpa.ConnectionDriverName", 
org.h2.Driver.class.getName());
-        properties.put("openjpa.ConnectionURL", 
"jdbc:h2:mem:mailboxintegrationstress;DB_CLOSE_DELAY=-1");
-        properties.put("openjpa.Log", "JDBC=WARN, SQL=WARN, Runtime=WARN");
-        properties.put("openjpa.ConnectionFactoryProperties", 
"PrettyPrint=true, PrettyPrintLineLength=72");
-        properties.put("openjpa.jdbc.SynchronizeMappings", 
"buildSchema(ForeignKeys=true)");
-        properties.put("openjpa.MetaDataFactory", "jpa(Types=" +
-                JPAMailbox.class.getName() + ";" +
-                AbstractJPAMailboxMessage.class.getName() + ";" +
-                JPAMailboxMessage.class.getName() + ";" +
-                JPAProperty.class.getName() + ";" +
-                JPAUserFlag.class.getName() + ";" +
-                JPASubscription.class.getName() + ")");
-        properties.put("openjpa.LockTimeout", locktimeout + "");
-       
-        entityManagerFactory = 
OpenJPAPersistence.getEntityManagerFactory(properties);
-        JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
-        JPAMailboxSessionMapperFactory mf = new 
JPAMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(locker, 
entityManagerFactory), new JPAModSeqProvider(locker, entityManagerFactory));
-
-        MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
-        GroupMembershipResolver groupMembershipResolver = new 
SimpleGroupMembershipResolver();
-        MessageParser messageParser = new MessageParser();
-
-        mailboxManager = new OpenJPAMailboxManager(mf, null, aclResolver, 
groupMembershipResolver, messageParser);
-        mailboxManager.init();
-
-        // Set the lock timeout via SQL because of a bug in openJPA
-        // https://issues.apache.org/jira/browse/OPENJPA-1656
-        setH2LockTimeout();
-    
-    }
-    
-    private void setH2LockTimeout() {
-        EntityManager manager = entityManagerFactory.createEntityManager();
-        manager.getTransaction().begin();
-        manager.createNativeQuery("SET DEFAULT_LOCK_TIMEOUT " + 
locktimeout).executeUpdate();
-        manager.getTransaction().commit();
-        manager.close();
-    }
-    
-    @After
-    public void tearDown() {
-        MailboxSession session = mailboxManager.createSystemSession("test", 
LoggerFactory.getLogger("Test"));
-        try {
-            mailboxManager.deleteEverything(session);
-        } catch (MailboxException e) {
-            e.printStackTrace();
-        }
-        session.close();
-    }
-
-    @Override
-    protected MailboxManager getMailboxManager() {
-        return mailboxManager;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/maildir/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/maildir/pom.xml b/mailbox/maildir/pom.xml
index bbb3ec5..699abef 100644
--- a/mailbox/maildir/pom.xml
+++ b/mailbox/maildir/pom.xml
@@ -92,5 +92,15 @@
             <version>${assertj-1.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.xenei</groupId>
+            <artifactId>junit-contracts</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/james-project/blob/728b0375/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
 
b/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
deleted file mode 100644
index 8203a40..0000000
--- 
a/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
+++ /dev/null
@@ -1,97 +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.IOException;
-
-import org.apache.james.mailbox.AbstractMailboxManagerTest;
-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.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runners.Suite.SuiteClasses;
-
-@SuiteClasses({
-    MaildirMailboxManagerTest.DomainUser.class,
-    MaildirMailboxManagerTest.User.class,
-    MaildirMailboxManagerTest.FullUser.class})
-
-public class MaildirMailboxManagerTest {
-
-    public static abstract class AbstractMaildirMailboxManagerTest extends 
AbstractMailboxManagerTest {
-        @Rule public TemporaryFolder tmpFolder = new TemporaryFolder();
-        
-        @Before
-        public void setup() throws Exception {
-            if (OsDetector.isWindows()) {
-                System.out.println("Maildir tests work only on non-windows 
systems. So skip the test");
-            } else {
-                createMailboxManager();
-            }
-        }
-        
-        protected void createMailboxManager(String configuration) throws 
MailboxException, IOException {
-            MaildirStore store = new 
MaildirStore(tmpFolder.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();
-            setMailboxManager(manager);
-        }
-
-    }
-    
-    public static class DomainUser extends AbstractMaildirMailboxManagerTest {
-        @Override
-        protected void createMailboxManager() throws MailboxException,
-                IOException {
-            createMailboxManager("/%domain/%user");
-        }
-    }
-    
-    @Ignore
-    public static class User extends AbstractMaildirMailboxManagerTest {
-        @Override
-        protected void createMailboxManager() throws MailboxException,
-                IOException {
-            createMailboxManager("/%user");
-        }
-    }
-    
-    public static class FullUser extends AbstractMaildirMailboxManagerTest {
-        @Override
-        protected void createMailboxManager() throws MailboxException,
-                IOException {
-            createMailboxManager("/%fulluser");
-        }
-    }
-
-}


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