1   /*
2    *  TestSerialCorpus.java
3    *
4    *  Copyright (c) 1998-2001, 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.3 2001/10/30 12:45:34 valyt Exp $
14   */
15  
16  package gate.corpora;
17  
18  import java.util.*;
19  import java.net.*;
20  import java.io.*;
21  import junit.framework.*;
22  
23  import gate.*;
24  import gate.util.*;
25  import gate.annotation.*;
26  
27  /** Tests for the SerialCorpus classes
28    */
29  public class TestSerialCorpus extends TestCase
30  {
31  
32    /** Debug flag */
33    private static final boolean DEBUG = false;
34  
35    /** Construction */
36    public TestSerialCorpus(String name) { super(name); }
37  
38    /** Fixture set up */
39    public void setUp() {
40    } // setUp
41  
42    /** Corpus creation */
43    public void testCreation() throws Exception {
44      Corpus c = new SerialCorpusImpl(Factory.newCorpus("test"));
45      c.setName("test corpus");
46  
47      assertTrue(c.isEmpty());
48      assertTrue(c.getName().equals("test corpus"));
49  
50      c.setFeatures(new SimpleFeatureMapImpl());
51      c.getFeatures().put("author", "hamish");
52      c.getFeatures().put("date", new Integer(180200));
53      assertTrue(c.getFeatures().size() == 2);
54  
55  
56    } // testCreation()
57  
58    /** Add some documents */
59    public void testDocumentAddition() throws Exception {
60      Corpus c = Factory.newCorpus("test corpus");
61      Document d1 = Factory.newDocument("a document");
62      Document d2 = Factory.newDocument("another document");
63      d2.setSourceUrl(new URL("http://localhost/1"));
64      d2.setSourceUrl(new URL("http://localhost/2"));
65      assertTrue(c.add(d1));
66      assertTrue(c.add(d2));
67      assertEquals(2, c.size());
68  
69      Corpus c1 = new SerialCorpusImpl(c);
70      Document d1_1 = (Document) c1.get(0);
71      Document d2_1 = (Document) c1.get(1);
72      assertEquals(d1, d1_1);
73      assertEquals(d2, d2_1);
74  
75    } // testDocumentAddition()
76  
77    /** Test suite routine for the test runner */
78    public static Test suite() {
79      return new TestSuite(TestSerialCorpus.class);
80    } // suite
81  
82    public static void main(String[] args){
83      try{
84        Gate.setLocalWebServer(false);
85        Gate.setNetConnected(false);
86        Gate.init();
87        TestSerialCorpus test = new TestSerialCorpus("");
88        test.setUp();
89        test.testCreation();
90        test.tearDown();
91  
92        test.setUp();
93        test.testDocumentAddition();
94        test.tearDown();
95  
96      }catch(Exception e){
97        e.printStackTrace();
98      }
99    }
100 
101 } // class TestCorpus
102