1   /*
2    *  TestCreole.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   *  Hamish Cunningham, 16/Mar/00
12   *
13   *  $Id: TestCreole.java,v 1.59 2005/01/11 13:51:31 ian Exp $
14   */
15  
16  package gate.creole;
17  
18  import java.beans.*;
19  import java.lang.reflect.Method;
20  import java.net.URL;
21  import java.util.*;
22  
23  import junit.framework.*;
24  
25  import gate.*;
26  import gate.util.GateException;
27  import gate.util.Out;
28  
29  /** CREOLE test class
30    */
31  public class TestCreole extends TestCase
32  {
33    /** Debug flag */
34    private static final boolean DEBUG = false;
35  
36    /** Construction */
37    public TestCreole(String name) throws GateException { super(name); }
38  
39    /** Local shorthand for the CREOLE register */
40    private CreoleRegister reg;
41  
42    /** Fixture set up */
43    public void setUp() throws Exception {
44      // Initialise the GATE library and creole register
45      Gate.init();
46  
47      // clear the register and the creole directory set
48      reg = Gate.getCreoleRegister();
49      reg.clear();
50  
51      // find a URL for finding test files and add to the directory set
52      URL testUrl = Gate.getUrl("tests/");
53  //    reg.registerDirectories(testUrl);
54      reg.addDirectory(testUrl);
55      reg.registerDirectories();
56      
57      if(DEBUG) {
58        Iterator iter = reg.values().iterator();
59        while(iter.hasNext()) Out.println(iter.next());
60      }
61    } // setUp
62  
63    /** Put things back as they should be after running tests
64      * (reinitialise the CREOLE register).
65      */
66    public void tearDown() throws Exception {
67      reg.clear();
68      Gate.init();
69    } // tearDown
70  
71    /** Test the getInstances methods on CreoleRegister */
72    public void testInstanceLists() throws Exception {
73      // misc locals
74      List l;
75      CreoleRegister cr = Gate.getCreoleRegister();
76      Iterator iter;
77      ResourceData resData = null;
78      Resource res = null;
79      int numLrInstances = 0;
80  
81      // Get the lists of types
82      Set vrTypes = reg.getVrTypes();
83      Set prTypes = reg.getPrTypes();
84      Set lrTypes = reg.getLrTypes();
85  
86      // The only instances of any type should be autoloading ones
87      l = cr.getVrInstances();
88      if(! allAutoloaders(l))
89        fail(" non-autoloading resources already present (1)");
90      l = cr.getLrInstances();
91      numLrInstances = l.size();
92      if(! allAutoloaders(l))
93        fail(" non-autoloading resources already present (2)");
94      l = cr.getPrInstances();
95      if(! allAutoloaders(l))
96        fail(" non-autoloading resources already present (3)");
97  
98      // Create an LR
99      FeatureMap params = Factory.newFeatureMap();
100     params.put("features", Factory.newFeatureMap());
101     params.put(Document.DOCUMENT_URL_PARAMETER_NAME, Gate.getUrl("tests/doc0.html")
102     );
103     res = Factory.createResource("gate.corpora.DocumentImpl", params);
104 
105     // lr instances list should be one longer now
106     if(! (cr.getLrInstances().size() == numLrInstances + 1))
107       fail("wrong number of LRs");
108 
109     // Create another LR
110     params = Factory.newFeatureMap();
111     params.put("features", Factory.newFeatureMap());
112     params.put(Document.DOCUMENT_URL_PARAMETER_NAME, Gate.getUrl("tests/doc0.html")
113     );
114     res = Factory.createResource("gate.corpora.DocumentImpl", params);
115 
116     // lr instances list should be two longer now
117     if(! (cr.getLrInstances().size() == numLrInstances + 2))
118       fail("wrong number of LRs");
119 
120     // we should have two instances of type document
121     l = cr.getLrInstances("gate.corpora.DocumentImpl");
122     if(l.size() != 2)
123       fail("wrong number of documents");
124   } // testInstanceLists
125 
126 
127   /** Test view registration */
128   public void testViews() throws Exception {
129     List smallViews1 =
130                   reg.getSmallVRsForResource("gate.persist.SerialDataStore");
131     String className1 = new String("");
132     if (smallViews1!= null && smallViews1.size()>0)
133       className1 = (String)smallViews1.get(0);
134     assertTrue(
135       "Found "+className1+
136       " as small viewer for gate.persist.SerialDataStore, "+
137       "instead  of gate.gui.SerialDatastoreViewer",
138       smallViews1.size() == 1 &&
139       "gate.gui.SerialDatastoreViewer".equals(className1)
140     );
141 
142     List largeViews1 =
143                   reg.getLargeVRsForResource("gate.Corpus");
144     assertTrue(
145       "Found "+largeViews1.size()+" wich are " +largeViews1 +
146       " as large viewers for gate.Corpus, "+
147      "instead  of 2 which are [gate.gui.CorpusEditor, gate.gui.FeaturesEditor]",
148       largeViews1.size() == 2
149     );
150 
151     List largeViews2 =
152                   reg.getLargeVRsForResource("gate.Document");
153     assertTrue(
154       "Found "+largeViews2.size()+" wich are " +largeViews2 +
155       " as large viewers for gate.Document, "+
156      "instead  of 2 which are [gate.gui.DocumentEditor, gate.gui.FeaturesEditor]",
157       largeViews2.size() == 2
158     );
159 
160     List annotViews1 =
161                   reg.getAnnotationVRs();
162     assertTrue(
163       "Found "+annotViews1.size()+" wich are " +annotViews1 +
164       " as annotation viewers for all types annotations, "+
165      "instead  of 2 which are [gate.gui.SchemaAnnotationEditor,"+
166      " gate.gui.UnrestrictedAnnotationEditor]",
167       annotViews1.size() == 2
168     );
169   } // testViews()
170 
171   /** Utility method to check that a list of resources are all
172     * auto-loading.
173     */
174   protected boolean allAutoloaders(List l) {
175     if(l != null) {
176       Resource res = null;
177       ResourceData resData = null;
178       CreoleRegister cr = Gate.getCreoleRegister();
179       Iterator iter = l.iterator();
180       while(iter.hasNext()) {
181         res = (Resource) iter.next();
182         if(DEBUG) Out.prln(res);
183         resData = (ResourceData) cr.get(res.getClass().getName());
184         if(DEBUG) Out.prln(resData);
185         if(! resData.isAutoLoading())
186           return false;
187       }
188     }
189 
190     return true;
191   } // allAutoloaders
192 
193   /** Test resource discovery */
194   public void testDiscovery() throws Exception {
195 
196     CreoleRegister reg = Gate.getCreoleRegister();
197     if(DEBUG) {
198       Iterator iter = reg.values().iterator();
199       while(iter.hasNext()) Out.println(iter.next());
200     }
201 
202     ResourceData rd = (ResourceData)
203       reg.get("gate.creole.tokeniser.DefaultTokeniser");
204     assertNotNull("couldn't find unicode tok in register of resources", rd);
205     assertTrue(rd.getName().equals("ANNIE Unicode Tokeniser"));
206 
207     String docFormatName = "gate.corpora.XmlDocumentFormat";
208     ResourceData xmlDocFormatRD = (ResourceData) reg.get(docFormatName);
209     assertTrue(xmlDocFormatRD.getName().equals("Sheffield XML Document Format"));
210     assertTrue(xmlDocFormatRD.isAutoLoading());
211     assertTrue(xmlDocFormatRD.getJarFileName().equals("ShefDocumentFormats.jar"));
212   } // testDiscovery()
213 
214   /** Test resource metadata */
215   public void testMetadata() throws Exception {
216 
217     // get some res data from the register
218     ResourceData pr1rd = (ResourceData) reg.get("testpkg.TestPR1");
219     ResourceData pr2rd = (ResourceData) reg.get("testpkg.TestPR2");
220     assertTrue(pr1rd != null & pr2rd != null);
221     assertTrue(pr2rd.getName().equals("Sheffield Test PR 2"));
222 
223     // checks values of parameters of param0 in test pr 1
224     assertTrue(pr1rd.getClassName().equals("testpkg.TestPR1"));
225     Iterator iter = pr1rd.getParameterList().getRuntimeParameters().iterator();
226     Iterator iter2 = null;
227     Parameter param = null;
228     while(iter.hasNext()) {
229       iter2 = ((List) iter.next()).iterator();
230       while(iter2.hasNext()) {
231         param = (Parameter) iter2.next();
232         if(param.typeName.equals("param0"))
233           break;
234       }
235       if(param.typeName.equals("param0"))
236         break;
237     }
238 
239     assertTrue("param0 was null", param != null);
240     assertTrue(param.typeName.equals("java.lang.String"));
241     assertTrue(param.optional);
242     assertTrue(! param.runtime);
243     assertTrue(param.comment == null);
244     assertTrue(param.name.equals("thing"));
245 
246     reg.clear();
247   } // testMetadata()
248 
249   /** Test TOOLS and PRIVATE attributes */
250   public void testToolsAndPrivate() throws Exception {
251     ResourceData pr3rd = (ResourceData) reg.get("testpkg.PrintOutTokens");
252     assertTrue("couldn't get PR3", pr3rd != null);
253     assertTrue("PR3 not a tool", pr3rd.isTool());
254     if(DEBUG) Out.prln(pr3rd.getFeatures());
255 
256     String docFormatName = "gate.corpora.XmlDocumentFormat";
257     ResourceData xmlDocFormatRD = (ResourceData) reg.get(docFormatName);
258     assertTrue("Xml doc format not PRIVATE", xmlDocFormatRD.isPrivate());
259     if(DEBUG) Out.prln(xmlDocFormatRD.getFeatures());
260 
261     // Create an LR
262     FeatureMap params = Factory.newFeatureMap();
263     params.put("features", Factory.newFeatureMap());
264     params.put(Document.DOCUMENT_URL_PARAMETER_NAME, Gate.getUrl("tests/doc0.html"));
265     Resource res = Factory.createResource("gate.corpora.DocumentImpl", params);
266 
267     List publics = reg.getPublicLrInstances();
268     List allLrs = reg.getLrInstances();
269 
270     assertTrue(
271       "wrong number of public LR instances",
272       publics.size() == 1 && allLrs.size() == 3
273     );
274 
275     if(DEBUG) {
276       Iterator iter = publics.iterator();
277       Out.prln("publics:");
278       while(iter.hasNext()) { Out.prln(iter.next()); }
279       iter = allLrs.iterator();
280       Out.prln("allLrs:");
281       while(iter.hasNext()) { Out.prln(iter.next()); }
282     }
283 
284   } // testToolsAndPrivate()
285 
286   /** Test resource loading */
287   public void testLoading() throws Exception {
288 
289     // get some res data from the register
290     assertTrue(
291       "wrong number of resources in the register: " + reg.size(),
292       reg.size() == 15
293     );
294     ResourceData pr1rd = (ResourceData) reg.get("testpkg.TestPR1");
295     ResourceData pr2rd = (ResourceData) reg.get("testpkg.TestPR2");
296     assertTrue("couldn't find PR1/PR2 res data", pr1rd != null && pr2rd != null);
297     assertTrue("wrong name on PR1", pr1rd.getName().equals("Sheffield Test PR 1"));
298 
299     // instantiation
300     ProcessingResource pr1 = (ProcessingResource)
301       Factory.createResource("testpkg.TestPR1", Factory.newFeatureMap());
302     ProcessingResource pr2 = (ProcessingResource)
303       Factory.createResource("testpkg.TestPR2", Factory.newFeatureMap());
304 
305     // run the beasts
306     FeatureMap pr1features = pr1.getFeatures();
307     FeatureMap pr2features = pr2.getFeatures();
308     assertNotNull("PR1 features are null", pr1features);
309     assertTrue(
310       "PR2 got wrong features: " + pr2features,
311       pr2features != null || pr2features.size() != 1
312     );
313     pr1.execute();
314     pr2.execute();
315     assertTrue(
316       "PR1 feature not present",
317       pr1.getFeatures().get("I").equals("have been run, thankyou")
318     );
319     assertTrue(
320       "PR2 feature not present",
321       pr2.getFeatures().get("I").equals("am in a bad mood")
322     );
323 
324     reg.clear();
325   } // testLoading()
326 
327   /** Test resource indexing by class */
328   public void testClassIndex() throws Exception {
329 
330     ResourceData docRd = (ResourceData) reg.get("gate.corpora.DocumentImpl");
331     assertNotNull("couldn't find document res data", docRd);
332     assertTrue(
333       "doc res data has wrong class name",
334       docRd.getClassName().equals("gate.corpora.DocumentImpl")
335     );
336     assertTrue(
337       "doc res data has wrong interface name",
338       docRd.getInterfaceName().equals("gate.Document")
339     );
340 
341     Class docClass = docRd.getResourceClass();
342     assertNotNull("couldn't get doc class", docClass);
343     LanguageResource docRes = (LanguageResource) docClass.newInstance();
344     assertTrue(
345       "instance of doc is wrong type",
346       docRes instanceof LanguageResource &&
347       docRes instanceof gate.Document
348     );
349 
350     reg.clear();
351   } // testClassIndex()
352 
353   /** Test type lists */
354   public void testTypeLists() throws Exception {
355     Set vrs = reg.getVrTypes();
356     Set prs = reg.getPrTypes();
357     Set lrs = reg.getLrTypes();
358 
359     assertTrue("wrong number vrs in reg: " + vrs.size(), vrs.size() == 7);
360     assertTrue("wrong number prs in reg: " + prs.size(), prs.size() == 5);
361     assertTrue("wrong number lrs in reg: " + lrs.size(), lrs.size() == 3);
362   } // testTypeLists()
363 
364   /** Test comments on resources */
365   public void testComments() throws Exception {
366 
367     ResourceData docRd = (ResourceData) reg.get("gate.corpora.DocumentImpl");
368     assertNotNull("testComments: couldn't find document res data", docRd);
369     String comment = docRd.getComment();
370     assertTrue(
371       "testComments: incorrect or missing COMMENT on document",
372       comment != null && comment.equals("GATE document")
373     );
374   } // testComments()
375 
376   /** Test parameter defaults */
377   public void testParameterDefaults1() throws Exception {
378 
379     ResourceData docRd = (ResourceData) reg.get("gate.corpora.DocumentImpl");
380     assertNotNull("Couldn: couldn't find document res data", docRd);
381     if(DEBUG) Out.prln(docRd.getParameterList().getInitimeParameters());
382     ParameterList paramList = docRd.getParameterList();
383     if(DEBUG) Out.prln(docRd);
384 
385     // runtime params - none for a document
386     Iterator iter = paramList.getRuntimeParameters().iterator();
387     assertTrue("Document has runtime params: " + paramList, ! iter.hasNext());
388 
389     // init time params
390     Parameter param = null;
391     iter = paramList.getInitimeParameters().iterator();
392     int paramDisjNumber = -1;
393     while(iter.hasNext()) {
394       List paramDisj = (List) iter.next();
395       Iterator iter2 = paramDisj.iterator();
396       paramDisjNumber++;
397 
398       for(int i=0; iter2.hasNext(); i++) {
399         param = (Parameter) iter2.next();
400 
401         switch(paramDisjNumber) {
402           case 0:
403             assertTrue(
404               "Doc param 0 wrong type: " + param.getTypeName(),
405               param.getTypeName().equals("java.lang.String")
406             );
407             assertTrue(
408               "Doc param 0 wrong name: " + param.getName(),
409               param.getName().equals("sourceUrlName")
410             );
411             Object defaultValue = param.calculateDefaultValue();
412             assertTrue(
413               "Doc param 0 default should be null but was: " + defaultValue,
414               defaultValue == null
415             );
416             break;
417           case 1:
418             assertTrue(
419               "Doc param 1 wrong name: " + param.getName(),
420               param.getName().equals(Document.DOCUMENT_ENCODING_PARAMETER_NAME)
421             );
422             break;
423           case 2:
424             assertTrue(
425               "Doc param 2 wrong name: " + param.getName(),
426               param.getName().equals(Document.DOCUMENT_START_OFFSET_PARAMETER_NAME)
427             );
428             break;
429           case 3:
430             assertTrue(
431               "Doc param 3 wrong name: " + param.getName(),
432               param.getName().equals(Document.DOCUMENT_END_OFFSET_PARAMETER_NAME)
433             );
434             break;
435           default:
436             fail("Doc has more than 4 params; 5th is: " + param);
437         } // switch
438       }
439     }
440 
441   } // testParameterDefaults1()
442 
443   /** Test parameter defaults (2) */
444   public void testParameterDefaults2() throws Exception {
445 
446     ResourceData rd = (ResourceData) reg.get("testpkg.PrintOutTokens");
447     assertNotNull("Couldn't find testpkg.POT res data", rd);
448 
449     // create a document, so that the parameter default will pick it up
450     Factory.newDocument(Gate.getUrl("tests/doc0.html"));
451 
452     ParameterList paramList = rd.getParameterList();
453     if(DEBUG) Out.prln(rd);
454 
455     // init time params - none for this one
456     Iterator iter = paramList.getInitimeParameters().iterator();
457     assertTrue("POT has initime params: " + paramList, ! iter.hasNext());
458 
459     // runtime params
460     Parameter param = null;
461     iter = paramList.getRuntimeParameters().iterator();
462     int paramDisjNumber = -1;
463     while(iter.hasNext()) {
464       List paramDisj = (List) iter.next();
465       Iterator iter2 = paramDisj.iterator();
466       paramDisjNumber++;
467 
468       for(int i=0; iter2.hasNext(); i++) {
469         param = (Parameter) iter2.next();
470 
471         switch(paramDisjNumber) {
472           case 0:
473             assertTrue(
474               "POT param 0 wrong type: " + param.getTypeName(),
475               param.getTypeName().equals("gate.corpora.DocumentImpl")
476             );
477             assertTrue(
478               "POT param 0 wrong name: " + param.getName(),
479               param.getName().equals("document")
480             );
481             Object defaultValue = param.calculateDefaultValue();
482             assertTrue(
483               "POT param 0 default should be Document but is " +
484               defaultValue.getClass().getName(),
485               defaultValue instanceof Document
486             );
487             break;
488           default:
489             fail("POT has more than 1 param; 2nd is: " + param);
490         } // switch
491       }
492     }
493 
494   } // testParameterDefaults2()
495 
496   /** Test param as lists*/
497   public void testParamAsLists() throws Exception{
498     ResourceData rd = (ResourceData) reg.get("testpkg.TestPR3");
499     assertNotNull("Couldn: couldn't find testPR3 res data", rd);
500 
501     ParameterList paramList = rd.getParameterList();
502     // runtime params - none for a document
503     List runTime = paramList.getRuntimeParameters();
504     assertTrue("PR3 should have 4 runtime params: " + paramList, runTime.size()==4);
505   }// End testParamAsLists();
506 
507   /** Test parameters */
508   public void testParameters() throws Exception {
509 
510     ResourceData docRd = (ResourceData) reg.get("gate.corpora.DocumentImpl");
511     assertNotNull("Couldn: couldn't find document res data", docRd);
512 
513     ParameterList paramList = docRd.getParameterList();
514     if(DEBUG) Out.prln(docRd);
515 
516     // runtime params - none for a document
517     Iterator iter = paramList.getRuntimeParameters().iterator();
518     assertTrue("Document has runtime params: " + paramList, ! iter.hasNext());
519 
520     // init time params
521     Parameter param = null;
522     List initimeParams = paramList.getInitimeParameters();
523     int initimeLen = initimeParams.size();
524     assertTrue(
525       "initime params has wrong number of elements: " + initimeLen,
526       initimeLen == 4
527     );
528     iter = initimeParams.iterator();
529     int paramDisjNumber = -1;
530     while(iter.hasNext()) {
531       List paramDisj = (List) iter.next();
532       Iterator iter2 = paramDisj.iterator();
533       paramDisjNumber++;
534 
535       int paramDisjLen = paramDisj.size();
536       assertTrue(
537         "param disj wrong length: " + paramDisjLen,
538         paramDisjLen == 1
539       );
540 
541       for(int i=0; iter2.hasNext(); i++) {
542         param = (Parameter) iter2.next();
543 
544         switch(paramDisjNumber) {
545           case 0:
546             assertTrue(
547               "Doc param 0 wrong type: " + param.getTypeName(),
548               param.getTypeName().equals("java.lang.String")
549             );
550             assertTrue(
551               "Doc param 0 wrong name: " + param.getName(),
552               param.getName().equals("sourceUrlName")
553             );
554             Object defaultValue = param.calculateDefaultValue();
555             assertTrue(
556               "Doc param 0 default should be null but was: " + defaultValue,
557               defaultValue == null
558             );
559             break;
560           case 1:
561             assertTrue(
562               "Doc param 1 wrong name: " + param.getName(),
563               param.getName().equals(Document.DOCUMENT_ENCODING_PARAMETER_NAME)
564             );
565             break;
566           case 2:
567             assertTrue(
568               "Doc param 2 wrong name: " + param.getName(),
569               param.getName().equals(Document.DOCUMENT_START_OFFSET_PARAMETER_NAME)
570             );
571             defaultValue = param.getDefaultValue();
572             break;
573           case 3:
574             assertTrue(
575               "Doc param 3 wrong name: " + param.getName(),
576               param.getName().equals(Document.DOCUMENT_END_OFFSET_PARAMETER_NAME)
577             );
578             break;
579           default:
580             fail("Doc has more than 4 params; 5th is: " + param);
581         } // switch
582       }
583     }
584 
585   } // testParameters()
586 
587   /** Test default run() on processing resources */
588   public void testDefaultRun() throws Exception {
589     ProcessingResource defaultPr = new AbstractProcessingResource() {
590     };
591     boolean gotExceptionAsExpected = false;
592     try {
593       defaultPr.execute();
594     } catch(ExecutionException e) {
595       gotExceptionAsExpected = true;
596     }
597 
598     assertTrue("check should have thrown exception", gotExceptionAsExpected);
599   } // testDefaultRun()
600 
601   /** Test arbitrary metadata elements on resources */
602   public void testArbitraryMetadata() throws Exception {
603 
604     ResourceData docRd = (ResourceData) reg.get("gate.corpora.DocumentImpl");
605     assertNotNull("testArbitraryMetadata: couldn't find doc res data", docRd);
606     FeatureMap features = docRd.getFeatures();
607     String comment = (String) features.get("FUNKY-METADATA-THAING");
608     assertTrue(
609       "testArbitraryMetadata: incorrect FUNKY-METADATA-THAING on document",
610       comment != null && comment.equals("hubba hubba")
611     );
612   } // testArbitraryMetadata()
613 
614   /** Test resource introspection */
615   public void testIntrospection() throws Exception {
616     // get the gate.Document resource and its class
617     ResourceData docRd = (ResourceData) reg.get("gate.corpora.DocumentImpl");
618     assertNotNull("couldn't find document res data (2)", docRd);
619     Class resClass = docRd.getResourceClass();
620 
621     // get the beaninfo and property descriptors for the resource
622     BeanInfo docBeanInfo = Introspector.getBeanInfo(resClass, Object.class);
623     PropertyDescriptor[] propDescrs = docBeanInfo.getPropertyDescriptors();
624 
625     // print all the properties in the reource's bean info;
626     // remember the setFeatures method
627     Method setFeaturesMethod = null;
628     for(int i = 0; i<propDescrs.length; i++) {
629       Method getMethodDescr = null;
630       Method setMethodDescr = null;
631       Class propClass = null;
632 
633       PropertyDescriptor propDescr = propDescrs[i];
634       propClass = propDescr.getPropertyType();
635       getMethodDescr = propDescr.getReadMethod();
636       setMethodDescr = propDescr.getWriteMethod();
637 
638       if(
639         setMethodDescr != null &&
640         setMethodDescr.getName().equals("setFeatures")
641       )
642         setFeaturesMethod = setMethodDescr;
643 
644       if(DEBUG) printProperty(propDescrs[i]);
645     }
646 
647     // try setting the features property
648     // invoke(Object obj, Object[] args)
649     LanguageResource res = (LanguageResource) resClass.newInstance();
650     FeatureMap feats = Factory.newFeatureMap();
651     feats.put("things are sunny in sunny countries", "aren't they?");
652     Object[] args = new Object[1];
653     args[0] = feats;
654     setFeaturesMethod.invoke(res, args);
655     assertTrue(
656       "features not added to resource properly",
657       res.getFeatures().get("things are sunny in sunny countries")
658         .equals("aren't they?")
659     );
660   } // testIntrospection
661 
662   /** Test the Factory resource creation provisions */
663   public void testFactory() throws Exception {
664     FeatureMap params = Factory.newFeatureMap();
665     params.put("features", Factory.newFeatureMap());
666     params.put(Document.DOCUMENT_URL_PARAMETER_NAME, Gate.getUrl("tests/doc0.html")
667     );
668     Resource res =
669       Factory.createResource("gate.corpora.DocumentImpl", params);
670   } // testFactory
671 
672   /** Utility method to print out the values of a property descriptor
673     * @see java.beans.PropertyDescriptor
674     */
675   public static void printProperty(PropertyDescriptor prop) {
676     Class propClass = prop.getPropertyType();
677     Method getMethodDescr = prop.getReadMethod();
678     Method setMethodDescr = prop.getWriteMethod();
679     Out.pr("prop dispname= " + prop.getDisplayName() + "; ");
680     Out.pr("prop type name= " + propClass.getName() + "; ");
681     if(getMethodDescr != null)
682       Out.pr("get meth name= " + getMethodDescr.getName() + "; ");
683     if(setMethodDescr != null)
684       Out.pr("set meth name= " + setMethodDescr.getName() + "; ");
685     Out.prln();
686   } // printProperty
687 
688   /** Example of what bean info classes do.
689     * If this was a public class in gate.corpora it would be used
690     * by the beans Introspector to generation bean info for the
691     * gate.corpora.DocumentImpl class. It inherits from SimpleBeanInfo
692     * whose default behaviour is to return null for the various methods;
693     * this tells the Introspector to do its own investigations.
694     */
695   class DocumentImplBeanInfo extends SimpleBeanInfo {
696 
697     /** Override the SimpleBeanInfo behaviour and return a 0-length
698       * array of properties; this will be passed on by the Introspector,
699       * the effect being to block info on the properties of the bean.
700       */
701     public PropertyDescriptor[] getPropertyDescriptors() {
702       return new PropertyDescriptor[0];
703     } // getPropertyDescriptors
704 
705   } // DocumentImplBeanInfo
706 
707   /** Test suite routine for the test runner */
708   public static Test suite() {
709     return new TestSuite(TestCreole.class);
710   } // suite
711 
712 } // class TestCreole
713