Author: eric
Date: Mon Dec 20 16:53:46 2010
New Revision: 1051205
URL: http://svn.apache.org/viewvc?rev=1051205&view=rev
Log:
StoreMailboxManagerTest to test extra APIs not covered by functional tests
(list,...) + Implementation for JPA.
Added:
james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
Modified:
james/mailbox/trunk/jpa/pom.xml
Modified: james/mailbox/trunk/jpa/pom.xml
URL:
http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/pom.xml?rev=1051205&r1=1051204&r2=1051205&view=diff
==============================================================================
--- james/mailbox/trunk/jpa/pom.xml (original)
+++ james/mailbox/trunk/jpa/pom.xml Mon Dec 20 16:53:46 2010
@@ -57,6 +57,12 @@
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
+ <artifactId>apache-james-mailbox-store</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
<artifactId>apache-james-imap-protocol-tester</artifactId>
<scope>test</scope>
</dependency>
Added:
james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
URL:
http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java?rev=1051205&view=auto
==============================================================================
---
james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
(added)
+++
james/mailbox/trunk/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxManagerTest.java
Mon Dec 20 16:53:46 2010
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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.EntityManagerFactory;
+
+import org.apache.james.mailbox.jpa.mail.JPACachingUidProvider;
+import org.apache.james.mailbox.jpa.mail.model.JPAHeader;
+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.openjpa.AbstractJPAMailboxMembership;
+import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMessage;
+import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMembership;
+import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMessage;
+import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
+import org.apache.james.mailbox.jpa.user.model.JPASubscription;
+import org.apache.james.mailbox.store.StoreMailboxManagerTest;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.junit.BeforeClass;
+
+/**
+ * JPAMailboxManagerTest that extends the StoreMailboxManagerTest.
+ */
+public class JPAMailboxManagerTest extends StoreMailboxManagerTest {
+
+ /**
+ * The entity manager factory.
+ */
+ private static EntityManagerFactory entityManagerFactory;
+
+ /**
+ * Setup the mailboxManager.
+ *
+ * @throws Exception
+ */
+ @BeforeClass
+ public static void setup() throws Exception {
+
+ 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=" +
+ JPAHeader.class.getName() + ";" +
+ JPAMailbox.class.getName() + ";" +
+ AbstractJPAMailboxMembership.class.getName() + ";" +
+ JPAMailboxMembership.class.getName() + ";" +
+ AbstractJPAMessage.class.getName() + ";" +
+ JPAMessage.class.getName() + ";" +
+ JPAProperty.class.getName() + ";" +
+ JPASubscription.class.getName() + ")");
+
+ entityManagerFactory =
OpenJPAPersistence.getEntityManagerFactory(properties);
+ JPACachingUidProvider uidProvider = new
JPACachingUidProvider(entityManagerFactory);
+ JPAMailboxSessionMapperFactory mf = new
JPAMailboxSessionMapperFactory(entityManagerFactory);
+
+ setMailboxManager(new OpenJPAMailboxManager(mf, null, uidProvider));
+
+ }
+
+}
Added:
james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
URL:
http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java?rev=1051205&view=auto
==============================================================================
---
james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
(added)
+++
james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
Mon Dec 20 16:53:46 2010
@@ -0,0 +1,130 @@
+/****************************************************************
+ * 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.store;
+
+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.junit.Test;
+
+/**
+ * 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 StoreMailboxManagerTest {
+
+ /**
+ * The mailboxManager that needs to get instanciated
+ * by the mailbox implementations.
+ */
+ private static MailboxManager mailboxManager;
+
+ /**
+ * Number of Mailboxes to be created in the Mailbox Manager.
+ */
+ private static final int MAILBOX_COUNT = 10;
+
+ /**
+ * Number of Messages per Mailbox to be created in the Mailbox Manager.
+ */
+ private static final int MESSAGE_PER_MAILBOX_COUNT = 10;
+
+ /**
+ * @throws UnsupportedEncodingException
+ * @throws MailboxException
+ */
+ @Test
+ public void testList() throws MailboxException,
UnsupportedEncodingException {
+
+ feedMailboxManager();
+
+ MailboxSession mailboxSession =
getMailboxManager().createSystemSession("manager", new SimpleLog("testList"));
+ getMailboxManager().startProcessingRequest(mailboxSession);
+ Assert.assertEquals(getMailboxManager().list(mailboxSession).size(),
MAILBOX_COUNT);
+
+ }
+
+ /**
+ * 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 {
+
+ MessageManager messageManager = null;
+ MailboxPath mailboxPath = null;
+
+ for (int i=0; i < MAILBOX_COUNT; i++) {
+
+ MailboxSession mailboxSession =
getMailboxManager().createSystemSession("user" + i, new
SimpleLog("testList-feeder"));
+
+ getMailboxManager().startProcessingRequest(mailboxSession);
+ mailboxPath = new MailboxPath("#private", "user" + i, "INBOX");
+ getMailboxManager().createMailbox(mailboxPath, mailboxSession);
+ messageManager = getMailboxManager().getMailbox(mailboxPath,
mailboxSession);
+ for (int j=0; j < MESSAGE_PER_MAILBOX_COUNT; j++) {
+ messageManager.appendMessage(new ByteArrayInputStream(new
String("fake message" + i).getBytes("UTF-8")),
+ Calendar.getInstance().getTime(),
+ mailboxSession,
+ true,
+ new Flags(Flags.Flag.RECENT));
+ }
+
+ getMailboxManager().endProcessingRequest(mailboxSession);
+ getMailboxManager().logout(mailboxSession, true);
+
+ }
+
+ }
+
+ /**
+ * Setter to inject the MailboxManager.
+ */
+ protected static void setMailboxManager(MailboxManager mailboxManager) {
+ StoreMailboxManagerTest.mailboxManager = mailboxManager;
+ }
+
+ /**
+ * Accessor to the MailboxManager.
+ *
+ * @return the mailboxManager instance.
+ */
+ protected static MailboxManager getMailboxManager() {
+ return mailboxManager;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]