1   /*
2    *  TestCorpus.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, 18/Feb/00
12   *
13   *  $Id: TestCorpus.java,v 1.19 2005/01/11 13:51:31 ian Exp $
14   */
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  /** Tests for the Corpus classes
26    */
27  public class TestCorpus extends TestCase
28  {
29  
30    /** Debug flag */
31    private static final boolean DEBUG = false;
32  
33    /** Construction */
34    public TestCorpus(String name) { super(name); }
35  
36    /** Fixture set up */
37    public void setUp() {
38    } // setUp
39  
40    /** Corpus creation */
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    } // testCreation()
62  
63    /** Add some documents */
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    } // testDocumentAddition()
74  
75    /** Test suite routine for the test runner */
76    public static Test suite() {
77      return new TestSuite(TestCorpus.class);
78    } // suite
79  
80  } // class TestCorpus
81