1 19 20 package org.apache.james.mailboxmanager.repository; 21 22 import java.io.ByteArrayInputStream ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 26 import junit.framework.TestCase; 27 28 import org.apache.avalon.framework.configuration.Configuration; 29 import org.apache.avalon.framework.configuration.ConfigurationException; 30 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 31 import org.apache.avalon.framework.container.ContainerUtil; 32 import org.apache.james.test.mock.avalon.MockLogger; 33 import org.xml.sax.SAXException ; 34 35 public class MailboxManagerMailRepositoryTest extends TestCase { 36 37 protected MailboxManagerMailRepository mailboxManagerMailRepository; 38 39 public void setUp() { 40 mailboxManagerMailRepository = new MailboxManagerMailRepository(); 41 ContainerUtil.enableLogging(mailboxManagerMailRepository, 42 new MockLogger()); 43 } 44 45 public void testConfigurePostfix() throws ConfigurationException, 46 SAXException , IOException { 47 mailboxManagerMailRepository.configure(get( 48 "mailboxmanager://#mail/tuser/", ".INBOX", true)); 49 assertEquals("#mail.tuser.INBOX", mailboxManagerMailRepository 50 .getMailboxName()); 51 52 mailboxManagerMailRepository.configure(get( 53 "mailboxmanager://#mail/tuser", ".NEWBOX", true)); 54 assertEquals("#mail.tuser.NEWBOX", mailboxManagerMailRepository 55 .getMailboxName()); 56 57 mailboxManagerMailRepository.configure(get( 58 "mailboxmanager://#mail/tuser", ".NEWBOX", false)); 59 assertEquals("#mail/tuser.NEWBOX", mailboxManagerMailRepository 60 .getMailboxName()); 61 62 mailboxManagerMailRepository.configure(get( 63 "mailboxmanager://#mail/tuser/", ".NEWBOX", false)); 64 assertEquals("#mail/tuser/.NEWBOX", mailboxManagerMailRepository 65 .getMailboxName()); 66 } 67 68 public void testConfigure() throws ConfigurationException, 69 SAXException , IOException { 70 mailboxManagerMailRepository.configure(get( 71 "mailboxmanager://#system/tuser/", null, true)); 72 assertEquals("#system.tuser", mailboxManagerMailRepository 73 .getMailboxName()); 74 75 mailboxManagerMailRepository.configure(get( 76 "mailboxmanager://#system/tuser", null, true)); 77 assertEquals("#system.tuser", mailboxManagerMailRepository 78 .getMailboxName()); 79 80 mailboxManagerMailRepository.configure(get( 81 "mailboxmanager://#system/tuser", null, false)); 82 assertEquals("#system/tuser", mailboxManagerMailRepository 83 .getMailboxName()); 84 85 mailboxManagerMailRepository.configure(get( 86 "mailboxmanager://#system/tuser/", null, false)); 87 assertEquals("#system/tuser/", mailboxManagerMailRepository 88 .getMailboxName()); 89 } 90 91 protected Configuration get(String url, String postfix, 92 boolean translateDelimiter) throws ConfigurationException, 93 SAXException , IOException { 94 String trans = ""; 95 if (translateDelimiter) { 96 trans = "translateDelimiters=\"true\" "; 97 } 98 if (postfix != null) { 99 postfix = "postfix=\"" + postfix + "\" "; 100 } else { 101 postfix = ""; 102 } 103 String configXml = "<repository destinationURL=\"" + url + "\" " + postfix 104 + trans + "type=\"MAIL\" />"; 105 InputStream stream=new ByteArrayInputStream (configXml.getBytes()); 106 return new DefaultConfigurationBuilder().build(stream); 107 } 108 109 } 110 | Popular Tags |