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