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 TestCorpus extends TestCase
28 {
29
30
31 private static final boolean DEBUG = false;
32
33
34 public TestCorpus(String name) { super(name); }
35
36
37 public void setUp() {
38 }
40
41 public void testCreation() throws Exception {
42 Corpus c = Factory.newCorpus("test corpus");
43
44 assertTrue(c.isEmpty());
45 assertTrue(c.getName().equals("test corpus"));
46
47 c.setFeatures(new SimpleFeatureMapImpl());
48 c.getFeatures().put("author", "hamish");
49 c.getFeatures().put("date", new Integer(180200));
50 assertTrue(c.getFeatures().size() == 2);
51
52 Corpus c2 = Factory.newCorpus("test corpus2");
53 c2.getFeatures().put("author", "hamish");
54 c2.getFeatures().put("author", "valy");
55 assertTrue(
56 "corpus feature set wrong, size = " + c2.getFeatures().size(),
57 c2.getFeatures().size() == 1
58 );
59 assertTrue(c2.getFeatures().get("author").equals("valy"));
60
61 }
63
64 public void testDocumentAddition() throws Exception {
65 Corpus c = Factory.newCorpus("test corpus");
66 Document d1 = Factory.newDocument("a document");
67 Document d2 = Factory.newDocument("another document");
68 d2.setSourceUrl(new URL("http://localhost/1"));
69 d2.setSourceUrl(new URL("http://localhost/2"));
70 assertTrue(c.add(d1));
71 assertTrue(c.add(d2));
72 assertEquals(2, c.size());
73 }
75
76 public static Test suite() {
77 return new TestSuite(TestCorpus.class);
78 }
80 }