001 /*
002 * TestSerialCorpus.java
003 *
004 * Copyright (c) 1995-2010, The University of Sheffield. See the file
005 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006 *
007 * This file is part of GATE (see http://gate.ac.uk/), and is free
008 * software, licenced under the GNU Library General Public License,
009 * Version 2, June 1991 (in the distribution as file licence.html,
010 * and also available at http://gate.ac.uk/gate/licence.html).
011 *
012 * Kalina Bontcheva, 20/Oct/2001
013 *
014 * $Id: TestSerialCorpus.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015 */
016
017 package gate.corpora;
018
019 import java.net.URL;
020
021 import junit.framework.*;
022
023 import gate.*;
024 import gate.util.SimpleFeatureMapImpl;
025
026 /** Tests for the SerialCorpus classes
027 */
028 public class TestSerialCorpus extends TestCase
029 {
030
031 /** Debug flag */
032 private static final boolean DEBUG = false;
033
034 /** Construction */
035 public TestSerialCorpus(String name) { super(name); }
036
037 /** Fixture set up */
038 public void setUp() {
039 } // setUp
040
041 /** Corpus creation */
042 public void testCreation() throws Exception {
043 Corpus c = new SerialCorpusImpl(Factory.newCorpus("test"));
044 c.setName("test corpus");
045
046 assertTrue(c.isEmpty());
047 assertTrue(c.getName().equals("test corpus"));
048
049 c.setFeatures(new SimpleFeatureMapImpl());
050 c.getFeatures().put("author", "hamish");
051 c.getFeatures().put("date", new Integer(180200));
052 assertTrue(c.getFeatures().size() == 2);
053
054
055 } // testCreation()
056
057 /** Add some documents */
058 public void testDocumentAddition() throws Exception {
059 Corpus c = Factory.newCorpus("test corpus");
060 Document d1 = Factory.newDocument("a document");
061 Document d2 = Factory.newDocument("another document");
062 d2.setSourceUrl(new URL("http://localhost/1"));
063 d2.setSourceUrl(new URL("http://localhost/2"));
064 assertTrue(c.add(d1));
065 assertTrue(c.add(d2));
066 assertEquals(2, c.size());
067
068 Corpus c1 = new SerialCorpusImpl(c);
069 Document d1_1 = (Document) c1.get(0);
070 Document d2_1 = (Document) c1.get(1);
071 assertEquals(d1, d1_1);
072 assertEquals(d2, d2_1);
073
074 } // testDocumentAddition()
075
076 /** Test suite routine for the test runner */
077 public static Test suite() {
078 return new TestSuite(TestSerialCorpus.class);
079 } // suite
080
081 public static void main(String[] args){
082 try{
083 Gate.setLocalWebServer(false);
084 Gate.setNetConnected(false);
085 Gate.init();
086 TestSerialCorpus test = new TestSerialCorpus("");
087 test.setUp();
088 test.testCreation();
089 test.tearDown();
090
091 test.setUp();
092 test.testDocumentAddition();
093 test.tearDown();
094
095 }catch(Exception e){
096 e.printStackTrace();
097 }
098 }
099
100 } // class TestCorpus
|