001 /*
002 * TestGate.java
003 *
004 * Copyright (c) 1995-2010, The University of Sheffield. See the file
005 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006 *
007 * This file is part of GATE (see http://gate.ac.uk/), and is free
008 * software, licenced under the GNU Library General Public License,
009 * Version 2, June 1991 (in the distribution as file licence.html,
010 * and also available at http://gate.ac.uk/gate/licence.html).
011 *
012 * Hamish Cunningham, 21/Jan/00
013 *
014 * $Id: TestGate.java 13063 2010-09-08 09:51:46Z ian_roberts $
015 */
016
017 package gate;
018
019 import gate.annotation.TestAnnotation;
020 import gate.config.TestConfig;
021 import gate.corpora.TestCorpus;
022 import gate.corpora.TestDocument;
023 import gate.corpora.TestDocumentStaxUtils;
024 import gate.corpora.TestSerialCorpus;
025 import gate.creole.TestControllers;
026 import gate.creole.TestCreole;
027 import gate.creole.TestCreoleAnnotationHandler;
028 import gate.creole.TestPR;
029 import gate.creole.TestXSchema;
030 import gate.creole.annic.test.TestAnnic;
031 import gate.creole.gazetteer.TestFlexibleGazetteer;
032 import gate.creole.gazetteer.TestGazetteer;
033 import gate.creole.ir.TestIndex;
034 import gate.creole.morph.TestMorph;
035 import gate.creole.test.DynamicRegistrationTest;
036 import gate.email.TestEmail;
037 import gate.html.TestHtml;
038 import gate.jape.functest.TestJape;
039 import gate.persist.TestPersist;
040 import gate.sgml.TestSgml;
041 import gate.util.Err;
042 import gate.util.GateException;
043 import gate.util.Out;
044 import gate.util.TestAnnotationMerging;
045 import gate.util.TestClassificationMeasures;
046 import gate.util.TestDiffer;
047 import gate.util.TestFeatureMap;
048 import gate.util.TestFiles;
049 import gate.util.TestJavac;
050 import gate.util.TestRBTreeMap;
051 import gate.util.TestReload;
052 import gate.util.TestTemplate;
053 import gate.util.TestTools;
054 import gate.xml.TestRepositioningInfo;
055 import gate.xml.TestXml;
056 import gnu.getopt.Getopt;
057
058 import java.io.File;
059 import java.lang.reflect.Method;
060 import java.net.MalformedURLException;
061 import java.net.URL;
062
063 import junit.framework.Test;
064 import junit.framework.TestSuite;
065
066 import com.ontotext.gate.gazetteer.TestHashGazetteer;
067
068 /** Top-level entry point for GATE test suite;
069 * "main" will run the JUnit test runner interface.
070 * <P>
071 * Many tests require access to files; generally these files are located
072 * on Web servers. In cases where there is no net connection, or the
073 * Web servers are down, the test files are searched for in the file system
074 * or Jar code base that the system has been loaded from. The search
075 * order for test files is like this:
076 * <UL>
077 * <LI>
078 * <A HREF=http://derwent.dcs.shef.ac.uk:80/gate.ac.uk/>
079 * http://derwent.dcs.shef.ac.uk:80/gate.ac.uk/</A>
080 * <LI>
081 * <A HREF=http://gate.ac.uk:80/>http://gate.ac.uk:80/</A>
082 * <LI>
083 * <A HREF=http://localhost:80/gate.ac.uk/>http://localhost:80/gate.ac.uk/</A>
084 * <LI>
085 * the file system location that the classes came from, e.g.
086 * <TT>z:\gate\classes</TT>, or <TT>jar:....gate.jar</TT>.
087 * </UL>
088 * This search order can be modified by parameters to the main
089 * function (see below).
090 */
091
092 public class TestGate {
093
094 /** Debug flag */
095 private static final boolean DEBUG = false;
096
097 /** Status flag for normal exit. */
098 private static final int STATUS_NORMAL = 0;
099
100 /** Status flag for error exit. */
101 private static final int STATUS_ERROR = 1;
102
103 private static final String
104 defOracleDriver = "jdbc:oracle:thin:@derwent:1521:dbgate";
105 private static final String
106 saiOracleDriver = "jdbc:oracle:thin:GATEUSER/gate@192.168.128.7:1521:GATE04";
107 private static final String
108 defPSQLDriver = "jdbc:postgresql://redmires/gate";
109 private static final String
110 saiPSQLDriver = "jdbc:postgresql://sirma/gate";
111
112
113 public static String oracleDriver = defOracleDriver;
114 public static String psqlDriver = defPSQLDriver;
115
116 /** Main routine for the GATE test suite.
117 * Command-line arguments:
118 * <UL>
119 * <LI>
120 * <B>-a</B> means run the test runner in automatic class reload mode
121 * <LI>
122 * <B>-n</B> means assume there's no net connection
123 * <LI>
124 * <B>-t</B> means run the test runner in text mode
125 * (useful for
126 * debugging, as there's less confusion to do with threads and
127 * class loaders).
128 * <LI>
129 * <B>-i file</B> additional initialisation file (probably called
130 * <TT>gate.xml</TT>). Used for site-wide initialisation by the
131 * start-up scripts.
132 * </UL>
133 */
134 public static void main(String[] args) throws Exception {
135 boolean textMode = false;
136 boolean autoloadingMode = false;
137
138 // process command-line options
139 Getopt g = new Getopt("GATE test suite", args, "tnNasi:");
140 int c;
141 while( (c = g.getopt()) != -1 )
142 switch(c) {
143 case 't':
144 textMode = true;
145 break;
146 case 'n':
147 Gate.setNetConnected(false);
148 break;
149 case 'N':
150 Gate.setNetConnected(false);
151 Gate.setLocalWebServer(false);
152 break;
153 case 'a':
154 autoloadingMode = true;
155 break;
156 case 's':
157 oracleDriver = saiOracleDriver;
158 psqlDriver = saiPSQLDriver;
159 break;
160 // -i gate.xml site-wide init file
161 case 'i':
162 String optionString = g.getOptarg();
163 URL u = null;
164 File f = new File(optionString);
165 try {
166 u = f.toURI().toURL();
167 } catch(MalformedURLException e) {
168 Err.prln("Bad initialisation file: " + optionString);
169 Err.prln(e);
170 System.exit(STATUS_ERROR);
171 }
172 Gate.setSiteConfigFile(f);
173 Out.prln(
174 "Initialisation file " + optionString +
175 " recorded for initialisation"
176 );
177 break;
178 case '?':
179 // leave the warning to getopt
180 return;
181 default:
182 Err.prln("getopt() returned " + c + "\n");
183 } // switch
184
185 // set up arguments for the JUnit test runner
186 String junitArgs[] = new String[2];
187 junitArgs[0] = "-noloading";
188 junitArgs[1] = "gate.TestGate";
189
190 // use the next line if you're running with output to console in text mode:
191 // junitArgs[1] = "-wait";
192
193 // execute the JUnit test runner
194 if(textMode) { // text runner mode
195 junit.textui.TestRunner.main(junitArgs);
196 } else if(autoloadingMode) { // autoloading mode
197 junitArgs[0] = "gate.TestGate";
198 junitArgs[1] = "";
199
200 // NOTE: the DB tests fail under this one (doesn't load oracle driver,
201 // even after the Class.forName call)
202 Class clazz = null;
203 clazz = Class.forName("oracle.jdbc.driver.OracleDriver");
204 clazz = null;
205 junit.swingui.TestRunner.main(junitArgs);
206
207 } else { // by default us the single-run GUI version
208 junit.swingui.TestRunner.main(junitArgs);
209 }
210
211 } // main
212
213 /** GATE test suite. Every test case class has to be
214 * registered here.
215 */
216 public static Test suite() throws Exception {
217 // inialise the library. we re-throw any exceptions thrown by
218 // init, after printing them out, because the junit gui doesn't
219 // say anything more informative than "can't invoke suite" if there's
220 // an exception here...
221
222 try {
223 //get the config if set through a property
224 String configFile = System.getProperty("gate.config");
225 if(configFile != null && configFile.length() > 0){
226 File f = new File(configFile);
227 try {
228 URL u = f.toURI().toURL();
229 } catch(MalformedURLException e) {
230 Err.prln("Bad initialisation file: " + configFile);
231 Err.prln(e);
232 System.exit(STATUS_ERROR);
233 }
234 Gate.setSiteConfigFile(f);
235 }
236 Gate.init();
237 } catch(GateException e) {
238 Out.prln("can't initialise GATE library! exception = " + e);
239 throw(e);
240 }
241
242 TestSuite suite = new TestSuite();
243
244 try {
245 ////////////////////////////////////////////////
246 // Test bench
247 ////////////////////////////////////////////////
248 // set this true to run all tests; false to run the just one below
249 String testName = System.getProperty("gate.testcase");
250 if(testName != null) {
251 // single test class specified in a system property, so run just
252 // that test
253 Class testClass = Class.forName(testName);
254 Method suiteMethod = testClass.getMethod("suite");
255 Test theSuite = (Test)suiteMethod.invoke(null);
256 suite.addTest(theSuite);
257 } else {
258 suite.addTest(TestAnnic.suite());
259 // no test name specified, so run them all
260
261 //WordNet has been moved into a plugin along with the test
262 //suite.addTest(TestWordNet.suite());
263 suite.addTest(TestIndex.suite());
264 suite.addTest(TestPersist.suite());
265 suite.addTest(TestControllers.suite());
266
267 // the db isn't usually available so this will always fail
268 //suite.addTest(TestSecurity.suite());
269 suite.addTest(TestConfig.suite());
270 suite.addTest(TestAnnotation.suite());
271 suite.addTest(TestEmail.suite());
272
273 suite.addTest(TestXml.suite());
274 suite.addTest(TestHtml.suite());
275 suite.addTest(TestSgml.suite());
276 suite.addTest(TestXSchema.suite());
277
278 suite.addTest(TestCreole.suite());
279 suite.addTest(CookBook.suite());
280 suite.addTest(TestFiles.suite());
281 suite.addTest(TestJavac.suite());
282 suite.addTest(TestReload.suite());
283 suite.addTest(TestJape.suite());
284 suite.addTest(TestTemplate.suite());
285 /* The TCL tests rely on the application being started from the
286 * gate directory. This is not possible from the nightly build script.
287 */
288 // suite.addTest(TestJacl.suite());
289 suite.addTest(TestDocument.suite());
290 suite.addTest(TestDocumentStaxUtils.suite());
291 suite.addTest(TestRBTreeMap.suite());
292 suite.addTest(TestCorpus.suite());
293 suite.addTest(TestSerialCorpus.suite());
294 suite.addTest(TestDiffer.suite());
295 //suite.addTest(TestIaa.suite()); Moved this to the IAA plugin
296 suite.addTest(TestAnnotationMerging.suite());
297 suite.addTest(TestClassificationMeasures.suite());
298 //no longer needed as replaced by testPR
299 // suite.addTest(TestTokeniser.suite());
300 suite.addTest(TestGazetteer.suite());
301 // suite.addTest(TestSplitterTagger.suite());
302 suite.addTest(TestFeatureMap.suite());
303 suite.addTest(TestTools.suite());
304 suite.addTest(TestCreoleAnnotationHandler.suite());
305 suite.addTest(TestPR.suite());
306 suite.addTest(TestMorph.suite());
307 // suite.addTest(TestMaxentWrapper.suite());
308
309 //test ontotext gazetteer
310 suite.addTest(TestHashGazetteer.suite());
311 suite.addTest(TestRepositioningInfo.suite());
312 suite.addTest(TestFlexibleGazetteer.suite());
313
314 // Dynamic creole registration
315 suite.addTest(DynamicRegistrationTest.suite());
316
317 } // if(allTests)
318
319 } catch(Exception e) {
320 Out.prln("can't add tests! exception = " + e);
321 throw(e);
322 }
323
324 return suite;
325 } // suite
326
327 } // class TestGate
|