1   /*
2    *  TestHtml.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   *  Cristian URSU,  8/May/2000
12   *
13   *  $Id: TestHtml.java,v 1.35 2005/01/11 13:51:35 ian Exp $
14   */
15  
16  package gate.html;
17  
18  import java.util.Map;
19  
20  import junit.framework.*;
21  
22  import gate.Gate;
23  
24  
25  /** Test class for HTML facilities
26    */
27  public class TestHtml extends TestCase
28  {
29    /** Debug flag */
30    private static final boolean DEBUG = false;
31  
32    /** Construction */
33    public TestHtml(String name) { super(name); }
34  
35    /** Fixture set up */
36    public void setUp() {
37    } // setUp
38  
39    /** A test */
40    public void testUnpackMarkup() throws Exception {
41      // create the markupElementsMap map
42      Map markupElementsMap = null;
43  
44      gate.Document doc = null;
45      /*
46      markupElementsMap = new HashMap();
47      // populate it
48      markupElementsMap.put ("h1","Header 1");
49      markupElementsMap.put ("H1","Header 1");
50      markupElementsMap.put ("A","link");
51      markupElementsMap.put ("a","link");
52      */
53    doc = gate.Factory.newDocument(Gate.getUrl("tests/html/test1.htm"));
54  // doc = gate.Factory.newDocument(new URL("http://www"));
55  
56     // get the docFormat that deals with it.
57     gate.DocumentFormat docFormat = gate.DocumentFormat.getDocumentFormat(
58                                                          doc, doc.getSourceUrl()
59                                                          );
60      assertTrue( "Bad document Format was produced. HtmlDocumentFormat was expected",
61              docFormat instanceof gate.corpora.HtmlDocumentFormat
62            );
63  
64  
65      // set's the map
66      docFormat.setMarkupElementsMap(markupElementsMap);
67      docFormat.unpackMarkup (doc,"DocumentContent");
68  
69      gate.corpora.TestDocument.verifyNodeIdConsistency(doc);
70  /*
71      // Save it as XML
72      File xmlFile = null;
73      xmlFile = Files.writeTempFile(null);
74  
75      OutputStreamWriter writer = new OutputStreamWriter(
76                      new FileOutputStream(xmlFile),"UTF-8");
77      // Write (test the toXml() method)
78      writer.write(doc.toXml());
79      writer.flush();
80      writer.close();
81  */
82    } // testUnpackMarkup()
83  //*
84    public static void main(String[] args){
85      try{
86        Gate.init();
87        TestHtml test = new TestHtml("gicu");
88        test.testUnpackMarkup();
89      } catch (Exception e){
90        e.printStackTrace(System.out);
91      }
92    }
93  //*/
94    /** Test suite routine for the test runner */
95    public static Test suite() {
96      return new TestSuite(TestHtml.class);
97    } // suite
98  
99  }//class TestHtml
100