TestXSchema.java
01 /*
02  *  TestXSchema.java
03  *
04  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
05  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
06  *
07  *  This file is part of GATE (see http://gate.ac.uk/), and is free
08  *  software, licenced under the GNU Library General Public License,
09  *  Version 2, June 1991 (in the distribution as file licence.html,
10  *  and also available at http://gate.ac.uk/gate/licence.html).
11  *
12  *  Cristian URSU, 11/Octomber/2000
13  *
14  *  $Id: TestXSchema.java 12718 2010-06-03 14:39:03Z thomas_heitz $
15  */
16 
17 package gate.creole;
18 
19 import java.io.ByteArrayInputStream;
20 
21 import junit.framework.*;
22 
23 import gate.*;
24 import gate.util.Out;
25 
26 /** Annotation schemas test class.
27   */
28 public class TestXSchema extends TestCase
29 {
30   /** Debug flag */
31   private static final boolean DEBUG = false;
32 
33   /** Construction */
34   public TestXSchema(String name) { super(name)}
35 
36   /** Fixture set up */
37   public void setUp() {
38   // setUp
39 
40   /** A test */
41   public void testFromAndToXSchema() throws Exception {
42 
43     ResourceData resData = (ResourceData)
44       Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
45 
46     FeatureMap parameters = Factory.newFeatureMap();
47     parameters.put(
48       AnnotationSchema.FILE_URL_PARAM_NAME, 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.toURI().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(
69       AnnotationSchema.FILE_URL_PARAM_NAME, Gate.getUrl("tests/xml/POSSchema.xml"));
70 
71     AnnotationSchema schema = (AnnotationSchema)
72       Factory.createResource("gate.creole.AnnotationSchema", parameters);
73 
74     if(DEBUG) {
75       Out.prln("schema RD: " + resData);
76       Out.prln("schema: " + schema);
77     }
78 
79   // testFactoryCreation()
80 
81   /** Test suite routine for the test runner */
82   public static Test suite() {
83     return new TestSuite(TestXSchema.class);
84   // suite
85 
86 // class TestXSchema