You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2015/09/22 12:23:41 UTC
svn commit: r1704538 - in
/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager: ./
IntegrationResources.java ManagerTestResources.java
QuotaMessageManagerTest.java
Author: btellier
Date: Tue Sep 22 10:23:38 2015
New Revision: 1704538
URL: http://svn.apache.org/viewvc?rev=1704538&view=rev
Log:
MAILBOX-64 Quota integration API and default tests
Added:
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/IntegrationResources.java
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/ManagerTestResources.java
james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/QuotaMessageManagerTest.java
Added: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/IntegrationResources.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/IntegrationResources.java?rev=1704538&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/IntegrationResources.java (added)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/IntegrationResources.java Tue Sep 22 10:23:38 2015
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.manager;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.acl.GroupMembershipResolver;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+
+/**
+ * Provides empty resources for integration tests.
+ */
+public interface IntegrationResources {
+
+ MailboxManager createMailboxManager(GroupMembershipResolver groupMembershipResolver) throws MailboxException;
+
+ QuotaManager createQuotaManager(MaxQuotaManager maxQuotaManager, MailboxManager mailboxManager) throws Exception;
+
+ MaxQuotaManager createMaxQuotaManager() throws Exception;
+
+ QuotaRootResolver createQuotaRootResolver(MailboxManager mailboxManager) throws Exception;
+
+ GroupMembershipResolver createGroupMembershipResolver() throws Exception;
+
+ /**
+ * Init you will want to perform before tests
+ *
+ * @throws Exception
+ */
+ void init() throws Exception;
+
+ void clean() throws Exception;
+
+}
\ No newline at end of file
Added: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/ManagerTestResources.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/ManagerTestResources.java?rev=1704538&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/ManagerTestResources.java (added)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/ManagerTestResources.java Tue Sep 22 10:23:38 2015
@@ -0,0 +1,146 @@
+/****************************************************************
+ * 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.manager;
+
+import org.apache.james.mailbox.FlagsBuilder;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.acl.GroupMembershipResolver;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.mock.MockMail;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.mail.Flags;
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Calendar;
+
+/**
+ * Provide an initialized Mailbox environment where we can run managers tests
+ */
+public class ManagerTestResources {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ManagerTestResources.class);
+
+ public static final String USER = "user@domain.org";
+ public static final String USER_PASS = "pass";
+
+ private MailboxManager mailboxManager;
+
+ private MailboxPath inbox;
+ private MessageManager messageManager;
+ private MailboxPath subFolder;
+
+ private MailboxSession session;
+
+ private MaxQuotaManager maxQuotaManager;
+ private QuotaManager quotaManager;
+ private GroupMembershipResolver groupMembershipResolver;
+ private QuotaRootResolver quotaRootResolver;
+
+ private IntegrationResources integrationResources;
+
+ public ManagerTestResources(IntegrationResources integrationResources) throws Exception {
+ this.integrationResources = integrationResources;
+ maxQuotaManager = integrationResources.createMaxQuotaManager();
+ groupMembershipResolver = integrationResources.createGroupMembershipResolver();
+ mailboxManager = integrationResources.createMailboxManager(groupMembershipResolver);
+ quotaRootResolver = integrationResources.createQuotaRootResolver(mailboxManager);
+ quotaManager = integrationResources.createQuotaManager(maxQuotaManager, mailboxManager);
+ integrationResources.init();
+ session = mailboxManager.login(USER, USER_PASS, LOG);
+ inbox = MailboxPath.inbox(session);
+ subFolder = new MailboxPath(inbox, "INBOX.SUB");
+
+ maxQuotaManager.setDefaultMaxMessage(1000);
+ maxQuotaManager.setDefaultMaxStorage(1000000);
+ }
+
+ public void createMailboxes() throws MailboxException {
+ mailboxManager.createMailbox(inbox, session);
+ mailboxManager.createMailbox(subFolder, session);
+ messageManager = mailboxManager.getMailbox(inbox, session);
+ }
+
+ public GroupMembershipResolver getGroupMembershipResolver() {
+ return groupMembershipResolver;
+ }
+
+ public QuotaManager getQuotaManager() {
+ return quotaManager;
+ }
+
+ public MaxQuotaManager getMaxQuotaManager() {
+ return maxQuotaManager;
+ }
+
+ public QuotaRootResolver getQuotaRootResolver() {
+ return quotaRootResolver;
+ }
+
+ public MessageManager getMessageManager() {
+ return messageManager;
+ }
+
+ public MailboxPath getSubFolder() {
+ return subFolder;
+ }
+
+ public MailboxPath getInbox() {
+ return inbox;
+ }
+
+ public MailboxManager getMailboxManager() {
+ return mailboxManager;
+ }
+
+ public MailboxSession getSession() {
+ return session;
+ }
+
+ public IntegrationResources getIntegrationResources() {
+ return integrationResources;
+ }
+
+ public void fillMailbox() throws MailboxException, UnsupportedEncodingException {
+ for(int i = 0; i < 4; i++) {
+ provideSomeMessages();
+ }
+ }
+
+ private void provideSomeMessages() throws MailboxException, UnsupportedEncodingException {
+ appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.SEEN).build());
+ appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.DELETED).build());
+ appendMessage(messageManager, session, new FlagsBuilder().build());
+ appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.RECENT).build());
+ }
+
+ public long appendMessage(MessageManager messageManager, MailboxSession session, Flags flags) throws MailboxException, UnsupportedEncodingException {
+ return messageManager.appendMessage(new ByteArrayInputStream(MockMail.MAIL_TEXT_PLAIN.getBytes("UTF-8")),
+ Calendar.getInstance().getTime(), session, true, flags);
+ }
+
+}
\ No newline at end of file
Added: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/QuotaMessageManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/QuotaMessageManagerTest.java?rev=1704538&view=auto
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/QuotaMessageManagerTest.java (added)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/manager/QuotaMessageManagerTest.java Tue Sep 22 10:23:38 2015
@@ -0,0 +1,139 @@
+/****************************************************************
+ * 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.manager;
+
+import org.apache.james.mailbox.FlagsBuilder;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.quota.MaxQuotaManager;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.exception.OverQuotaException;
+import org.apache.james.mailbox.mock.MockMail;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.mail.Flags;
+
+/**
+ * Test for quota support upon basic Message manager operation.
+ *
+ * Tests are performed with sufficient rights to ensure all underlying functions behave well.
+ * Quota are adjusted and we check that exceptions are well thrown.
+ */
+public abstract class QuotaMessageManagerTest {
+
+ private ManagerTestResources resources;
+
+ private MessageManager messageManager;
+ private MailboxManager mailboxManager;
+ private MaxQuotaManager maxQuotaManager;
+ private QuotaRootResolver quotaRootResolver;
+
+ private MailboxSession session;
+ private MailboxPath inbox;
+ private MailboxPath subFolder;
+
+ protected abstract ManagerTestResources createResources() throws Exception;
+
+ @Before
+ public void setUp() throws Exception {
+ resources = createResources();
+ resources.createMailboxes();
+ messageManager = resources.getMessageManager();
+ mailboxManager = resources.getMailboxManager();
+ session = resources.getSession();
+ inbox = resources.getInbox();
+ subFolder = resources.getSubFolder();
+ maxQuotaManager = resources.getMaxQuotaManager();
+ quotaRootResolver = resources.getQuotaRootResolver();
+ }
+
+ @After
+ public void cleanUp() throws Exception {
+ resources.getIntegrationResources().clean();
+ }
+
+ @Test(expected = OverQuotaException.class)
+ public void testAppendOverQuotaMessages() throws Exception {
+ maxQuotaManager.setMaxMessage(quotaRootResolver.getQuotaRoot(inbox), 8l);
+ resources.fillMailbox();
+ }
+
+ @Test(expected = OverQuotaException.class)
+ public void testAppendOverQuotaSize() throws Exception {
+ maxQuotaManager.setMaxStorage(quotaRootResolver.getQuotaRoot(inbox), 3 * MockMail.MAIL_TEXT_PLAIN.length() + 1);
+ resources.fillMailbox();
+ }
+
+ @Test(expected = OverQuotaException.class)
+ public void testCopyOverQuotaMessages() throws Exception {
+ try {
+ resources.fillMailbox();
+ } catch(OverQuotaException overQuotaException) {
+ // Silent these exception as we don't want it to disturb the test
+ }
+ maxQuotaManager.setMaxMessage(quotaRootResolver.getQuotaRoot(inbox), 20l);
+ mailboxManager.copyMessages(MessageRange.all(), inbox, subFolder, session);
+ }
+
+ @Test(expected = OverQuotaException.class)
+ public void testCopyOverQuotaSize() throws Exception {
+ maxQuotaManager.setMaxStorage(quotaRootResolver.getQuotaRoot(inbox), 20l * MockMail.MAIL_TEXT_PLAIN.length());
+ try {
+ resources.fillMailbox();
+ } catch(OverQuotaException overQuotaException) {
+ // Silent these exception as we don't want it to disturb the test
+ }
+ mailboxManager.copyMessages(MessageRange.all(), inbox, subFolder, session);
+ }
+
+ @Test
+ public void testRetrievalOverMaxMessage() throws Exception {
+ maxQuotaManager.setMaxMessage(quotaRootResolver.getQuotaRoot(inbox), 8l);
+ try {
+ resources.fillMailbox();
+ } catch(OverQuotaException overQuotaException) {
+ // We are here over quota
+ }
+ messageManager.expunge(MessageRange.all(), session);
+ // We have suppressed at list one message. Ensure we can add an other message. If is impossible, an exception will be thrown.
+ resources.appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.SEEN).build());
+ }
+
+ @Test
+ public void testRetrievalOverMaxStorage() throws Exception {
+ maxQuotaManager.setMaxStorage(quotaRootResolver.getQuotaRoot(inbox), 8 * MockMail.MAIL_TEXT_PLAIN.length() + 1);
+ try {
+ resources.fillMailbox();
+ } catch(OverQuotaException overQuotaException) {
+ // We are here over quota
+ }
+ messageManager.expunge(MessageRange.all(), session);
+ // We have suppressed at list one message. Ensure we can add an other message. If is impossible, an exception will be thrown.
+ resources.appendMessage(messageManager, session, new FlagsBuilder().add(Flags.Flag.SEEN).build());
+ }
+
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org