| TestXSchema |

    1   /*
    2    *  TestXSchema.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   *  Cristian URSU, 11/Octomber/2000
    12   *
    13   *  $Id: TestXSchema.java,v 1.11 2001/02/08 13:56:40 valyt Exp $
    14   */
    15
    16  package gate.creole;
    17
    18  import java.util.*;
    19  import java.io.*;
    20  import java.net.*;
    21
    22  import junit.framework.*;
    23
    24  import gate.*;
    25  import gate.util.*;
    26
    27  /** Annotation schemas test class.
    28    */
    29  public class TestXSchema extends TestCase
    30  {
    31    /** Debug flag */
    32    private static final boolean DEBUG = false;
    33
    34    /** Construction */
    35    public TestXSchema(String name) { super(name); }
    36
    37    /** Fixture set up */
    38    public void setUp() {
    39    } // setUp
    40
    41    /** A test */
    42    public void testFromAndToXSchema() throws Exception {
    43
    44      ResourceData resData = (ResourceData)
    45        Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
    46
    47      FeatureMap parameters = Factory.newFeatureMap();
    48      parameters.put("xmlFileUrl", Gate.getUrl("tests/xml/POSSchema.xml"));
    49
    50      AnnotationSchema annotSchema = (AnnotationSchema)
    51        Factory.createResource("gate.creole.AnnotationSchema", parameters);
    52
    53      String s = annotSchema.toXSchema();
    54      // write back the XSchema fom memory
    55      // File file = Files.writeTempFile(new ByteArrayInputStream(s.getBytes()));
    56      // load it again.
    57      //annotSchema.fromXSchema(file.toURL());
    58      annotSchema.fromXSchema(new ByteArrayInputStream(s.getBytes()));
    59    } // testFromAndToXSchema()
    60
    61    /** Test creation of annotation schemas via gate.Factory */
    62    public void testFactoryCreation() throws Exception {
    63
    64      ResourceData resData = (ResourceData)
    65        Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
    66
    67      FeatureMap parameters = Factory.newFeatureMap();
    68      parameters.put("xmlFileUrl", Gate.getUrl("tests/xml/POSSchema.xml"));
    69
    70      AnnotationSchema schema = (AnnotationSchema)
    71        Factory.createResource("gate.creole.AnnotationSchema", parameters);
    72
    73      if(DEBUG) {
    74        Out.prln("schema RD: " + resData);
    75        Out.prln("schema: " + schema);
    76      }
    77
    78    } // testFactoryCreation()
    79
    80    /** Test suite routine for the test runner */
    81    public static Test suite() {
    82      return new TestSuite(TestXSchema.class);
    83    } // suite
    84
    85  } // class TestXSchema
    86

| TestXSchema |