DynamicRegistrationTest.java
01 /*
02  *  DynamicRegistrationTest.java
03  *
04  *  Copyright (c) 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  */
13 
14 package gate.creole.test;
15 
16 import gate.Corpus;
17 import gate.Document;
18 import gate.Factory;
19 import gate.Gate;
20 import gate.ProcessingResource;
21 import gate.creole.AbstractLanguageAnalyser;
22 import gate.creole.AbstractProcessingResource;
23 import gate.creole.ExecutionException;
24 import gate.creole.SerialAnalyserController;
25 import gate.creole.metadata.CreoleResource;
26 import junit.framework.Test;
27 import junit.framework.TestCase;
28 import junit.framework.TestSuite;
29 
30 /**
31  * Test case for the dynamic registration system. Intended for use inside of TestGate.
32  *
33  */
34 public class DynamicRegistrationTest extends TestCase {
35 
36   @CreoleResource(name = "This is a test")
37   public static class TestResource extends AbstractLanguageAnalyser {
38     private static final long serialVersionUID = 1L;
39 
40     @Override
41     public void execute() throws ExecutionException {
42 
43     }
44   }
45 
46 
47   public void testDynamicRegistration() throws Exception {
48     Gate.getCreoleRegister().registerComponent(TestResource.class);
49 
50     SerialAnalyserController controller = (SerialAnalyserController)Factory.createResource("gate.creole.SerialAnalyserController",
51             Factory.newFeatureMap(),
52             Factory.newFeatureMap(),
53             "basicRun");
54     ProcessingResource testResource = (ProcessingResource)
55       Factory.createResource(TestResource.class.getName());
56     controller.add(testResource);
57     Corpus corpus = Factory.newCorpus("basicTestCorpus");
58     String engText = "This is the cereal shot from gnus.";
59     Document doc = Factory.newDocument(engText);
60     corpus.add(doc);
61     controller.setCorpus(corpus);
62     controller.setDocument(doc);
63     controller.execute();
64   }
65 
66   /** Test suite routine for the test runner */
67   public static Test suite() {
68     return new TestSuite(DynamicRegistrationTest.class);
69   // suite
70 
71 }