1   /*
2    *  TestXSchema.java
3    *
4    *  Copyright (c) 1998-2005, 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.15 2005/01/11 13:51:31 ian Exp $
14   */
15  
16  package gate.creole;
17  
18  import java.io.ByteArrayInputStream;
19  
20  import junit.framework.*;
21  
22  import gate.*;
23  import gate.util.Out;
24  
25  /** Annotation schemas test class.
26    */
27  public class TestXSchema extends TestCase
28  {
29    /** Debug flag */
30    private static final boolean DEBUG = false;
31  
32    /** Construction */
33    public TestXSchema(String name) { super(name); }
34  
35    /** Fixture set up */
36    public void setUp() {
37    } // setUp
38  
39    /** A test */
40    public void testFromAndToXSchema() throws Exception {
41  
42      ResourceData resData = (ResourceData)
43        Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
44  
45      FeatureMap parameters = Factory.newFeatureMap();
46      parameters.put(
47        AnnotationSchema.FILE_URL_PARAM_NAME, Gate.getUrl("tests/xml/POSSchema.xml"));
48  
49      AnnotationSchema annotSchema = (AnnotationSchema)
50        Factory.createResource("gate.creole.AnnotationSchema", parameters);
51  
52      String s = annotSchema.toXSchema();
53      // write back the XSchema fom memory
54      // File file = Files.writeTempFile(new ByteArrayInputStream(s.getBytes()));
55      // load it again.
56      //annotSchema.fromXSchema(file.toURL());
57      annotSchema.fromXSchema(new ByteArrayInputStream(s.getBytes()));
58    } // testFromAndToXSchema()
59  
60    /** Test creation of annotation schemas via gate.Factory */
61    public void testFactoryCreation() throws Exception {
62  
63      ResourceData resData = (ResourceData)
64        Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
65  
66      FeatureMap parameters = Factory.newFeatureMap();
67      parameters.put(
68        AnnotationSchema.FILE_URL_PARAM_NAME, 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