1
15
16 package gate.corpora;
17
18 import java.net.URL;
19
20 import junit.framework.*;
21
22 import gate.*;
23 import gate.util.SimpleFeatureMapImpl;
24
25
27 public class TestSerialCorpus extends TestCase
28 {
29
30
31 private static final boolean DEBUG = false;
32
33
34 public TestSerialCorpus(String name) { super(name); }
35
36
37 public void setUp() {
38 }
40
41 public void testCreation() throws Exception {
42 Corpus c = new SerialCorpusImpl(Factory.newCorpus("test"));
43 c.setName("test corpus");
44
45 assertTrue(c.isEmpty());
46 assertTrue(c.getName().equals("test corpus"));
47
48 c.setFeatures(new SimpleFeatureMapImpl());
49 c.getFeatures().put("author", "hamish");
50 c.getFeatures().put("date", new Integer(180200));
51 assertTrue(c.getFeatures().size() == 2);
52
53
54 }
56
57 public void testDocumentAddition() throws Exception {
58 Corpus c = Factory.newCorpus("test corpus");
59 Document d1 = Factory.newDocument("a document");
60 Document d2 = Factory.newDocument("another document");
61 d2.setSourceUrl(new URL("http://localhost/1"));
62 d2.setSourceUrl(new URL("http://localhost/2"));
63 assertTrue(c.add(d1));
64 assertTrue(c.add(d2));
65 assertEquals(2, c.size());
66
67 Corpus c1 = new SerialCorpusImpl(c);
68 Document d1_1 = (Document) c1.get(0);
69 Document d2_1 = (Document) c1.get(1);
70 assertEquals(d1, d1_1);
71 assertEquals(d2, d2_1);
72
73 }
75
76 public static Test suite() {
77 return new TestSuite(TestSerialCorpus.class);
78 }
80 public static void main(String[] args){
81 try{
82 Gate.setLocalWebServer(false);
83 Gate.setNetConnected(false);
84 Gate.init();
85 TestSerialCorpus test = new TestSerialCorpus("");
86 test.setUp();
87 test.testCreation();
88 test.tearDown();
89
90 test.setUp();
91 test.testDocumentAddition();
92 test.tearDown();
93
94 }catch(Exception e){
95 e.printStackTrace();
96 }
97 }
98
99 }