KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > filter > plugins > AbstractFilterTst


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.filter.plugins;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.io.File JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.columba.addressbook.main.AddressbookMain;
26 import org.columba.core.config.Config;
27 import org.columba.core.logging.Logging;
28 import org.columba.core.plugin.PluginManager;
29 import org.columba.mail.folder.AbstractMessageFolder;
30 import org.columba.mail.folder.FolderTstHelper;
31 import org.columba.mail.folder.MHFolderFactory;
32 import org.columba.mail.folder.MailboxTstFactory;
33 import org.columba.mail.main.MailMain;
34
35 /**
36  * Base class for all filter tests.
37  * <p>
38  * Provides a test folder.
39  *
40  * @author fdietz
41  *
42  */

43 public class AbstractFilterTst extends TestCase {
44
45     protected AbstractMessageFolder sourceFolder;
46
47     protected MailboxTstFactory factory;
48
49     /**
50      * Constructor for test.
51      * <p>
52      * This is used when executing this individual test only or by the ant task.
53      * <p>
54      */

55     public AbstractFilterTst(String JavaDoc test) {
56         super(test);
57
58         this.factory = new MHFolderFactory();
59     }
60
61     /**
62      * Constructor for AbstractFilterTest.
63      *
64      * @param arg0
65      * @param factory
66      */

67     public AbstractFilterTst(MailboxTstFactory factory, String JavaDoc arg0) {
68         super(arg0);
69         this.factory = factory;
70     }
71
72     /**
73      * @return Returns the folder.
74      */

75     public AbstractMessageFolder getSourceFolder() {
76         return sourceFolder;
77     }
78
79     /**
80      * @see TestCase#setUp()
81      */

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

101         sourceFolder = factory.createFolder(1);
102
103         // create MH folder
104
// -> use homeDirectory as top-level folder
105
// -> this has to be an absolute path
106
/*
107          * sourceFolder = new CachedMHFolder("test", "CachedMHFolder",
108          * FolderTstHelper.homeDirectory + "/folders/");
109          */

110     }
111
112     /**
113      * @see TestCase#tearDown()
114      */

115     protected void tearDown() throws Exception JavaDoc {
116         File JavaDoc f = sourceFolder.getDirectoryFile();
117
118         recursiveDelete(f);
119     }
120
121     
122     private void recursiveDelete(File JavaDoc folder) {
123         // delete all files in folder
124
File JavaDoc[] list = folder.listFiles();
125
126         for (int i = 0; i < list.length; i++) {
127             if( list[i].isDirectory() ) {
128                 recursiveDelete(list[i]);
129             } else {
130                 list[i].delete();
131             }
132         }
133         
134         folder.delete();
135     }
136     
137     /**
138      * Add message to test folder.
139      *
140      * @throws Exception
141      */

142     public Object JavaDoc addMessage() throws Exception JavaDoc {
143         // add message "0.eml" as inputstream to folder
144
String JavaDoc input = FolderTstHelper.getString(0);
145     
146
147         // create stream from string
148
ByteArrayInputStream JavaDoc inputStream = FolderTstHelper
149                 .getByteArrayInputStream(input);
150
151         // add stream to folder
152
Object JavaDoc uid = getSourceFolder().addMessage(inputStream);
153
154         // close stream
155
inputStream.close();
156
157         return uid;
158     }
159
160 }
Popular Tags