KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > mailboxmanager > repository > MailboxManagerMailRepositoryTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.mailboxmanager.repository;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
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 JavaDoc;
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 JavaDoc, IOException JavaDoc {
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 JavaDoc, IOException JavaDoc {
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 JavaDoc url, String JavaDoc postfix,
92             boolean translateDelimiter) throws ConfigurationException,
93             SAXException JavaDoc, IOException JavaDoc {
94         String JavaDoc trans = "";
95         if (translateDelimiter) {
96             trans = "translateDelimiters=\"true\" ";
97         }
98         if (postfix != null) {
99             postfix = "postfix=\"" + postfix + "\" ";
100         } else {
101             postfix = "";
102         }
103         String JavaDoc configXml = "<repository destinationURL=\"" + url + "\" " + postfix
104                 + trans + "type=\"MAIL\" />";
105         InputStream JavaDoc stream=new ByteArrayInputStream JavaDoc(configXml.getBytes());
106         return new DefaultConfigurationBuilder().build(stream);
107     }
108
109 }
110
Popular Tags