KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fotreetest > FOTreeTestSuite


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

17
18 /* $Id: FOTreeTestSuite.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fotreetest;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import org.apache.commons.io.FileUtils;
28 import org.apache.commons.io.filefilter.AndFileFilter;
29 import org.apache.commons.io.filefilter.IOFileFilter;
30 import org.apache.commons.io.filefilter.NameFileFilter;
31 import org.apache.commons.io.filefilter.PrefixFileFilter;
32 import org.apache.commons.io.filefilter.SuffixFileFilter;
33 import org.apache.commons.io.filefilter.TrueFileFilter;
34 import org.apache.fop.DebugHelper;
35 import org.apache.fop.layoutengine.LayoutEngineTestSuite;
36
37 import junit.framework.Test;
38 import junit.framework.TestCase;
39 import junit.framework.TestSuite;
40
41 /**
42  * JUnit test suit for running layout engine test under JUnit control.
43  */

44 public final class FOTreeTestSuite {
45
46     static {
47         DebugHelper.registerStandardElementListObservers();
48     }
49     
50     private FOTreeTestSuite() {
51         //don't instantiate!
52
}
53     
54     /**
55      * @return the test suite with all the tests (one for each XML file)
56      * @throws IOException in case of an I/O problem
57      */

58     public static Test suite() throws IOException JavaDoc {
59         TestSuite suite = new TestSuite();
60
61         File JavaDoc mainDir = new File JavaDoc("test/fotree");
62
63         final FOTreeTester tester = new FOTreeTester();
64         
65         IOFileFilter filter;
66         String JavaDoc single = System.getProperty("fop.fotree.single");
67         String JavaDoc startsWith = System.getProperty("fop.fotree.starts-with");
68         if (single != null) {
69             filter = new NameFileFilter(single);
70         } else if (startsWith != null) {
71             filter = new PrefixFileFilter(startsWith);
72             filter = new AndFileFilter(filter, new SuffixFileFilter(".fo"));
73         } else {
74             filter = new SuffixFileFilter(".fo");
75             filter = LayoutEngineTestSuite.decorateWithDisabledList(filter);
76         }
77         Collection JavaDoc files = FileUtils.listFiles(new File JavaDoc(mainDir, "testcases"),
78                 filter, TrueFileFilter.INSTANCE);
79         String JavaDoc privateTests = System.getProperty("fop.fotree.private");
80         if ("true".equalsIgnoreCase(privateTests)) {
81             Collection JavaDoc privateFiles = FileUtils.listFiles(
82                     new File JavaDoc(mainDir, "private-testcases"),
83                     filter, TrueFileFilter.INSTANCE);
84             files.addAll(privateFiles);
85         }
86         Iterator JavaDoc i = files.iterator();
87         while (i.hasNext()) {
88             File JavaDoc f = (File JavaDoc)i.next();
89             addTestCase(suite, tester, f);
90         }
91         
92         return suite;
93     }
94     
95     private static void addTestCase(TestSuite suite,
96                 final FOTreeTester tester, final File JavaDoc f) {
97         suite.addTest(new FOTreeTestCase(f.getName()) {
98             public void runTest() throws Exception JavaDoc {
99                 org.apache.commons.logging.LogFactory.getLog(this.getClass()).info("Starting " + f.getName());
100                 prepare(tester, f);
101                 testMain();
102             }
103         });
104     }
105     
106     private static class FOTreeTestCase extends TestCase {
107         
108         private FOTreeTester tester;
109         private File JavaDoc testFile;
110         
111         public FOTreeTestCase(String JavaDoc name) {
112             super(name);
113         }
114         
115         public void prepare(FOTreeTester tester, File JavaDoc testFile) {
116             //super(testFile.getName());
117
this.tester = tester;
118             this.testFile = testFile;
119         }
120         
121         public void testMain() throws Exception JavaDoc {
122             tester.runTest(testFile);
123         }
124     }
125 }
126
Popular Tags