|
TestGate |
|
1 /* 2 * TestGate.java 3 * 4 * Copyright (c) 1998-2001, The University of Sheffield. 5 * 6 * This file is part of GATE (see http://gate.ac.uk/), and is free 7 * software, licenced under the GNU Library General Public License, 8 * Version 2, June 1991 (in the distribution as file licence.html, 9 * and also available at http://gate.ac.uk/gate/licence.html). 10 * 11 * Hamish Cunningham, 21/Jan/00 12 * 13 * $Id: TestGate.java,v 1.196 2003/06/16 09:52:37 valyt Exp $ 14 */ 15 16 package gate; 17 18 import java.util.*; 19 import java.net.*; 20 import java.io.*; 21 import junit.framework.*; 22 import gnu.getopt.*; 23 24 import gate.*; 25 import gate.annotation.*; 26 import gate.corpora.*; 27 import gate.creole.*; 28 import gate.creole.tokeniser.*; 29 import gate.creole.gazetteer.*; 30 import gate.jape.*; 31 import gate.xml.*; 32 import gate.email.*; 33 import gate.html.*; 34 import gate.sgml.*; 35 import gate.util.*; 36 import gate.config.*; 37 import gate.persist.*; 38 import gate.security.*; 39 import com.ontotext.gate.gazetteer.*; 40 import gate.creole.ir.*; 41 import gate.wordnet.*; 42 43 /** Top-level entry point for GATE test suite; 44 * "main" will run the JUnit test runner interface. 45 * <P> 46 * Many tests require access to files; generally these files are located 47 * on Web servers. In cases where there is no net connection, or the 48 * Web servers are down, the test files are searched for in the file system 49 * or Jar code base that the system has been loaded from. The search 50 * order for test files is like this: 51 * <UL> 52 * <LI> 53 * <A HREF=http://derwent.dcs.shef.ac.uk:80/gate.ac.uk/> 54 * http://derwent.dcs.shef.ac.uk:80/gate.ac.uk/</A> 55 * <LI> 56 * <A HREF=http://gate.ac.uk:80/>http://gate.ac.uk:80/</A> 57 * <LI> 58 * <A HREF=http://localhost:80/gate.ac.uk/>http://localhost:80/gate.ac.uk/</A> 59 * <LI> 60 * the file system location that the classes came from, e.g. 61 * <TT>z:\gate\classes</TT>, or <TT>jar:....gate.jar</TT>. 62 * </UL> 63 * This search order can be modified by parameters to the main 64 * function (see below). 65 */ 66 67 public class TestGate { 68 69 /** Debug flag */ 70 private static final boolean DEBUG = false; 71 72 /** Status flag for normal exit. */ 73 private static final int STATUS_NORMAL = 0; 74 75 /** Status flag for error exit. */ 76 private static final int STATUS_ERROR = 1; 77 78 private static final String 79 defOracleDriver = "jdbc:oracle:thin:@derwent:1521:dbgate"; 80 private static final String 81 saiOracleDriver = "jdbc:oracle:thin:GATEUSER/gate@192.168.128.7:1521:GATE04"; 82 private static final String 83 defPSQLDriver = "jdbc:postgresql://redmires/gate"; 84 private static final String 85 saiPSQLDriver = "jdbc:postgresql://sirma/gate"; 86 87 88 public static String oracleDriver = defOracleDriver; 89 public static String psqlDriver = defPSQLDriver; 90 91 /** Main routine for the GATE test suite. 92 * Command-line arguments: 93 * <UL> 94 * <LI> 95 * <B>-a</B> means run the test runner in automatic class reload mode 96 * <LI> 97 * <B>-n</B> means assume there's no net connection 98 * <LI> 99 * <B>-t</B> means run the test runner in text mode 100 * (useful for 101 * debugging, as there's less confusion to do with threads and 102 * class loaders). 103 * <LI> 104 * <B>-i file</B> additional initialisation file (probably called 105 * <TT>gate.xml</TT>). Used for site-wide initialisation by the 106 * start-up scripts. 107 * </UL> 108 */ 109 public static void main(String[] args) throws Exception { 110 boolean textMode = false; 111 boolean autoloadingMode = false; 112 113 // process command-line options 114 Getopt g = new Getopt("GATE test suite", args, "tnNasi:"); 115 int c; 116 while( (c = g.getopt()) != -1 ) 117 switch(c) { 118 case 't': 119 textMode = true; 120 break; 121 case 'n': 122 Gate.setNetConnected(false); 123 break; 124 case 'N': 125 Gate.setNetConnected(false); 126 Gate.setLocalWebServer(false); 127 break; 128 case 'a': 129 autoloadingMode = true; 130 break; 131 case 's': 132 oracleDriver = saiOracleDriver; 133 psqlDriver = saiPSQLDriver; 134 break; 135 // -i gate.xml site-wide init file 136 case 'i': 137 String optionString = g.getOptarg(); 138 URL u = null; 139 File f = new File(optionString); 140 try { 141 u = f.toURL(); 142 } catch(MalformedURLException e) { 143 Err.prln("Bad initialisation file: " + optionString); 144 Err.prln(e); 145 System.exit(STATUS_ERROR); 146 } 147 Gate.setSiteConfigFile(f); 148 Out.prln( 149 "Initialisation file " + optionString + 150 " recorded for initialisation" 151 ); 152 break; 153 case '?': 154 // leave the warning to getopt 155 return; 156 default: 157 Err.prln("getopt() returned " + c + "\n"); 158 } // switch 159 160 // set up arguments for the JUnit test runner 161 String junitArgs[] = new String[2]; 162 junitArgs[0] = "-noloading"; 163 junitArgs[1] = "gate.TestGate"; 164 165 // use the next line if you're running with output to console in text mode: 166 // junitArgs[1] = "-wait"; 167 168 // execute the JUnit test runner 169 if(textMode) { // text runner mode 170 junit.textui.TestRunner.main(junitArgs); 171 } else if(autoloadingMode) { // autoloading mode 172 junitArgs[0] = "gate.TestGate"; 173 junitArgs[1] = ""; 174 175 // NOTE: the DB tests fail under this one (doesn't load oracle driver, 176 // even after the Class.forName call) 177 Class clazz = null; 178 clazz = Class.forName("oracle.jdbc.driver.OracleDriver"); 179 clazz = null; 180 junit.swingui.TestRunner.main(junitArgs); 181 182 } else { // by default us the single-run GUI version 183 junit.swingui.TestRunner.main(junitArgs); 184 } 185 186 } // main 187 188 /** GATE test suite. Every test case class has to be 189 * registered here. 190 */ 191 public static Test suite() throws Exception { 192 // inialise the library. we re-throw any exceptions thrown by 193 // init, after printing them out, because the junit gui doesn't 194 // say anything more informative than "can't invoke suite" if there's 195 // an exception here... 196 try { 197 Gate.init(); 198 } catch(GateException e) { 199 Out.prln("can't initialise GATE library! exception = " + e); 200 throw(e); 201 } 202 203 TestSuite suite = new TestSuite(); 204 205 try { 206 //////////////////////////////////////////////// 207 // Test bench 208 //////////////////////////////////////////////// 209 // set this true to run all tests; false to run the just one below 210 boolean allTests = true; 211 if(! allTests){ 212 suite.addTest(TestJavac.suite()); 213 } else { 214 suite.addTest(TestWordNet.suite()); 215 suite.addTest(TestIndex.suite()); 216 suite.addTest(TestPersist.suite()); 217 suite.addTest(TestBumpyStack.suite()); 218 suite.addTest(TestControllers.suite()); 219 suite.addTest(TestSecurity.suite()); 220 suite.addTest(TestAnnotationDiff.suite()); 221 suite.addTest(TestConfig.suite()); 222 suite.addTest(TestAnnotation.suite()); 223 suite.addTest(TestEmail.suite()); 224 suite.addTest(TestXml.suite()); 225 suite.addTest(TestHtml.suite()); 226 suite.addTest(TestSgml.suite()); 227 suite.addTest(TestXSchema.suite()); 228 suite.addTest(TestCreole.suite()); 229 suite.addTest(CookBook.suite()); 230 suite.addTest(TestFiles.suite()); 231 suite.addTest(TestJavac.suite()); 232 suite.addTest(TestJdk.suite()); 233 suite.addTest(TestJape.suite()); 234 suite.addTest(TestTemplate.suite()); 235 suite.addTest(TestJacl.suite()); 236 suite.addTest(TestDocument.suite()); 237 suite.addTest(TestRBTreeMap.suite()); 238 suite.addTest(TestCorpus.suite()); 239 suite.addTest(TestSerialCorpus.suite()); 240 suite.addTest(TestDiffer.suite()); 241 //no longer needed as replaced by testPR 242 // suite.addTest(TestTokeniser.suite()); 243 // suite.addTest(TestGazetteer.suite()); 244 // suite.addTest(TestSplitterTagger.suite()); 245 suite.addTest(TestFeatureMap.suite()); 246 suite.addTest(TestPR.suite()); 247 248 //test ontotext gazetteer 249 suite.addTest(TestHashGazetteer.suite()); 250 251 } // if(allTests) 252 253 } catch(Exception e) { 254 Out.prln("can't add tests! exception = " + e); 255 throw(e); 256 } 257 258 return suite; 259 } // suite 260 261 } // class TestGate 262
|
TestGate |
|