1   /*
2    *  TestSerialCorpus.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   *  Kalina Bontcheva, 20/Oct/2001
12   *
13   *  $Id: TestSerialCorpus.java,v 1.6 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 SerialCorpus classes
26    */
27  public class TestSerialCorpus extends TestCase
28  {
29  
30    /** Debug flag */
31    private static final boolean DEBUG = false;
32  
33    /** Construction */
34    public TestSerialCorpus(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 = 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    } // testCreation()
55  
56    /** Add some documents */
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    } // testDocumentAddition()
74  
75    /** Test suite routine for the test runner */
76    public static Test suite() {
77      return new TestSuite(TestSerialCorpus.class);
78    } // suite
79  
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  } // class TestCorpus
100