1 19 20 package org.apache.james.mailboxmanager.mailstore; 21 22 import java.util.Arrays ; 23 24 import org.apache.avalon.cornerstone.services.store.Store; 25 import org.apache.avalon.framework.configuration.ConfigurationException; 26 import org.apache.avalon.framework.configuration.DefaultConfiguration; 27 import org.apache.james.mailboxmanager.MailboxManagerException; 28 import org.apache.james.mailboxmanager.mailbox.MailboxSession; 29 import org.apache.james.services.MailRepository; 30 import org.apache.james.test.mock.avalon.MockLogger; 31 import org.jmock.Mock; 32 import org.jmock.MockObjectTestCase; 33 import org.jmock.core.constraint.IsEqual; 34 35 public class MailStoreMailboxCacheTest extends MockObjectTestCase { 36 37 MailstoreMailboxCache mailstoreMailboxCache; 38 39 public void setUp() { 40 mailstoreMailboxCache = new MailstoreMailboxCache(); 41 mailstoreMailboxCache.enableLogging(new MockLogger()); 42 mailstoreMailboxCache.setMountPoint("#mail"); 43 mailstoreMailboxCache.setDestinationURL("file://var/mail/inboxes/"); 44 } 45 46 public void testBuildUrlNoInbox() { 47 assertEquals("file://var/mail/inboxes/t1", mailstoreMailboxCache 48 .buildUrl("#mail.t1")); 49 assertEquals("file://var/mail/inboxes/t1.t2", mailstoreMailboxCache 50 .buildUrl("#mail.t1.t2")); 51 } 52 53 public void testBuildUrlInbox() { 54 assertEquals("file://var/mail/inboxes/", mailstoreMailboxCache 55 .buildUrl("#mail.INBOX")); 56 assertEquals("file://var/mail/inboxes/t1", mailstoreMailboxCache 57 .buildUrl("#mail.t1.INBOX")); 58 assertEquals("file://var/mail/inboxes/t1.t2", mailstoreMailboxCache 59 .buildUrl("#mail.t1.t2.INBOX")); 60 } 61 62 public void testGetMailboxSession() throws MailboxManagerException, 63 ConfigurationException { 64 65 DefaultConfiguration repositoryConfiguration = new DefaultConfiguration( 66 "repository"); 67 68 DefaultConfiguration expectedConfiguration = new DefaultConfiguration( 69 repositoryConfiguration); 70 expectedConfiguration.setAttribute("destinationURL", 71 "file://var/mail/inboxes/t1"); 72 73 Mock store = mock(Store.class); 74 Mock mockRepository = mock(MailRepository.class); 75 store.expects(exactly(2)).method("select").with( 76 new IsEqual(expectedConfiguration)).will( 77 returnValue(mockRepository.proxy())); 78 79 mailstoreMailboxCache.setMailStore((Store) store.proxy()); 80 mailstoreMailboxCache.setRepositoryConf(repositoryConfiguration); 81 MailboxSession s1 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX"); 82 MailboxSession s2 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX"); 83 assertNotSame(s1, s2); 84 s1.close(); 85 MailboxSession s3 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX"); 86 s3.close(); 87 s2.close(); 88 89 MailboxSession s4 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX"); 90 91 String [] keys = new String [] { "test" }; 92 mockRepository.expects(once()).method("list").withNoArguments().will( 93 returnIterator(keys)); 94 assertEquals(Arrays.asList(keys), s4.list()); 95 } 96 97 } 98 | Popular Tags |