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:40:07 UTC

svn commit: r1704565 - in /james/protocols/trunk/imap/src: main/java/org/apache/james/imap/processor/ test/java/org/apache/james/imap/processor/

Author: btellier
Date: Tue Sep 22 10:40:05 2015
New Revision: 1704565

URL: http://svn.apache.org/viewvc?rev=1704565&view=rev
Log:
PROTOCOLS-108 Adding IMAP processors for QUOTAs

Added:
    james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
    james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
    james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java
    james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
    james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
    james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java

Added: james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java?rev=1704565&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java (added)
+++ james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java Tue Sep 22 10:40:05 2015
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.response.StatusResponseFactory;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.request.GetQuotaRequest;
+import org.apache.james.imap.message.response.QuotaResponse;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * GETQUOTA processor
+ */
+public class GetQuotaProcessor extends AbstractMailboxProcessor<GetQuotaRequest> implements CapabilityImplementingProcessor {
+
+    private static final List<String> CAPABILITIES = Collections.singletonList(ImapConstants.SUPPORTS_QUOTA);
+
+    private final QuotaManager quotaManager;
+    private final QuotaRootResolver quotaRootResolver;
+
+    public GetQuotaProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) {
+        super(GetQuotaRequest.class, next, mailboxManager, factory);
+        this.quotaManager = quotaManager;
+        this.quotaRootResolver = quotaRootResolver;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.james.imap.processor.CapabilityImplementingProcessor#
+     * getImplementedCapabilities(org.apache.james.imap.api.process.ImapSession)
+     */
+    public List<String> getImplementedCapabilities(ImapSession session) {
+        return CAPABILITIES;
+    }
+
+    @Override
+    protected void doProcess(GetQuotaRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) {
+        try {
+            if(hasRight(message.getQuotaRoot(), session)) {
+                QuotaRoot quotaRoot = quotaRootResolver.createQuotaRoot(message.getQuotaRoot());
+                Quota messageQuota = quotaManager.getMessageQuota(quotaRoot);
+                Quota storageQuota = quotaManager.getStorageQuota(quotaRoot);
+                responder.respond(new QuotaResponse(ImapConstants.MESSAGE_QUOTA_RESOURCE, quotaRoot.getValue(), messageQuota));
+                responder.respond(new QuotaResponse(ImapConstants.STORAGE_QUOTA_RESOURCE, quotaRoot.getValue(), storageQuota));
+                okComplete(command, tag, responder);
+            } else {
+                Object[] params = new Object[]{
+                        SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT.toString(),
+                        command.getName(),
+                        "Any mailbox of this user USER"
+                };
+                HumanReadableText humanReadableText = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
+                no(command, tag, responder, humanReadableText);
+            }
+        } catch(MailboxException me) {
+            taggedBad(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX);
+        }
+    }
+
+    private boolean hasRight(String quotaRoot, ImapSession session) throws MailboxException {
+        // If any of the mailboxes owned by quotaRoot user can be read by the current user, then we should respond to him.
+        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        List<MailboxPath> mailboxList = quotaRootResolver.retrieveAssociatedMailboxes(quotaRootResolver.createQuotaRoot(quotaRoot), mailboxSession);
+        for(MailboxPath mailboxPath : mailboxList) {
+            if(getMailboxManager().hasRight(mailboxPath, SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT, mailboxSession)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Added: james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java?rev=1704565&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java (added)
+++ james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java Tue Sep 22 10:40:05 2015
@@ -0,0 +1,96 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.response.StatusResponseFactory;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.request.GetQuotaRootRequest;
+import org.apache.james.imap.message.response.QuotaRootResponse;
+import org.apache.james.imap.message.response.QuotaResponse;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * GETQUOTAROOT Processor
+ */
+public class GetQuotaRootProcessor extends AbstractMailboxProcessor<GetQuotaRootRequest> implements CapabilityImplementingProcessor {
+
+    private static final List<String> CAPABILITIES = Collections.singletonList(ImapConstants.SUPPORTS_QUOTA);
+    private final QuotaRootResolver quotaRootResolver;
+    private final QuotaManager quotaManager;
+
+    public GetQuotaRootProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory, QuotaRootResolver quotaRootResolver, QuotaManager quotaManager) {
+        super(GetQuotaRootRequest.class, next, mailboxManager, factory);
+        this.quotaRootResolver = quotaRootResolver;
+        this.quotaManager = quotaManager;
+    }
+
+    public List<String> getImplementedCapabilities(ImapSession session) {
+        return CAPABILITIES;
+    }
+
+    @Override
+    protected void doProcess(GetQuotaRootRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) {
+        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxManager mailboxManager = getMailboxManager();
+
+        final MailboxPath mailboxPath = buildFullPath(session, message.getMailboxName());
+
+        // First check mailbox exists
+        try {
+            if (mailboxManager.hasRight(mailboxPath, SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT, mailboxSession)) {
+                QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
+                Quota messageQuota = quotaManager.getMessageQuota(quotaRoot);
+                // See RFC 2087 : response for STORAGE should be in KB. For more accuracy, we stores B, so conversion should be made
+                Quota storageQuota = quotaManager.getStorageQuota(quotaRoot);
+                responder.respond(new QuotaRootResponse(message.getMailboxName(), quotaRoot.getValue()));
+                responder.respond(new QuotaResponse(ImapConstants.MESSAGE_QUOTA_RESOURCE, quotaRoot.getValue(), messageQuota));
+                responder.respond(new QuotaResponse(ImapConstants.STORAGE_QUOTA_RESOURCE, quotaRoot.getValue(), storageQuota));
+                okComplete(command, tag, responder);
+            } else {
+                Object[] params = new Object[]{
+                        SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT.toString(),
+                        command.getName(),
+                        message.getMailboxName()
+                };
+                HumanReadableText humanReadableText = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
+                no(command, tag, responder, humanReadableText);
+            }
+        } catch(MailboxException me) {
+            taggedBad(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX);
+        }
+
+    }
+}

Added: james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java?rev=1704565&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java (added)
+++ james/protocols/trunk/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java Tue Sep 22 10:40:05 2015
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.response.StatusResponseFactory;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.request.SetQuotaRequest;
+import org.apache.james.mailbox.MailboxManager;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * SETQUOTA processor
+ */
+public class SetQuotaProcessor extends AbstractMailboxProcessor<SetQuotaRequest> implements CapabilityImplementingProcessor {
+    private static final List<String> CAPABILITIES = Collections.singletonList(ImapConstants.SUPPORTS_QUOTA);
+
+    public List<String> getImplementedCapabilities(ImapSession session) {
+        return CAPABILITIES;
+    }
+
+    public SetQuotaProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory) {
+        super(SetQuotaRequest.class, next, mailboxManager, factory);
+    }
+
+    @Override
+    protected void doProcess(SetQuotaRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) {
+        Object[] params = new Object[]{
+            "Full admin rights",
+            command.getName(),
+            "Can not perform SETQUOTA commands"
+        };
+        HumanReadableText humanReadableText = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
+        no(command, tag, responder, humanReadableText);
+    }
+}

Added: james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java?rev=1704565&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java (added)
+++ james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java Tue Sep 22 10:40:05 2015
@@ -0,0 +1,205 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import com.google.common.collect.Lists;
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapSessionState;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.message.response.StatusResponse;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.request.GetQuotaRequest;
+import org.apache.james.imap.message.response.QuotaResponse;
+import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.quota.QuotaImpl;
+import org.apache.james.mailbox.store.quota.QuotaRootImpl;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(JMock.class)
+public class GetQuotaProcessorTest {
+
+    private static final QuotaRoot QUOTA_ROOT = QuotaRootImpl.quotaRoot("plop");
+    public static final MailboxPath MAILBOX_PATH = new MailboxPath("namespace", "plop", "INBOX");
+    public static final Quota MESSAGE_QUOTA = QuotaImpl.quota(24, 1589);
+    public static final Quota STORAGE_QUOTA = QuotaImpl.quota(240, 15890);
+
+    private GetQuotaProcessor testee;
+    private Mockery mockery;
+    private ImapSession mockedImapSession;
+    private ImapProcessor.Responder mockedResponder;
+    private QuotaManager mockedQuotaManager;
+    private QuotaRootResolver mockedQuotaRootResolver;
+    private MailboxManager mockedMailboxManager;
+    private MailboxSession mailboxSession;
+
+    @Before
+    public void setUp() {
+        mailboxSession = new MockMailboxSession("plop");
+        mockery = new JUnit4Mockery();
+        UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
+        mockedImapSession = mockery.mock(ImapSession.class);
+        mockedQuotaManager = mockery.mock(QuotaManager.class);
+        mockedQuotaRootResolver = mockery.mock(QuotaRootResolver.class);
+        mockedResponder = mockery.mock(ImapProcessor.Responder.class);
+        mockedMailboxManager = mockery.mock(MailboxManager.class);
+        testee = new GetQuotaProcessor(mockery.mock(ImapProcessor.class), mockedMailboxManager,
+            statusResponseFactory, mockedQuotaManager, mockedQuotaRootResolver);
+    }
+
+    @Test
+    public void processorShouldWorkOnValidRights() throws Exception {
+        GetQuotaRequest getQuotaRequest = new GetQuotaRequest("A004", ImapCommand.anyStateCommand("Name"), "quotaRoot");
+        Expectations expectations = new Expectations();
+
+        expectations.allowing(mockedImapSession).getState();
+        expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+
+        expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
+        expectations.will(Expectations.returnValue(mailboxSession));
+
+        expectations.allowing(mockedQuotaRootResolver).createQuotaRoot(expectations.with("quotaRoot"));
+        expectations.will(Expectations.returnValue(QUOTA_ROOT));
+
+        expectations.allowing(mockedQuotaRootResolver).retrieveAssociatedMailboxes(expectations.with(QUOTA_ROOT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(Lists.newArrayList(MAILBOX_PATH)));
+
+        expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
+            expectations.with(SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(true));
+
+        expectations.allowing(mockedQuotaManager).getMessageQuota(expectations.with(QUOTA_ROOT));
+        expectations.will(Expectations.returnValue(MESSAGE_QUOTA));
+
+        expectations.allowing(mockedQuotaManager).getStorageQuota(expectations.with(QUOTA_ROOT));
+        expectations.will(Expectations.returnValue(STORAGE_QUOTA));
+
+        expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+
+        final QuotaResponse storageQuotaResponse = new QuotaResponse("STORAGE", "plop", STORAGE_QUOTA);
+        final QuotaResponse messageQuotaResponse = new QuotaResponse("MESSAGE", "plop", MESSAGE_QUOTA);
+
+        mockery.checking(expectations);
+
+        mockery.checking(new Expectations() {
+            {
+                oneOf(mockedResponder).respond(with(equal(storageQuotaResponse)));
+                oneOf(mockedResponder).respond(with(equal(messageQuotaResponse)));
+                oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.OK)));
+            }
+        });
+
+        testee.doProcess(getQuotaRequest, mockedResponder, mockedImapSession);
+    }
+
+    @Test
+    public void processorShouldWorkOnExceptionThrown() throws Exception {
+        GetQuotaRequest getQuotaRequest = new GetQuotaRequest("A004", ImapCommand.anyStateCommand("Name"), "quotaRoot");
+        Expectations expectations = new Expectations();
+
+        expectations.allowing(mockedImapSession).getState();
+        expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+
+        expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
+        expectations.will(Expectations.returnValue(mailboxSession));
+
+        expectations.allowing(mockedQuotaRootResolver).createQuotaRoot(expectations.with("quotaRoot"));
+        expectations.will(Expectations.returnValue(QUOTA_ROOT));
+
+        expectations.allowing(mockedQuotaRootResolver).retrieveAssociatedMailboxes(expectations.with(QUOTA_ROOT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(Lists.newArrayList(MAILBOX_PATH)));
+
+        expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
+            expectations.with(SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(true));
+
+        expectations.allowing(mockedQuotaManager).getMessageQuota(expectations.with(QUOTA_ROOT));
+        expectations.will(Expectations.throwException(new MailboxException()));
+
+        expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+
+        mockery.checking(expectations);
+
+        mockery.checking(new Expectations() {
+            {
+                oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.BAD)));
+            }
+        });
+
+        testee.doProcess(getQuotaRequest, mockedResponder, mockedImapSession);
+    }
+
+    @Test
+    public void processorShouldWorkOnNoRights() throws Exception {
+        GetQuotaRequest getQuotaRequest = new GetQuotaRequest("A004", ImapCommand.anyStateCommand("Name"), "quotaRoot");
+        Expectations expectations = new Expectations();
+
+        expectations.allowing(mockedImapSession).getState();
+        expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+
+        expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
+        expectations.will(Expectations.returnValue(mailboxSession));
+
+        expectations.allowing(mockedQuotaRootResolver).createQuotaRoot(expectations.with("quotaRoot"));
+        expectations.will(Expectations.returnValue(QUOTA_ROOT));
+
+        expectations.allowing(mockedQuotaRootResolver).retrieveAssociatedMailboxes(expectations.with(QUOTA_ROOT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(Lists.newArrayList(MAILBOX_PATH)));
+
+        expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
+            expectations.with(SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(false));
+
+        expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+
+        mockery.checking(expectations);
+
+        mockery.checking(new Expectations() {
+            {
+                oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.NO)));
+            }
+        });
+
+        testee.doProcess(getQuotaRequest, mockedResponder, mockedImapSession);
+    }
+
+}

Added: james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java?rev=1704565&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java (added)
+++ james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java Tue Sep 22 10:40:05 2015
@@ -0,0 +1,187 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapSessionState;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.message.response.StatusResponse;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.request.GetQuotaRootRequest;
+import org.apache.james.imap.message.response.QuotaResponse;
+import org.apache.james.imap.message.response.QuotaRootResponse;
+import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.Quota;
+import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
+import org.apache.james.mailbox.store.quota.QuotaImpl;
+import org.apache.james.mailbox.store.quota.QuotaRootImpl;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GetQuotaRootProcessorTest {
+
+    private static final QuotaRoot QUOTA_ROOT = QuotaRootImpl.quotaRoot("plop");
+    public static final MailboxPath MAILBOX_PATH = new MailboxPath("#private", "plop", "INBOX");
+    public static final Quota MESSAGE_QUOTA = QuotaImpl.quota(24, 1589);
+    public static final Quota STORAGE_QUOTA = QuotaImpl.quota(240, 15890);
+
+    private GetQuotaRootProcessor testee;
+    private Mockery mockery;
+    private ImapSession mockedImapSession;
+    private ImapProcessor.Responder mockedResponder;
+    private QuotaManager mockedQuotaManager;
+    private QuotaRootResolver mockedQuotaRootResolver;
+    private MailboxManager mockedMailboxManager;
+    private MailboxSession mailboxSession;
+
+    @Before
+    public void setUp() {
+        mailboxSession = new MockMailboxSession("plop");
+        mockery = new JUnit4Mockery();
+        UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
+        mockedImapSession = mockery.mock(ImapSession.class);
+        mockedQuotaManager = mockery.mock(QuotaManager.class);
+        mockedQuotaRootResolver = mockery.mock(QuotaRootResolver.class);
+        mockedResponder = mockery.mock(ImapProcessor.Responder.class);
+        mockedMailboxManager = mockery.mock(MailboxManager.class);
+        testee = new GetQuotaRootProcessor(mockery.mock(ImapProcessor.class), mockedMailboxManager,
+            statusResponseFactory, mockedQuotaRootResolver, mockedQuotaManager);
+    }
+
+    @Test
+    public void processorShouldWorkOnValidRights() throws Exception {
+        GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest("A004", ImapCommand.anyStateCommand("Name"), "INBOX");
+        Expectations expectations = new Expectations();
+
+        expectations.allowing(mockedImapSession).getState();
+        expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+
+        expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
+        expectations.will(Expectations.returnValue(mailboxSession));
+
+        expectations.allowing(mockedQuotaRootResolver).getQuotaRoot(expectations.with(MAILBOX_PATH));
+        expectations.will(Expectations.returnValue(QUOTA_ROOT));
+
+        expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
+            expectations.with(SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(true));
+
+        expectations.allowing(mockedQuotaManager).getMessageQuota(expectations.with(QUOTA_ROOT));
+        expectations.will(Expectations.returnValue(MESSAGE_QUOTA));
+
+        expectations.allowing(mockedQuotaManager).getStorageQuota(expectations.with(QUOTA_ROOT));
+        expectations.will(Expectations.returnValue(STORAGE_QUOTA));
+
+        expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+
+        final QuotaResponse storageQuotaResponse = new QuotaResponse("STORAGE", "plop", STORAGE_QUOTA);
+        final QuotaResponse messageQuotaResponse = new QuotaResponse("MESSAGE", "plop", MESSAGE_QUOTA);
+        final QuotaRootResponse quotaRootResponse = new QuotaRootResponse("INBOX", "plop");
+
+        mockery.checking(expectations);
+
+        mockery.checking(new Expectations() {
+            {
+                oneOf(mockedResponder).respond(with(equal(quotaRootResponse)));
+                oneOf(mockedResponder).respond(with(equal(storageQuotaResponse)));
+                oneOf(mockedResponder).respond(with(equal(messageQuotaResponse)));
+                oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.OK)));
+            }
+        });
+
+        testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+    }
+
+    @Test
+    public void processorShouldWorkOnErrorThrown() throws Exception {
+        GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest("A004", ImapCommand.anyStateCommand("Name"), "INBOX");
+        Expectations expectations = new Expectations();
+
+        expectations.allowing(mockedImapSession).getState();
+        expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+
+        expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
+        expectations.will(Expectations.returnValue(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
+            expectations.with(SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT), expectations.with(mailboxSession));
+        expectations.will(Expectations.throwException(new MailboxException()));
+
+        expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+
+
+        mockery.checking(expectations);
+
+        mockery.checking(new Expectations() {
+            {
+                oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.BAD)));
+            }
+        });
+
+        testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+    }
+
+    @Test
+    public void processorShouldWorkOnNonValidRights() throws Exception {
+        GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest("A004", ImapCommand.anyStateCommand("Name"), "INBOX");
+        Expectations expectations = new Expectations();
+
+        expectations.allowing(mockedImapSession).getState();
+        expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+
+        expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
+        expectations.will(Expectations.returnValue(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).hasRight(expectations.with(MAILBOX_PATH),
+            expectations.with(SimpleMailboxACL.Rfc4314Rights.r_Read_RIGHT), expectations.with(mailboxSession));
+        expectations.will(Expectations.returnValue(false));
+
+        expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+
+        mockery.checking(expectations);
+
+        mockery.checking(new Expectations() {
+            {
+                oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.NO)));
+            }
+        });
+
+        testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+    }
+
+}

Added: james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java?rev=1704565&view=auto
==============================================================================
--- james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java (added)
+++ james/protocols/trunk/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java Tue Sep 22 10:40:05 2015
@@ -0,0 +1,89 @@
+/****************************************************************
+ * 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.imap.processor;
+
+import org.apache.james.imap.api.ImapCommand;
+import org.apache.james.imap.api.ImapSessionState;
+import org.apache.james.imap.api.ImapSessionUtils;
+import org.apache.james.imap.api.message.response.StatusResponse;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.message.request.SetQuotaRequest;
+import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(JMock.class)
+public class SetQuotaProcessorTest {
+
+    private SetQuotaProcessor testee;
+    private Mockery mockery;
+    private ImapSession mockedImapSession;
+    private ImapProcessor.Responder mockedResponder;
+    private MailboxManager mockedMailboxManager;
+    private MailboxSession mailboxSession;
+
+    @Before
+    public void setUp() {
+        mailboxSession = new MockMailboxSession("plop");
+        mockery = new JUnit4Mockery();
+        UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
+        mockedImapSession = mockery.mock(ImapSession.class);
+        mockedResponder = mockery.mock(ImapProcessor.Responder.class);
+        mockedMailboxManager = mockery.mock(MailboxManager.class);
+        testee = new SetQuotaProcessor(mockery.mock(ImapProcessor.class), mockedMailboxManager,
+            statusResponseFactory);
+    }
+
+    @Test
+    public void processorShouldWorkOnNoRights() throws Exception {
+        SetQuotaRequest setQuotaRequest = new SetQuotaRequest("A004", ImapCommand.anyStateCommand("Name"), "quotaRoot");
+        Expectations expectations = new Expectations();
+
+        expectations.allowing(mockedImapSession).getState();
+        expectations.will(Expectations.returnValue(ImapSessionState.AUTHENTICATED));
+
+        expectations.allowing(mockedImapSession).getAttribute(expectations.with(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY));
+        expectations.will(Expectations.returnValue(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).startProcessingRequest(expectations.with(mailboxSession));
+
+        expectations.allowing(mockedMailboxManager).endProcessingRequest(expectations.with(mailboxSession));
+
+        mockery.checking(expectations);
+
+        mockery.checking(new Expectations() {
+            {
+                oneOf(mockedResponder).respond(with(new StatusResponseTypeMatcher(StatusResponse.Type.NO)));
+            }
+        });
+
+        testee.doProcess(setQuotaRequest, mockedResponder, mockedImapSession);
+    }
+
+}




---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org