C:\Java WorkShop\Lexx\src\lexx\test\AllTests.java

1    package lexx.test; 
2     
3    import java.io.File; 
4    import java.io.FileOutputStream; 
5    import java.io.IOException; 
6    import java.io.InputStream; 
7     
8    import javax.swing.JFrame; 
9    import javax.swing.JLabel; 
10    
11   import junit.framework.Test; 
12   import junit.framework.TestCase; 
13   import junit.framework.TestSuite; 
14   import lexx.api.JavaPackages; 
15   import lexx.gui.editor.EditorPanel; 
16    
17   /** 
18    * <p>Runs All Tests<p> 
19    * <p>This class runs all tests in the Lexx IDE</p> 
20    * <p>Copyright (c) 2002-2003</p> 
21    * @since 20/03/2003 
22    * @author Mohammed Imran 
23    * @version 1.0 
24    */ 
25   public class AllTests extends TestCase 
26   { 
27    
28     public AllTests(String s) 
29     { 
30       super(s); 
31     } 
32    
33     public static Test suite() 
34     { 
35       TestSuite suite = new TestSuite(); 
36       suite.addTestSuite(lexx.api.JavaPackagesTest.class); 
37       suite.addTestSuite(lexx.autocomplete.java.JavaAutoTest.class); 
38       suite.addTestSuite(lexx.autocomplete.java.JavaObjectUtilTest.class); 
39       suite.addTestSuite(lexx.autocomplete.java.PopupMethodTest.class); 
40       suite.addTestSuite(lexx.parser.ast.java.ASTAnalyserTest.class); 
41       suite.addTestSuite(lexx.plugins.ant.BuildProjectTest.class); 
42       suite.addTestSuite(lexx.plugins.ant.ProcessTest.class); 
43       suite.addTestSuite(lexx.plugins.javadoc.JavaDocTest.class); 
44       suite.addTestSuite(lexx.server.ChatTest.class); 
45       suite.addTestSuite(lexx.server.HashTest.class); 
46       suite.addTestSuite(lexx.server.ServerTest.class); 
47       suite.addTestSuite(lexx.test.Simulator.class); 
48       suite.addTestSuite(lexx.trie.TrieTest.class); 
49       suite.addTestSuite(lexx.utils.FileUtilTest.class); 
50       suite.addTestSuite(lexx.utils.MD5Test.class); 
51       suite.addTestSuite(lexx.utils.StringSearchTest.class); 
52       return suite; 
53     } 
54    
55     public static void main(String args[]) 
56     { 
57       lexx.RunApp.setupProxy(); 
58       lexx.RunApp.setupLogger(); 
59       String[] a = new String[1]; 
60       a[0] = "lexx.test.AllTests"; 
61       junit.swingui.TestRunner.main(a); 
62     } 
63    
64     /** 
65      * This extracts a zip file which contains a project and performs all the 
66      * required settings inorder for you to run other modules. 
67      * @param fileName the name of the zip file found in the package lexx.test 
68      * @return the directory which contains the project data 
69      */ 
70     public synchronized static File createAndSetupTestFile(String fileName) 
71     { 
72       try 
73       { 
74         File test = AllTests.getTestFile(fileName); 
75         File tmp = File.createTempFile("createAndSetupTestFile", fileName). 
76                    getCanonicalFile(); 
77         lexx.utils.FileUtil.extractZip(test, tmp); 
78         String classPath = lexx.plugins.ant.BuildProject.getLib(tmp.toString()); 
79         lexx.utils.Config.setupConfig(tmp + "/config.lexx", new JLabel(), 
80                                       new JFrame()); 
81         lexx.utils.Config.setProjectPath(tmp.toString()); 
82    
83         pack = new JavaPackages(lexx.utils. 
84                                 Config.getClassesPath(), new JLabel(), classPath); 
85    
86         return tmp; 
87       } 
88       catch(IOException ex) 
89       { 
90         return null; 
91       } 
92     } 
93    
94     /** 
95      * This removes the temporarily create project file and turns off all modules 
96      * to conserve memory 
97      * @param path the directory where the project is stored 
98      * @param p the editorpanel which has loaded up the file. (You can just type 
99      * null if you don't have an editorpanel) 
100     */ 
101    public synchronized static void finalize(File path, EditorPanel p) 
102    { 
103      if(p != null) 
104      { 
105        p.getTextPane().removeAll(); 
106        p.getTextPane().disable(); 
107        p.removeAll(); 
108        p.disable(); 
109      } 
110      if(pack != null) 
111      { 
112        pack.close(); 
113      } 
114      lexx.utils.Config.setPackages(null); 
115      lexx.utils.FileUtil.deleteRecursivly(path); 
116      System.runFinalization(); 
117      System.gc(); 
118    } 
119   
120    private static JavaPackages pack = null; 
121   
122    static JavaPackages getPackages() 
123    { 
124      return pack; 
125    } 
126   
127    public static EditorPanel getEditorPanel(File javaFile) 
128    { 
129      if(pack == null) 
130      { 
131        throw new RuntimeException( 
132            "Must call createAndSetupTestFile(String fileName) first"); 
133      } 
134   
135      return new EditorPanel(pack, javaFile, javaFile.getName()); 
136    } 
137   
138    /** 
139     * This unzips a file found in the package lexx.test 
140     * @param fileName name of the zip file 
141     * @return the directory where the file has been extracted to 
142     */ 
143    public static File getTestFile(String fileName) 
144    { 
145      try 
146      { 
147        InputStream in = AllTests.class.getResourceAsStream(fileName); 
148        File f = File.createTempFile("AllTest", fileName); 
149        f.deleteOnExit(); 
150        lexx.utils.FileUtil.write(in, new FileOutputStream(f)); 
151        return f; 
152      } 
153      catch(Exception ex) 
154      { 
155        ex.printStackTrace(); 
156        return null; 
157      } 
158    } 
159  } 
160