Revision: 19625
          http://sourceforge.net/p/gate/code/19625
Author:   markagreenwood
Date:     2016-10-04 11:10:55 +0000 (Tue, 04 Oct 2016)
Log Message:
-----------
I think that's the rest of the tests renabled that can be, all the remaining 
ones probably need to go into plugins, and even some of the ones I have enabled 
need work to actually test things properly but that is at least a good starting 
point

Modified Paths:
--------------
    gate/branches/sawdust2/gate-core/src/test/java/gate/config/TestConfig.java

Added Paths:
-----------
    gate/branches/sawdust2/gate-core/src/test/java/gate/config/
    
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/DynamicRegistrationTest.java
    
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestCreoleAnnotationHandler.java
    gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestXSchema.java
    gate/branches/sawdust2/gate-core/src/test/java/gate/creole/metadata/

Removed Paths:
-------------
    gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestGate.java
    gate/branches/sawdust2/gate-core/src/test/disabled/gate/config/
    
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestCreoleAnnotationHandler.java
    
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestXSchema.java
    gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/ir/
    gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/metadata/
    gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/test/
    gate/branches/sawdust2/gate-core/src/test/disabled/gate/swing/

Deleted: gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestGate.java
===================================================================
--- gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestGate.java       
2016-10-04 09:25:59 UTC (rev 19624)
+++ gate/branches/sawdust2/gate-core/src/test/disabled/gate/TestGate.java       
2016-10-04 11:10:55 UTC (rev 19625)
@@ -1,216 +0,0 @@
-/*
- *  TestGate.java
- *
- *  Copyright (c) 1995-2012, The University of Sheffield. See the file
- *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
- *
- *  This file is part of GATE (see http://gate.ac.uk/), and is free
- *  software, licenced under the GNU Library General Public License,
- *  Version 2, June 1991 (in the distribution as file licence.html,
- *  and also available at http://gate.ac.uk/gate/licence.html).
- *
- *  Hamish Cunningham, 21/Jan/00
- *
- *  $Id$
- */
-
-package gate;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import gate.annotation.TestAnnotation;
-import gate.config.TestConfig;
-import gate.corpora.TestCorpus;
-import gate.corpora.TestDocument;
-import gate.corpora.TestDocumentStaxUtils;
-import gate.corpora.TestSerialCorpus;
-import gate.corpora.TestTikaFormats;
-import gate.creole.TestControllers;
-import gate.creole.TestCreole;
-import gate.creole.TestCreoleAnnotationHandler;
-import gate.creole.TestXSchema;
-import gate.creole.annic.test.TestAnnic;
-import gate.creole.test.DynamicRegistrationTest;
-import gate.email.TestEmail;
-import gate.html.TestHtml;
-import gate.persist.TestPersist;
-import gate.sgml.TestSgml;
-import gate.util.Err;
-import gate.util.GateException;
-import gate.util.Out;
-import gate.util.TestAnnotationMerging;
-import gate.util.TestClassificationMeasures;
-import gate.util.TestDiffer;
-import gate.util.TestFeatureMap;
-import gate.util.TestFiles;
-import gate.util.TestJavac;
-import gate.util.TestRBTreeMap;
-import gate.util.TestTemplate;
-import gate.util.TestTools;
-import gate.xml.TestRepositioningInfo;
-import gate.xml.TestXml;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/** Top-level entry point for GATE test suite;
-  * "main" will run the JUnit test runner interface.
-  * <P>
-  * Many tests require access to files; generally these files are located
-  * on Web servers. In cases where there is no net connection, or the
-  * Web servers are down, the test files are searched for in the file system
-  * or Jar code base that the system has been loaded from. The search
-  * order for test files is like this:
-  * <UL>
-  * <LI>
-  * <A HREF=http://derwent.dcs.shef.ac.uk:80/gate.ac.uk/>
-  * http://derwent.dcs.shef.ac.uk:80/gate.ac.uk/</A>
-  * <LI>
-  * <A HREF=http://gate.ac.uk:80/>http://gate.ac.uk:80/</A>
-  * <LI>
-  * <A HREF=http://localhost:80/gate.ac.uk/>http://localhost:80/gate.ac.uk/</A>
-  * <LI>
-  * the file system location that the classes came from, e.g.
-  * <TT>z:\gate\classes</TT>, or <TT>jar:....gate.jar</TT>.
-  * </UL>
-  * This search order can be modified by parameters to the main
-  * function (see below).
-  */
-
-public class TestGate {
-
-  /** Status flag for normal exit. */
-  @SuppressWarnings("unused")
-  private static final int STATUS_NORMAL = 0;
-
-  /** Status flag for error exit. */
-  private static final int STATUS_ERROR = 1;
-
-  /** GATE test suite. Every test case class has to be
-    * registered here.
-    */
-  public static Test suite() throws Exception {
-    // inialise the library. we re-throw any exceptions thrown by
-    // init, after printing them out, because the junit gui doesn't
-    // say anything more informative than "can't invoke suite" if there's
-    // an exception here...
-
-    try {
-      //get the config if set through a property
-      String configFile = System.getProperty("gate.config");
-      if(configFile != null && configFile.length() > 0){
-        File f = new File(configFile);
-        try {
-          @SuppressWarnings("unused")
-          URL u = f.toURI().toURL();
-        } catch(MalformedURLException e) {
-          Err.prln("Bad initialisation file: " + configFile);
-          Err.prln(e);
-          System.exit(STATUS_ERROR);
-        }
-        Gate.setSiteConfigFile(f);
-      }
-      Gate.init();
-    } catch(GateException e) {
-      Out.prln("can't initialise GATE library! exception = " + e);
-      throw(e);
-    }
-
-    TestSuite suite = new TestSuite();
-
-    try {
-      ////////////////////////////////////////////////
-      // Test bench
-      ////////////////////////////////////////////////
-      // set this true to run all tests; false to run the just one below
-      String testName = System.getProperty("gate.testcase");
-      if(testName != null) {
-        // single test class specified in a system property, so run just
-        // that test
-        Class<?> testClass = Class.forName(testName);
-        Method suiteMethod = testClass.getMethod("suite");
-        Test theSuite = (Test)suiteMethod.invoke(null);
-        suite.addTest(theSuite);
-      } else {
-        // no test name specified, so run them all
-        suite.addTest(TestUtils.suite());
-        suite.addTest(TestAnnic.suite());
-
-        //WordNet has been moved into a plugin along with the test
-        //suite.addTest(TestWordNet.suite());
-
-        //The IR impls are now in a plugin along with the tests
-        //suite.addTest(TestIndex.suite());
-        suite.addTest(TestPersist.suite());
-        suite.addTest(TestControllers.suite());
-
-        // the db isn't usually available so this will always fail
-        //suite.addTest(TestSecurity.suite());
-        suite.addTest(TestConfig.suite());
-        suite.addTest(TestAnnotation.suite());
-        suite.addTest(TestEmail.suite());
-
-        suite.addTest(TestXml.suite());
-        suite.addTest(TestHtml.suite());
-        suite.addTest(TestSgml.suite());
-        suite.addTest(TestXSchema.suite());
-
-        suite.addTest(TestCreole.suite());
-        suite.addTest(TestFiles.suite());
-        suite.addTest(TestJavac.suite());
-        
-        //Moved into the ANNIE plugin
-        //suite.addTest(TestJape.suite());
-
-        //Moved into the ANNIE plugin
-        //TODO fix these tests so that they work properly
-        //suite.addTest(TestConstraints.suite());
-        
-        suite.addTest(TestTemplate.suite());
-        suite.addTest(TestDocument.suite());
-        suite.addTest(TestDocumentStaxUtils.suite());
-        suite.addTest(TestTikaFormats.suite());
-        suite.addTest(TestRBTreeMap.suite());
-        suite.addTest(TestCorpus.suite());
-        suite.addTest(TestSerialCorpus.suite());
-        suite.addTest(TestDiffer.suite());
-        suite.addTest(TestAnnotationMerging.suite());
-        suite.addTest(TestClassificationMeasures.suite());
-
-        //Moved into the ANNIE plugin
-        //suite.addTest(TestGazetteer.suite());
-        suite.addTest(TestFeatureMap.suite());
-        suite.addTest(TestTools.suite());
-        suite.addTest(TestCreoleAnnotationHandler.suite());
-        
-        //moved into ANNIE 
-        //suite.addTest(TestPR.suite());
-        
-        //Moved nito the Tools plugin
-        //suite.addTest(TestMorph.suite());
-
-        //test ontotext gazetteer
-        //Moved into the ANNIE plugin
-        //suite.addTest(TestHashGazetteer.suite());
-        
-        suite.addTest(TestRepositioningInfo.suite());
-        
-        //Moved nito the Tools plugin
-        //suite.addTest(TestFlexibleGazetteer.suite());
-
-        // Dynamic creole registration
-        suite.addTest(DynamicRegistrationTest.suite());
-
-      } // if(allTests)
-
-    } catch(Exception e) {
-      Out.prln("can't add tests! exception = " + e);
-      throw(e);
-    }
-
-    return suite;
-  } // suite
-
-} // class TestGate

Deleted: 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestCreoleAnnotationHandler.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestCreoleAnnotationHandler.java
     2016-10-04 09:25:59 UTC (rev 19624)
+++ 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestCreoleAnnotationHandler.java
     2016-10-04 11:10:55 UTC (rev 19625)
@@ -1,143 +0,0 @@
-/*
- *  TestCreoleAnnotationHandler.java
- *
- *  Copyright (c) 2008, The University of Sheffield.
- *
- *  This file is part of GATE (see http://gate.ac.uk/), and is free
- *  software, licenced under the GNU Library General Public License,
- *  Version 2, June 1991 (in the distribution as file licence.html,
- *  and also available at http://gate.ac.uk/gate/licence.html).
- *
- *  Ian Roberts, 27/Jul/2008
- *
- *  $Id$
- */
-
-package gate.creole;
-
-import java.net.URL;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.ElementNameQualifier;
-import org.custommonkey.xmlunit.XMLUnit;
-import org.jdom.input.SAXBuilder;
-import org.jdom.output.DOMOutputter;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-import gate.Gate;
-import gate.Plugin;
-import gate.corpora.TestDocument;
-import gate.util.GateException;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test for the CreoleAnnotationHandler, compares the XML produced by the
- * annotation handler to an expected result.
- */
-public class TestCreoleAnnotationHandler extends TestCase {
-
-  private SAXBuilder jdomBuilder = new SAXBuilder();
-
-  private DOMOutputter jdom2dom = new DOMOutputter();
-
-  private DocumentBuilderFactory jaxpFactory = 
DocumentBuilderFactory.newInstance();
-
-  /** Construction */
-  public TestCreoleAnnotationHandler(String name) throws GateException {
-    super(name);
-  }
-
-  @Override
-  public void setUp() throws Exception {
-    // Initialise the GATE library and creole register
-    Gate.init();
-
-    XMLUnit.setIgnoreComments(true);
-    XMLUnit.setIgnoreWhitespace(true);
-    XMLUnit.setIgnoreAttributeOrder(true);
-  }
-
-  /**
-   * Take a skeleton creole.xml file, process the annotations on the classes it
-   * mentions and compare the resulting XML to the expected result.
-   */
-  public void testCreoleAnnotationHandler() throws Exception {
-    URL originalUrl = new 
URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/initial-creole.xml");
-    org.jdom.Document creoleXml =
-      jdomBuilder.build(originalUrl.openStream());
-    CreoleAnnotationHandler processor = new CreoleAnnotationHandler(new 
Plugin.Directory(new 
URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/")));
-    processor.processAnnotations(creoleXml);
-
-    URL expectedURL = new 
URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/expected-creole.xml");
-
-    // XMLUnit requires the expected and actual results as W3C DOM rather than
-    // JDOM
-    DocumentBuilder docBuilder = jaxpFactory.newDocumentBuilder();
-    org.w3c.dom.Document targetXmlDOM =
-      docBuilder.parse(expectedURL.openStream());
-
-    org.w3c.dom.Document actualXmlDOM = jdom2dom.output(creoleXml);
-
-    Diff diff = XMLUnit.compareXML(targetXmlDOM, actualXmlDOM);
-
-    // compare parameter elements with the same NAME, resources with the same
-    // CLASS, and all other elements that have the same element name
-    diff.overrideElementQualifier(new ElementNameQualifier() {
-      @Override
-      public boolean qualifyForComparison(Element control, Element test) {
-        if("PARAMETER".equals(control.getTagName()) && 
"PARAMETER".equals(test.getTagName())) {
-          return 
control.getAttribute("NAME").equals(test.getAttribute("NAME"));
-        }
-        else if("RESOURCE".equals(control.getTagName()) && 
"RESOURCE".equals(test.getTagName())) {
-          String controlClass = findClass(control);
-          String testClass = findClass(test);
-          return (controlClass == null) ? (testClass == null)
-                    : controlClass.equals(testClass);
-        }
-        else {
-          return super.qualifyForComparison(control, test);
-        }
-      }
-
-      private String findClass(Element resource) {
-        Node node = resource.getFirstChild();
-        while(node != null && !"CLASS".equals(node.getNodeName())) {
-          node = node.getNextSibling();
-        }
-
-        if(node != null) {
-          return node.getTextContent();
-        }
-        else {
-          return null;
-        }
-      }
-    });
-
-    // do the comparison!
-    boolean match = diff.similar();
-    if(!match) {
-      // if comparison failed, output the "actual" result document for
-      // debugging purposes
-      System.err.println("---------actual-----------");        
-      new XMLOutputter(Format.getPrettyFormat()).output(creoleXml, System.err);
-    }
-
-    assertTrue("XML produced by annotation handler does not match expected: "
-        + diff.toString() , match);
-  }
-
-  /** Test suite routine for the test runner */
-  public static Test suite() {
-    return new TestSuite(TestCreoleAnnotationHandler.class);
-  } // suite
-
-}

Deleted: 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestXSchema.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestXSchema.java 
    2016-10-04 09:25:59 UTC (rev 19624)
+++ 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestXSchema.java 
    2016-10-04 11:10:55 UTC (rev 19625)
@@ -1,91 +0,0 @@
-/*
- *  TestXSchema.java
- *
- *  Copyright (c) 1995-2012, The University of Sheffield. See the file
- *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
- *
- *  This file is part of GATE (see http://gate.ac.uk/), and is free
- *  software, licenced under the GNU Library General Public License,
- *  Version 2, June 1991 (in the distribution as file licence.html,
- *  and also available at http://gate.ac.uk/gate/licence.html).
- *
- *  Cristian URSU, 11/Octomber/2000
- *
- *  $Id$
- */
-
-package gate.creole;
-
-import gate.Factory;
-import gate.FeatureMap;
-import gate.Gate;
-import gate.corpora.TestDocument;
-import gate.util.Out;
-
-import java.io.ByteArrayInputStream;
-import java.net.URL;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/** Annotation schemas test class.
-  */
-public class TestXSchema extends TestCase
-{
-  /** Debug flag */
-  private static final boolean DEBUG = false;
-
-  /** Construction */
-  public TestXSchema(String name) { super(name); }
-
-  /** Fixture set up */
-  @Override
-  public void setUp() {
-  } // setUp
-
-  /** A test */
-  public void testFromAndToXSchema() throws Exception {
-
-    //esourceData resData = 
Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
-
-    FeatureMap parameters = Factory.newFeatureMap();
-    parameters.put(
-      AnnotationSchema.FILE_URL_PARAM_NAME, new 
URL(TestDocument.getTestServerName()+"tests/xml/POSSchema.xml"));
-
-    AnnotationSchema annotSchema = (AnnotationSchema)
-      Factory.createResource("gate.creole.AnnotationSchema", parameters);
-
-    String s = annotSchema.toXSchema();
-    // write back the XSchema fom memory
-    // File file = Files.writeTempFile(new ByteArrayInputStream(s.getBytes()));
-    // load it again.
-    //annotSchema.fromXSchema(file.toURI().toURL());
-    annotSchema.fromXSchema(new ByteArrayInputStream(s.getBytes()));
-  } // testFromAndToXSchema()
-
-  /** Test creation of annotation schemas via gate.Factory */
-  public void testFactoryCreation() throws Exception {
-
-    ResourceData resData = 
Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
-
-    FeatureMap parameters = Factory.newFeatureMap();
-    parameters.put(
-      AnnotationSchema.FILE_URL_PARAM_NAME, new 
URL(TestDocument.getTestServerName()+"tests/xml/POSSchema.xml"));
-
-    AnnotationSchema schema = (AnnotationSchema)
-      Factory.createResource("gate.creole.AnnotationSchema", parameters);
-
-    if(DEBUG) {
-      Out.prln("schema RD: " + resData);
-      Out.prln("schema: " + schema);
-    }
-
-  } // testFactoryCreation()
-
-  /** Test suite routine for the test runner */
-  public static Test suite() {
-    return new TestSuite(TestXSchema.class);
-  } // suite
-
-} // class TestXSchema

Modified: 
gate/branches/sawdust2/gate-core/src/test/java/gate/config/TestConfig.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/config/TestConfig.java  
    2016-10-04 09:25:59 UTC (rev 19624)
+++ gate/branches/sawdust2/gate-core/src/test/java/gate/config/TestConfig.java  
2016-10-04 11:10:55 UTC (rev 19625)
@@ -16,24 +16,22 @@
 
 package gate.config;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
 import gate.CreoleRegister;
 import gate.Gate;
 import gate.GateConstants;
+import gate.Plugin;
 import gate.corpora.TestDocument;
 import gate.util.Files;
 import gate.util.GateException;
 import gate.util.OptionsMap;
 import gate.util.Out;
 import gate.util.Strings;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-
-import junit.framework.Test;
 import junit.framework.TestCase;
-import junit.framework.TestSuite;
 
 /** CREOLE test class
   */
@@ -42,14 +40,16 @@
   /** Debug flag */
   private static final boolean DEBUG = false;
 
-  /** Construction */
-  public TestConfig(String name) throws GateException { super(name); }
 
   /** Fixture set up */
   @Override
   public void setUp() throws Exception {
+    if (!Gate.isInitialised()) {
+      Gate.runInSandbox(true);
+      Gate.init();
+    }
     CreoleRegister register = Gate.getCreoleRegister();
-    register.registerDirectories(new 
URL(TestDocument.getTestServerName()+"tests"));
+    register.registerPlugin(new Plugin.Directory(new 
URL(TestDocument.getTestServerName()+"tests")));
   } // setUp
 
   /** Put things back as they should be after running tests
@@ -59,7 +59,6 @@
   public void tearDown() throws Exception {
     CreoleRegister register = Gate.getCreoleRegister();
     register.clear();
-    Gate.init();
   } // tearDown
 
   /**
@@ -136,8 +135,16 @@
 
   /** Test config updating */
   public void testConfigUpdating() throws Exception {
+    
+    //TODO try and fix this in some way
+    // Don't test if there is no file. Should probably test with a static file
+    // in the resources instead of relying on the running user
+    if (Gate.getUserConfigFile() == null) return;
+    
     // clear the gate config so we don't write values from the
     // system initialisation into the test file
+        
+    
     OptionsMap configMap = Gate.getUserConfig();
     configMap.clear();
 
@@ -195,6 +202,11 @@
 
   /** Test session state file naming */
   public void testSessionStateFileNaming() throws Exception {
+    
+    //TODO fix this
+    //again we can't test these thinfs if there is no file to test
+    if (Gate.getUserSessionFile() == null) return;
+    
     String fileSep = Strings.getFileSep();
     if(DEBUG) {
       Out.prln("file sep is: " + fileSep);
@@ -235,9 +247,4 @@
 
   } // testConfigFileNaming
 
-  /** Test suite routine for the test runner */
-  public static Test suite() {
-    return new TestSuite(TestConfig.class);
-  } // suite
-
 } // class TestConfig

Copied: 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/DynamicRegistrationTest.java
 (from rev 19624, 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/test/DynamicRegistrationTest.java)
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/DynamicRegistrationTest.java
                             (rev 0)
+++ 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/DynamicRegistrationTest.java
     2016-10-04 11:10:55 UTC (rev 19625)
@@ -0,0 +1,60 @@
+/*
+ *  DynamicRegistrationTest.java
+ *
+ *  Copyright (c) 2010, The University of Sheffield. See the file
+ *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ *  This file is part of GATE (see http://gate.ac.uk/), and is free
+ *  software, licenced under the GNU Library General Public License,
+ *  Version 2, June 1991 (in the distribution as file licence.html,
+ *  and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ */
+
+package gate.creole;
+
+import gate.Corpus;
+import gate.Document;
+import gate.Factory;
+import gate.Gate;
+import gate.Plugin;
+import gate.ProcessingResource;
+import gate.creole.metadata.CreoleResource;
+import junit.framework.TestCase;
+
+/**
+ * Test case for the dynamic registration system. Intended for use inside of 
TestGate.
+ *
+ */
+public class DynamicRegistrationTest extends TestCase {
+
+  @CreoleResource(name = "This is a test")
+  public static class TestResource extends AbstractLanguageAnalyser {
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public void execute() throws ExecutionException {
+
+    }
+  }
+
+
+  public void testDynamicRegistration() throws Exception {
+    Gate.getCreoleRegister().registerPlugin(new 
Plugin.Component(TestResource.class));
+
+    SerialAnalyserController controller = 
(SerialAnalyserController)Factory.createResource("gate.creole.SerialAnalyserController",
+            Factory.newFeatureMap(),
+            Factory.newFeatureMap(),
+            "basicRun");
+    ProcessingResource testResource = (ProcessingResource)
+      Factory.createResource(TestResource.class.getName());
+    controller.add(testResource);
+    Corpus corpus = Factory.newCorpus("basicTestCorpus");
+    String engText = "This is the cereal shot from gnus.";
+    Document doc = Factory.newDocument(engText);
+    corpus.add(doc);
+    controller.setCorpus(corpus);
+    controller.setDocument(doc);
+    controller.execute();
+  }
+}

Copied: 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestCreoleAnnotationHandler.java
 (from rev 19624, 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestCreoleAnnotationHandler.java)
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestCreoleAnnotationHandler.java
                         (rev 0)
+++ 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestCreoleAnnotationHandler.java
 2016-10-04 11:10:55 UTC (rev 19625)
@@ -0,0 +1,143 @@
+/*
+ *  TestCreoleAnnotationHandler.java
+ *
+ *  Copyright (c) 2008, The University of Sheffield.
+ *
+ *  This file is part of GATE (see http://gate.ac.uk/), and is free
+ *  software, licenced under the GNU Library General Public License,
+ *  Version 2, June 1991 (in the distribution as file licence.html,
+ *  and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ *  Ian Roberts, 27/Jul/2008
+ *
+ *  $Id$
+ */
+
+package gate.creole;
+
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.ElementNameQualifier;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.DOMOutputter;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import gate.Gate;
+import gate.Plugin;
+import gate.corpora.TestDocument;
+import gate.util.GateException;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test for the CreoleAnnotationHandler, compares the XML produced by the
+ * annotation handler to an expected result.
+ */
+public class TestCreoleAnnotationHandler extends TestCase {
+
+  private SAXBuilder jdomBuilder = new SAXBuilder();
+
+  private DOMOutputter jdom2dom = new DOMOutputter();
+
+  private DocumentBuilderFactory jaxpFactory = 
DocumentBuilderFactory.newInstance();
+
+  /** Construction */
+  public TestCreoleAnnotationHandler(String name) throws GateException {
+    super(name);
+  }
+
+  @Override
+  public void setUp() throws Exception {
+    // Initialise the GATE library and creole register
+    Gate.init();
+
+    XMLUnit.setIgnoreComments(true);
+    XMLUnit.setIgnoreWhitespace(true);
+    XMLUnit.setIgnoreAttributeOrder(true);
+  }
+
+  /**
+   * Take a skeleton creole.xml file, process the annotations on the classes it
+   * mentions and compare the resulting XML to the expected result.
+   */
+  public void testCreoleAnnotationHandler() throws Exception {
+    URL originalUrl = new 
URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/initial-creole.xml");
+    org.jdom.Document creoleXml =
+      jdomBuilder.build(originalUrl.openStream());
+    CreoleAnnotationHandler processor = new CreoleAnnotationHandler(new 
Plugin.Directory(new 
URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/")));
+    processor.processAnnotations(creoleXml);
+
+    URL expectedURL = new 
URL(TestDocument.getTestServerName()+"tests/creole-annotation-handler/expected-creole.xml");
+
+    // XMLUnit requires the expected and actual results as W3C DOM rather than
+    // JDOM
+    DocumentBuilder docBuilder = jaxpFactory.newDocumentBuilder();
+    org.w3c.dom.Document targetXmlDOM =
+      docBuilder.parse(expectedURL.openStream());
+
+    org.w3c.dom.Document actualXmlDOM = jdom2dom.output(creoleXml);
+
+    Diff diff = XMLUnit.compareXML(targetXmlDOM, actualXmlDOM);
+
+    // compare parameter elements with the same NAME, resources with the same
+    // CLASS, and all other elements that have the same element name
+    diff.overrideElementQualifier(new ElementNameQualifier() {
+      @Override
+      public boolean qualifyForComparison(Element control, Element test) {
+        if("PARAMETER".equals(control.getTagName()) && 
"PARAMETER".equals(test.getTagName())) {
+          return 
control.getAttribute("NAME").equals(test.getAttribute("NAME"));
+        }
+        else if("RESOURCE".equals(control.getTagName()) && 
"RESOURCE".equals(test.getTagName())) {
+          String controlClass = findClass(control);
+          String testClass = findClass(test);
+          return (controlClass == null) ? (testClass == null)
+                    : controlClass.equals(testClass);
+        }
+        else {
+          return super.qualifyForComparison(control, test);
+        }
+      }
+
+      private String findClass(Element resource) {
+        Node node = resource.getFirstChild();
+        while(node != null && !"CLASS".equals(node.getNodeName())) {
+          node = node.getNextSibling();
+        }
+
+        if(node != null) {
+          return node.getTextContent();
+        }
+        else {
+          return null;
+        }
+      }
+    });
+
+    // do the comparison!
+    boolean match = diff.similar();
+    if(!match) {
+      // if comparison failed, output the "actual" result document for
+      // debugging purposes
+      System.err.println("---------actual-----------");        
+      new XMLOutputter(Format.getPrettyFormat()).output(creoleXml, System.err);
+    }
+
+    assertTrue("XML produced by annotation handler does not match expected: "
+        + diff.toString() , match);
+  }
+
+  /** Test suite routine for the test runner */
+  public static Test suite() {
+    return new TestSuite(TestCreoleAnnotationHandler.class);
+  } // suite
+
+}

Copied: 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestXSchema.java 
(from rev 19624, 
gate/branches/sawdust2/gate-core/src/test/disabled/gate/creole/TestXSchema.java)
===================================================================
--- gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestXSchema.java 
                        (rev 0)
+++ gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestXSchema.java 
2016-10-04 11:10:55 UTC (rev 19625)
@@ -0,0 +1,90 @@
+/*
+ *  TestXSchema.java
+ *
+ *  Copyright (c) 1995-2012, The University of Sheffield. See the file
+ *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ *  This file is part of GATE (see http://gate.ac.uk/), and is free
+ *  software, licenced under the GNU Library General Public License,
+ *  Version 2, June 1991 (in the distribution as file licence.html,
+ *  and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ *  Cristian URSU, 11/Octomber/2000
+ *
+ *  $Id$
+ */
+
+package gate.creole;
+
+import gate.Factory;
+import gate.FeatureMap;
+import gate.Gate;
+import gate.corpora.TestDocument;
+import gate.util.Out;
+
+import java.io.ByteArrayInputStream;
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/** Annotation schemas test class.
+  */
+public class TestXSchema extends TestCase
+{
+  /** Debug flag */
+  private static final boolean DEBUG = false;
+
+  /** Construction */
+  public TestXSchema(String name) { super(name); }
+
+  /** Fixture set up */
+  @Override
+  public void setUp() throws Exception {
+    if (!Gate.isInitialised()) {
+      Gate.runInSandbox(true);
+      Gate.init();
+    }
+  } // setUp
+
+  /** A test */
+  public void testFromAndToXSchema() throws Exception {
+
+    //esourceData resData = 
Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
+
+    FeatureMap parameters = Factory.newFeatureMap();
+    parameters.put(
+      AnnotationSchema.FILE_URL_PARAM_NAME, new 
URL(TestDocument.getTestServerName()+"tests/xml/POSSchema.xml"));
+
+    AnnotationSchema annotSchema = (AnnotationSchema)
+      Factory.createResource("gate.creole.AnnotationSchema", parameters);
+
+    String s = annotSchema.toXSchema();
+    // write back the XSchema fom memory
+    // File file = Files.writeTempFile(new ByteArrayInputStream(s.getBytes()));
+    // load it again.
+    //annotSchema.fromXSchema(file.toURI().toURL());
+    annotSchema.fromXSchema(new ByteArrayInputStream(s.getBytes()));
+  } // testFromAndToXSchema()
+
+  /** Test creation of annotation schemas via gate.Factory */
+  public void testFactoryCreation() throws Exception {
+
+    ResourceData resData = 
Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
+
+    FeatureMap parameters = Factory.newFeatureMap();
+    parameters.put(
+      AnnotationSchema.FILE_URL_PARAM_NAME, new 
URL(TestDocument.getTestServerName()+"tests/xml/POSSchema.xml"));
+
+    AnnotationSchema schema = (AnnotationSchema)
+      Factory.createResource("gate.creole.AnnotationSchema", parameters);
+
+    if(DEBUG) {
+      Out.prln("schema RD: " + resData);
+      Out.prln("schema: " + schema);
+    }
+
+  } // testFactoryCreation()
+
+} // class TestXSchema

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to