KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > AbstractFolderTst


1 //The contents of this file are subject to the Mozilla Public License Version
2
//1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
//Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.folder;
19
20 import java.io.File JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import junit.framework.TestCase;
26
27 import org.columba.addressbook.main.AddressbookMain;
28 import org.columba.core.config.Config;
29 import org.columba.core.logging.Logging;
30 import org.columba.core.plugin.PluginManager;
31 import org.columba.mail.main.MailMain;
32
33 /**
34  * Abstract testcase creates a folder in setUp and removes it in tearDown.
35  * <p>
36  * Create new testcases by subclassing this class and using getSourceFolder()
37  * and getDestFolder() directly.
38  *
39  * @author fdietz
40  * @author redsolo
41  */

42 public class AbstractFolderTst extends TestCase {
43
44     /** A source folder. */
45     protected AbstractMessageFolder sourceFolder;
46
47     /** A destination folder. */
48     protected AbstractMessageFolder destFolder;
49
50     /** A set with all created folders. */
51     private Set JavaDoc folders;
52
53     private static int folderId = 0;
54
55     private MailboxTstFactory factory;
56
57     /**
58      * Constructor for test.
59      * <p>
60      * This is used when executing this individual test only or by the ant task.
61      * <p>
62      */

63     public AbstractFolderTst(String JavaDoc test) {
64         super(test);
65
66         this.factory = new MHFolderFactory();
67     }
68
69     /**
70      * Constructor for test.
71      * <p>
72      * Used by {@link AllTests}.
73      */

74     public AbstractFolderTst(MailboxTstFactory factory, String JavaDoc test) {
75         super(test);
76
77         this.factory = factory;
78     }
79
80     /**
81      * @see TestCase#setUp()
82      */

83     protected void setUp() throws Exception JavaDoc {
84
85         // create config-folder
86
// File file = new File("test_config");
87
// file.mkdir();
88
//
89
// new Config(file);
90
//
91
// Logging.DEBUG = true;
92
// Logging.createDefaultHandler();
93
//
94
// // init mail component
95
// new MailMain().init();
96
// new AddressbookMain().init();
97
//
98
// // now load all available plugins
99
// PluginManager.getInstance().initExternalPlugins();
100

101         folders = new HashSet JavaDoc();
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 JavaDoc {
120         recursiveDelete(new File JavaDoc(FolderTstHelper.homeDirectory + "/folders/"));
121     }
122
123     private void recursiveDelete(File JavaDoc folder) {
124         // delete all files in folder
125
File JavaDoc[] list = folder.listFiles();
126
127         for (int i = 0; i < list.length; i++) {
128             if( list[i].isDirectory() ) {
129                 recursiveDelete(list[i]);
130             } else {
131                 list[i].delete();
132             }
133         }
134         
135         folder.delete();
136     }
137     
138     /**
139      * @return Returns the folder.
140      */

141     public AbstractMessageFolder getSourceFolder() {
142         return sourceFolder;
143     }
144
145     /**
146      * @return Returns the destFolder.
147      */

148     public AbstractMessageFolder getDestFolder() {
149         return destFolder;
150     }
151
152 }
Popular Tags