001: //The contents of this file are subject to the Mozilla Public License Version
002: //1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: //Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.folder;
019:
020: import java.io.File;
021: import java.util.HashSet;
022: import java.util.Iterator;
023: import java.util.Set;
024:
025: import junit.framework.TestCase;
026:
027: import org.columba.addressbook.main.AddressbookMain;
028: import org.columba.core.config.Config;
029: import org.columba.core.logging.Logging;
030: import org.columba.core.plugin.PluginManager;
031: import org.columba.mail.main.MailMain;
032:
033: /**
034: * Abstract testcase creates a folder in setUp and removes it in tearDown.
035: * <p>
036: * Create new testcases by subclassing this class and using getSourceFolder()
037: * and getDestFolder() directly.
038: *
039: * @author fdietz
040: * @author redsolo
041: */
042: public class AbstractFolderTst extends TestCase {
043:
044: /** A source folder. */
045: protected AbstractMessageFolder sourceFolder;
046:
047: /** A destination folder. */
048: protected AbstractMessageFolder destFolder;
049:
050: /** A set with all created folders. */
051: private Set folders;
052:
053: private static int folderId = 0;
054:
055: private MailboxTstFactory factory;
056:
057: /**
058: * Constructor for test.
059: * <p>
060: * This is used when executing this individual test only or by the ant task.
061: * <p>
062: */
063: public AbstractFolderTst(String test) {
064: super (test);
065:
066: this .factory = new MHFolderFactory();
067: }
068:
069: /**
070: * Constructor for test.
071: * <p>
072: * Used by {@link AllTests}.
073: */
074: public AbstractFolderTst(MailboxTstFactory factory, String test) {
075: super (test);
076:
077: this .factory = factory;
078: }
079:
080: /**
081: * @see TestCase#setUp()
082: */
083: protected void setUp() throws Exception {
084:
085: // create config-folder
086: // File file = new File("test_config");
087: // file.mkdir();
088: //
089: // new Config(file);
090: //
091: // Logging.DEBUG = true;
092: // Logging.createDefaultHandler();
093: //
094: // // init mail component
095: // new MailMain().init();
096: // new AddressbookMain().init();
097: //
098: // // now load all available plugins
099: // PluginManager.getInstance().initExternalPlugins();
100:
101: folders = new HashSet();
102: sourceFolder = factory.createFolder(folderId++);
103: folders.add(sourceFolder);
104: destFolder = factory.createFolder(folderId++);
105: folders.add(destFolder);
106:
107: }
108:
109: public AbstractMessageFolder createFolder() {
110: AbstractMessageFolder folder = factory.createFolder(folderId++);
111: folders.add(folder);
112:
113: return folder;
114: }
115:
116: /**
117: * @see junit.framework.TestCase#tearDown()
118: */
119: protected void tearDown() throws Exception {
120: recursiveDelete(new File(FolderTstHelper.homeDirectory
121: + "/folders/"));
122: }
123:
124: private void recursiveDelete(File folder) {
125: // delete all files in folder
126: File[] list = folder.listFiles();
127:
128: for (int i = 0; i < list.length; i++) {
129: if (list[i].isDirectory()) {
130: recursiveDelete(list[i]);
131: } else {
132: list[i].delete();
133: }
134: }
135:
136: folder.delete();
137: }
138:
139: /**
140: * @return Returns the folder.
141: */
142: public AbstractMessageFolder getSourceFolder() {
143: return sourceFolder;
144: }
145:
146: /**
147: * @return Returns the destFolder.
148: */
149: public AbstractMessageFolder getDestFolder() {
150: return destFolder;
151: }
152:
153: }
|