Modified: james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/ListProcessorTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/ListProcessorTest.java?rev=616502&r1=616501&r2=616502&view=diff ============================================================================== --- james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/ListProcessorTest.java (original) +++ james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/ListProcessorTest.java Tue Jan 29 11:59:29 2008 @@ -19,29 +19,146 @@ package org.apache.james.imapserver.processor.imap4rev1; +import org.apache.james.api.imap.ImapCommand; +import org.apache.james.api.imap.ImapConstants; import org.apache.james.api.imap.message.response.imap4rev1.StatusResponseFactory; import org.apache.james.api.imap.process.ImapProcessor; -import org.apache.james.imap.message.response.imap4rev1.server.AbstractListingResponse; +import org.apache.james.api.imap.process.ImapSession; import org.apache.james.imap.message.response.imap4rev1.server.ListResponse; +import org.apache.james.mailboxmanager.ListResult; import org.apache.james.mailboxmanager.manager.MailboxManagerProvider; +import org.jmock.Mock; +import org.jmock.MockObjectTestCase; -public class ListProcessorTest extends AbstractTestListProcessor { +public class ListProcessorTest extends MockObjectTestCase { + ListProcessor processor; + Mock next; + Mock provider; + Mock responder; + Mock result; + Mock session; + Mock command; + Mock serverResponseFactory; + protected void setUp() throws Exception { - super.setUp(); + serverResponseFactory = mock(StatusResponseFactory.class); + session = mock(ImapSession.class); + command = mock(ImapCommand.class); + next = mock(ImapProcessor.class); + responder = mock(ImapProcessor.Responder.class); + result = mock(ListResult.class); + provider = mock(MailboxManagerProvider.class); + processor = createProcessor((ImapProcessor) next.proxy(), + (MailboxManagerProvider) provider.proxy(), (StatusResponseFactory) serverResponseFactory.proxy()); } protected void tearDown() throws Exception { super.tearDown(); } - AbstractListingProcessor createProcessor(ImapProcessor next, MailboxManagerProvider provider, StatusResponseFactory factory) { + ListProcessor createProcessor(ImapProcessor next, MailboxManagerProvider provider, StatusResponseFactory factory) { return new ListProcessor(next, provider, factory); } - AbstractListingResponse createResponse(boolean noinferior, boolean noselect, boolean marked, + ListResponse createResponse(boolean noinferior, boolean noselect, boolean marked, boolean unmarked, String hierarchyDelimiter, String mailboxName) { return new ListResponse(noinferior, noselect, marked, unmarked, hierarchyDelimiter, mailboxName); } + void setUpResult(String[] attributes, String hierarchyDelimiter, String name) { + result.expects(once()).method("getAttributes").will(returnValue(attributes)); + result.expects(once()).method("getHierarchyDelimiter").will(returnValue(hierarchyDelimiter)); + result.expects(once()).method("getName").will(returnValue(name)); + } + + public void testNoInferiors() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_NOINFERIORS, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(true, false, false, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testNoSelect() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_NOSELECT, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, true, false, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testUnMarked() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_UNMARKED, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, false, false, true, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testMarked() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_MARKED, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, false, true, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testMarkedAndUnmarked() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_MARKED, ImapConstants.NAME_ATTRIBUTE_UNMARKED, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, false, true, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testUnmarkedAndMarked() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_UNMARKED, ImapConstants.NAME_ATTRIBUTE_MARKED, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, false, true, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testNoSelectUnmarkedAndMarked() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_NOSELECT, ImapConstants.NAME_ATTRIBUTE_UNMARKED, ImapConstants.NAME_ATTRIBUTE_MARKED, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, true, false, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testUnmarkedAndMarkedNoSelect() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_UNMARKED, ImapConstants.NAME_ATTRIBUTE_MARKED, ImapConstants.NAME_ATTRIBUTE_NOSELECT, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, true, false, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testUnmarkedNoSelectAndMarked() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_UNMARKED, ImapConstants.NAME_ATTRIBUTE_NOSELECT, ImapConstants.NAME_ATTRIBUTE_MARKED, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(false, true, false, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } + + public void testNoinferiorsUnmarkedNoSelectAndMarked() throws Exception { + String[] attributes = {"\\noise", ImapConstants.NAME_ATTRIBUTE_NOINFERIORS, ImapConstants.NAME_ATTRIBUTE_UNMARKED, ImapConstants.NAME_ATTRIBUTE_NOSELECT, ImapConstants.NAME_ATTRIBUTE_MARKED, "\\bogus"}; + setUpResult(attributes, ".", "#INBOX"); + responder.expects(once()).method("respond").with( + eq(createResponse(true, true, false, false, ".", "#INBOX"))); + processor.processResult((ImapProcessor.Responder) responder.proxy(), + false, 0, (ListResult) result.proxy()); + } }
Added: james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/UserMetaDataIMAPSubscriberTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/UserMetaDataIMAPSubscriberTest.java?rev=616502&view=auto ============================================================================== --- james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/UserMetaDataIMAPSubscriberTest.java (added) +++ james/server/trunk/imap-mailbox-processor-function/src/test/java/org/apache/james/imapserver/processor/imap4rev1/UserMetaDataIMAPSubscriberTest.java Tue Jan 29 11:59:29 2008 @@ -0,0 +1,117 @@ +/**************************************************************** + * 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.imapserver.processor.imap4rev1; + +import java.util.Collection; +import java.util.HashSet; + +import org.apache.james.api.user.UserMetaDataRespository; +import org.jmock.Mock; +import org.jmock.MockObjectTestCase; + +public class UserMetaDataIMAPSubscriberTest extends MockObjectTestCase { + + private static final String EXISTING_MAILBOX = "Beta"; + + private static final String NEW_MAILBOX = "Epsilon"; + + private static final String USER = "A User"; + + Collection subscriptions; + Mock metaData; + UserMetaDataIMAPSubscriber subscriber; + + protected void setUp() throws Exception { + super.setUp(); + subscriptions = new HashSet(); + subscriptions.add("Alpha"); + subscriptions.add(EXISTING_MAILBOX); + subscriptions.add("Gamma"); + subscriptions.add("Delta"); + metaData = mock(UserMetaDataRespository.class); + subscriber = new UserMetaDataIMAPSubscriber((UserMetaDataRespository) metaData.proxy()); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testShouldCreateNewWhenEmpty() throws Exception { + HashSet result = new HashSet(); + result.add(NEW_MAILBOX); + + metaData.expects(once()).method("getAttribute") + .with(eq(USER), eq(UserMetaDataIMAPSubscriber.META_DATA_KEY)) + .will(returnValue(null)); + + metaData.expects(once()).method("setAttribute").with(eq(USER), eq(result), + eq(UserMetaDataIMAPSubscriber.META_DATA_KEY)); + + subscriber.subscribe(USER, NEW_MAILBOX); + } + + public void testShouldAddToExistingSet() throws Exception { + HashSet result = new HashSet(subscriptions); + result.add(NEW_MAILBOX); + expectGetSubscriptions(); + metaData.expects(once()).method("setAttribute").with(eq(USER), eq(result), + eq(UserMetaDataIMAPSubscriber.META_DATA_KEY)); + + subscriber.subscribe(USER, NEW_MAILBOX); + } + + public void testShouldNotCallWhenAlreadySubscribed() throws Exception { + expectGetSubscriptions(); + + subscriber.subscribe(USER, EXISTING_MAILBOX); + } + + public void testSubscriptions() throws Exception { + + expectGetSubscriptions(); + + final Collection results = subscriber.subscriptions(USER); + assertEquals(subscriptions, results); + assertNotSame("To ensure independence, a copy should be returned.", subscriptions, results); + } + + private void expectGetSubscriptions() { + metaData.expects(once()).method("getAttribute") + .with(eq(USER), eq(UserMetaDataIMAPSubscriber.META_DATA_KEY)) + .will(returnValue(subscriptions)); + } + + public void testShouldUnsubscribeWhenMailboxListed() throws Exception { + expectGetSubscriptions(); + HashSet results = new HashSet(subscriptions); + results.remove(EXISTING_MAILBOX); + + metaData.expects(once()).method("setAttribute").with(eq(USER), eq(results), + eq(UserMetaDataIMAPSubscriber.META_DATA_KEY)); + + subscriber.unsubscribe(USER, EXISTING_MAILBOX); + } + + public void testShouldNotCallWhenMailboxNoSubscribed() throws Exception { + expectGetSubscriptions(); + + subscriber.unsubscribe(USER, NEW_MAILBOX); + } +} Modified: james/server/trunk/phoenix-deployment/src/java/org/apache/james/imapserver/phoenix/PhoenixImapProcessorFactory.java URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/java/org/apache/james/imapserver/phoenix/PhoenixImapProcessorFactory.java?rev=616502&r1=616501&r2=616502&view=diff ============================================================================== --- james/server/trunk/phoenix-deployment/src/java/org/apache/james/imapserver/phoenix/PhoenixImapProcessorFactory.java (original) +++ james/server/trunk/phoenix-deployment/src/java/org/apache/james/imapserver/phoenix/PhoenixImapProcessorFactory.java Tue Jan 29 11:59:29 2008 @@ -22,6 +22,7 @@ import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; +import org.apache.james.api.user.UserMetaDataRespository; import org.apache.james.imapserver.processor.main.DefaultImapProcessorFactory; import org.apache.james.mailboxmanager.manager.MailboxManagerProvider; import org.apache.james.services.UsersRepository; @@ -30,10 +31,12 @@ public void service(ServiceManager serviceManager) throws ServiceException { UsersRepository usersRepository = ( UsersRepository ) serviceManager. - lookup( "org.apache.james.services.UsersRepository" ); + lookup( UsersRepository.ROLE ); MailboxManagerProvider mailboxManagerProvider = - (MailboxManagerProvider) serviceManager.lookup("org.apache.james.mailboxmanager.manager.MailboxManagerProvider"); - configure(usersRepository, mailboxManagerProvider); + (MailboxManagerProvider) serviceManager.lookup( MailboxManagerProvider.ROLE ); + UserMetaDataRespository userMetaDataRepository = + (UserMetaDataRespository) serviceManager.lookup( UserMetaDataRespository.ROLE ); + configure(usersRepository, mailboxManagerProvider, userMetaDataRepository); } } Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/HostSystemFactory.java URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/HostSystemFactory.java?rev=616502&r1=616501&r2=616502&view=diff ============================================================================== --- james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/HostSystemFactory.java (original) +++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/experimental/imapserver/HostSystemFactory.java Tue Jan 29 11:59:29 2008 @@ -19,24 +19,43 @@ package org.apache.james.experimental.imapserver; +import java.io.File; + +import org.apache.commons.io.FileUtils; import org.apache.james.imapserver.codec.encode.main.DefaultImapEncoderFactory; import org.apache.james.imapserver.mock.MailboxManagerProviderSingleton; import org.apache.james.imapserver.processor.main.DefaultImapProcessorFactory; import org.apache.james.test.functional.imap.HostSystem; +import org.apache.james.user.impl.file.FileUserMetaDataRepository; public class HostSystemFactory { - + + private static final String META_DATA_DIRECTORY = "target/user-meta-data"; + + public static void resetUserMetaData() throws Exception { + + File dir = new File(META_DATA_DIRECTORY); + if (dir.exists()) { + FileUtils.deleteDirectory(dir); + } + dir.mkdirs(); + } + public static HostSystem createStandardImap() throws Exception { ExperimentalHostSystem result = new ExperimentalHostSystem(); final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory(); - defaultImapProcessorFactory.configure(result, MailboxManagerProviderSingleton.getMailboxManagerProviderInstance()); + resetUserMetaData(); + defaultImapProcessorFactory.configure(result, + MailboxManagerProviderSingleton.getMailboxManagerProviderInstance(), + new FileUserMetaDataRepository(META_DATA_DIRECTORY)); result.configure(new DefaultImapDecoderFactory().buildImapDecoder(), new DefaultImapEncoderFactory().buildImapEncoder(), defaultImapProcessorFactory.buildImapProcessor(), new ExperimentalHostSystem.Resetable() { public void reset() throws Exception { MailboxManagerProviderSingleton.reset(); + resetUserMetaData(); } }); Modified: james/server/trunk/user-api/src/main/java/org/apache/james/api/user/UserMetaDataRespository.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-api/src/main/java/org/apache/james/api/user/UserMetaDataRespository.java?rev=616502&r1=616501&r2=616502&view=diff ============================================================================== --- james/server/trunk/user-api/src/main/java/org/apache/james/api/user/UserMetaDataRespository.java (original) +++ james/server/trunk/user-api/src/main/java/org/apache/james/api/user/UserMetaDataRespository.java Tue Jan 29 11:59:29 2008 @@ -34,6 +34,8 @@ */ public interface UserMetaDataRespository { + public static final String ROLE = "org.apache.james.api.user"; + /** * Gets the attribute for the given key. * @param username the name of the user, not null --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
