Author: eric
Date: Mon Jan 3 13:44:16 2011
New Revision: 1054614
URL: http://svn.apache.org/viewvc?rev=1054614&view=rev
Log:
Have a separate Mock MailboxManager for testing purposes.
Added:
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxManager.java
Modified:
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
Modified:
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
URL:
http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java?rev=1054614&r1=1054613&r2=1054614&view=diff
==============================================================================
---
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
(original)
+++
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
Mon Jan 3 13:44:16 2011
@@ -18,21 +18,12 @@
****************************************************************/
package org.apache.james.mailbox;
-import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
-import java.util.Calendar;
-
-import javax.mail.Flags;
import junit.framework.Assert;
import org.apache.commons.logging.impl.SimpleLog;
-import org.apache.james.mailbox.MailboxException;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxPath;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageManager;
-import org.apache.james.mailbox.mock.MockMail;
+import org.apache.james.mailbox.mock.MockMailboxManager;
import org.junit.Test;
/**
@@ -53,31 +44,6 @@ public abstract class MailboxManagerTest
protected MailboxManager mailboxManager;
/**
- * Number of Domains to be created in the Mailbox Manager.
- */
- private static final int DOMAIN_COUNT = 3;
-
- /**
- * Number of Users (with INBOX) to be created in the Mailbox Manager.
- */
- private static final int USER_COUNT = 3;
-
- /**
- * Number of Sub Mailboxes (mailbox in INBOX) to be created in the Mailbox
Manager.
- */
- private static final int SUB_MAILBOXES_COUNT = 3;
-
- /**
- * Number of Sub Sub Mailboxes (mailbox in a mailbox under INBOX) to be
created in the Mailbox Manager.
- */
- private static final int SUB_SUB_MAILBOXES_COUNT = 3;
-
- /**
- * Number of Messages per Mailbox to be created in the Mailbox Manager.
- */
- private static final int MESSAGE_PER_MAILBOX_COUNT = 3;
-
- /**
* Create some INBOXes and their sub mailboxes and assert list() method.
*
* @throws UnsupportedEncodingException
@@ -86,86 +52,15 @@ public abstract class MailboxManagerTest
@Test
public void testList() throws MailboxException,
UnsupportedEncodingException {
- feedMailboxManager();
+ setMailboxManager(new
MockMailboxManager(getMailboxManager()).getMockMailboxManager());
MailboxSession mailboxSession =
getMailboxManager().createSystemSession("manager", new SimpleLog("testList"));
getMailboxManager().startProcessingRequest(mailboxSession);
- Assert.assertEquals(DOMAIN_COUNT *
- (USER_COUNT + // INBOX
- USER_COUNT * SUB_MAILBOXES_COUNT + // INBOX.SUB_FOLDER
- USER_COUNT * SUB_MAILBOXES_COUNT * SUB_SUB_MAILBOXES_COUNT),
// INBOX.SUB_FOLDER.SUBSUB_FOLDER
- getMailboxManager().list(mailboxSession).size());
+ Assert.assertEquals(MockMailboxManager.EXPECTED_MAILBOXES_COUNT,
getMailboxManager().list(mailboxSession).size());
}
/**
- * Utility method to feed the Mailbox Manager with a number of
- * mailboxes and messages per mailbox.
- *
- * @throws MailboxException
- * @throws UnsupportedEncodingException
- */
- private void feedMailboxManager() throws MailboxException,
UnsupportedEncodingException {
-
- MailboxPath mailboxPath = null;
-
- for (int i=0; i < DOMAIN_COUNT; i++) {
-
- for (int j=0; j < USER_COUNT; j++) {
-
- String user = "user" + j + "@localhost" + i;
-
- String folderName = "INBOX";
-
- MailboxSession mailboxSession =
getMailboxManager().createSystemSession(user, new
SimpleLog("mailboxmanager-test"));
- mailboxPath = new MailboxPath("#private", user, folderName);
- createMailbox(mailboxSession, mailboxPath);
-
- for (int k=0; k < SUB_MAILBOXES_COUNT; k++) {
-
- String subFolderName = folderName + ".SUB_FOLDER_" + k;
- mailboxPath = new MailboxPath("#private", user,
subFolderName);
- createMailbox(mailboxSession, mailboxPath);
-
- for (int l=0; l < SUB_SUB_MAILBOXES_COUNT; l++) {
-
- String subSubfolderName = subFolderName +
".SUBSUB_FOLDER_" + l;
- mailboxPath = new MailboxPath("#private", user,
subSubfolderName);
- createMailbox(mailboxSession, mailboxPath);
-
- }
-
- }
-
- getMailboxManager().logout(mailboxSession, true);
-
- }
-
- }
-
- }
-
- /**
- *
- * @param mailboxPath
- * @throws MailboxException
- * @throws UnsupportedEncodingException
- */
- private void createMailbox(MailboxSession mailboxSession, MailboxPath
mailboxPath) throws MailboxException, UnsupportedEncodingException {
- getMailboxManager().startProcessingRequest(mailboxSession);
- getMailboxManager().createMailbox(mailboxPath, mailboxSession);
- MessageManager messageManager =
getMailboxManager().getMailbox(mailboxPath, mailboxSession);
- for (int j=0; j < MESSAGE_PER_MAILBOX_COUNT; j++) {
- messageManager.appendMessage(new
ByteArrayInputStream(MockMail.MAIL_TEXT_PLAIN.getBytes("UTF-8")),
- Calendar.getInstance().getTime(),
- mailboxSession,
- true,
- new Flags(Flags.Flag.RECENT));
- }
- getMailboxManager().endProcessingRequest(mailboxSession);
- }
-
- /**
* Implement this method to create the mailboxManager.
*
* @return
Added:
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxManager.java
URL:
http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxManager.java?rev=1054614&view=auto
==============================================================================
---
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxManager.java
(added)
+++
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxManager.java
Mon Jan 3 13:44:16 2011
@@ -0,0 +1,165 @@
+/****************************************************************
+ * 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.mock;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Calendar;
+
+import javax.mail.Flags;
+
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.james.mailbox.MailboxException;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxPath;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+
+/**
+ * A mock mailbox manager.
+ *
+ */
+public class MockMailboxManager {
+
+ /**
+ * The mock mailbox manager constructed based on a provided mailboxmanager.
+ */
+ private MailboxManager mockMailboxManager;
+
+ /**
+ * Number of Domains to be created in the Mailbox Manager.
+ */
+ public static final int DOMAIN_COUNT = 3;
+
+ /**
+ * Number of Users (with INBOX) to be created in the Mailbox Manager.
+ */
+ public static final int USER_COUNT = 3;
+
+ /**
+ * Number of Sub Mailboxes (mailbox in INBOX) to be created in the Mailbox
Manager.
+ */
+ public static final int SUB_MAILBOXES_COUNT = 3;
+
+ /**
+ * Number of Sub Sub Mailboxes (mailbox in a mailbox under INBOX) to be
created in the Mailbox Manager.
+ */
+ public static final int SUB_SUB_MAILBOXES_COUNT = 3;
+
+ /**
+ * The expected Mailboxes count calculated based on the feeded mails.
+ */
+ public static final int EXPECTED_MAILBOXES_COUNT = DOMAIN_COUNT *
+ (USER_COUNT + // INBOX
+ USER_COUNT * SUB_MAILBOXES_COUNT + // INBOX.SUB_FOLDER
+ USER_COUNT * SUB_MAILBOXES_COUNT *
SUB_SUB_MAILBOXES_COUNT); // INBOX.SUB_FOLDER.SUBSUB_FOLDER
+
+ /**
+ * Number of Messages per Mailbox to be created in the Mailbox Manager.
+ */
+ public static final int MESSAGE_PER_MAILBOX_COUNT = 3;
+
+ /**
+ * Construct a mock mailboxManager based on a valid mailboxManager.
+ * The mailboxManager will be feeded with mailboxes and mails.
+ *
+ * @param mailboxManager
+ * @throws UnsupportedEncodingException
+ * @throws MailboxException
+ */
+ public MockMailboxManager(MailboxManager mailboxManager) throws
MailboxException, UnsupportedEncodingException {
+ this.mockMailboxManager = mailboxManager;
+ feedMockMailboxManager();
+ }
+
+ /**
+ * @return
+ */
+ public MailboxManager getMockMailboxManager() {
+ return mockMailboxManager;
+ }
+
+ /**
+ * Utility method to feed the Mailbox Manager with a number of
+ * mailboxes and messages per mailbox.
+ *
+ * @throws MailboxException
+ * @throws UnsupportedEncodingException
+ */
+ private void feedMockMailboxManager() throws MailboxException,
UnsupportedEncodingException {
+
+ MailboxPath mailboxPath = null;
+
+ for (int i=0; i < DOMAIN_COUNT; i++) {
+
+ for (int j=0; j < USER_COUNT; j++) {
+
+ String user = "user" + j + "@localhost" + i;
+
+ String folderName = "INBOX";
+
+ MailboxSession mailboxSession =
getMockMailboxManager().createSystemSession(user, new
SimpleLog("mailboxmanager-test"));
+ mailboxPath = new MailboxPath("#private", user, folderName);
+ createMailbox(mailboxSession, mailboxPath);
+
+ for (int k=0; k < SUB_MAILBOXES_COUNT; k++) {
+
+ String subFolderName = folderName + ".SUB_FOLDER_" + k;
+ mailboxPath = new MailboxPath("#private", user,
subFolderName);
+ createMailbox(mailboxSession, mailboxPath);
+
+ for (int l=0; l < SUB_SUB_MAILBOXES_COUNT; l++) {
+
+ String subSubfolderName = subFolderName +
".SUBSUB_FOLDER_" + l;
+ mailboxPath = new MailboxPath("#private", user,
subSubfolderName);
+ createMailbox(mailboxSession, mailboxPath);
+
+ }
+
+ }
+
+ getMockMailboxManager().logout(mailboxSession, true);
+
+ }
+
+ }
+
+ }
+
+ /**
+ *
+ * @param mailboxPath
+ * @throws MailboxException
+ * @throws UnsupportedEncodingException
+ */
+ private void createMailbox(MailboxSession mailboxSession, MailboxPath
mailboxPath) throws MailboxException, UnsupportedEncodingException {
+ getMockMailboxManager().startProcessingRequest(mailboxSession);
+ getMockMailboxManager().createMailbox(mailboxPath, mailboxSession);
+ MessageManager messageManager =
getMockMailboxManager().getMailbox(mailboxPath, mailboxSession);
+ for (int j=0; j < MESSAGE_PER_MAILBOX_COUNT; j++) {
+ messageManager.appendMessage(new
ByteArrayInputStream(MockMail.MAIL_TEXT_PLAIN.getBytes("UTF-8")),
+ Calendar.getInstance().getTime(),
+ mailboxSession,
+ true,
+ new Flags(Flags.Flag.RECENT));
+ }
+ getMockMailboxManager().endProcessingRequest(mailboxSession);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]