TestCorpus.java
01 /*
02  *  TestCorpus.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  *  Hamish Cunningham, 18/Feb/00
13  *
14  *  $Id: TestCorpus.java 12006 2009-12-01 17:24:28Z thomas_heitz $
15  */
16 
17 package gate.corpora;
18 
19 import java.net.URL;
20 
21 import junit.framework.*;
22 
23 import gate.*;
24 import gate.util.SimpleFeatureMapImpl;
25 
26 /** Tests for the Corpus classes
27   */
28 public class TestCorpus extends TestCase
29 {
30 
31   /** Debug flag */
32   private static final boolean DEBUG = false;
33 
34   /** Construction */
35   public TestCorpus(String name) { super(name)}
36 
37   /** Fixture set up */
38   public void setUp() {
39   // setUp
40 
41   /** Corpus creation */
42   public void testCreation() throws Exception {
43     Corpus c = Factory.newCorpus("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     Corpus c2 = Factory.newCorpus("test corpus2");
54     c2.getFeatures().put("author""hamish");
55     c2.getFeatures().put("author""valy");
56     assertTrue(
57       "corpus feature set wrong, size = " + c2.getFeatures().size(),
58       c2.getFeatures().size() == 1
59     );
60     assertTrue(c2.getFeatures().get("author").equals("valy"));
61 
62   // testCreation()
63 
64   /** Add some documents */
65   public void testDocumentAddition() throws Exception {
66     Corpus c = Factory.newCorpus("test corpus");
67     Document d1 = Factory.newDocument("a document");
68     Document d2 = Factory.newDocument("another document");
69     d2.setSourceUrl(new URL("http://localhost/1"));
70     d2.setSourceUrl(new URL("http://localhost/2"));
71     assertTrue(c.add(d1));
72     assertTrue(c.add(d2));
73     assertEquals(2, c.size());
74   // testDocumentAddition()
75 
76   /** Test suite routine for the test runner */
77   public static Test suite() {
78     return new TestSuite(TestCorpus.class);
79   // suite
80 
81 // class TestCorpus