TestHtml.java
001 /*
002  *  TestHtml.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  *  Cristian URSU,  8/May/2000
013  *
014  *  $Id: TestHtml.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015  */
016 
017 package gate.html;
018 
019 import java.util.Map;
020 
021 import junit.framework.*;
022 
023 import gate.Gate;
024 
025 
026 /** Test class for HTML facilities
027   */
028 public class TestHtml extends TestCase
029 {
030   /** Debug flag */
031   private static final boolean DEBUG = false;
032 
033   /** Construction */
034   public TestHtml(String name) { super(name)}
035 
036   /** Fixture set up */
037   public void setUp() {
038   // setUp
039 
040   /** A test */
041   public void testUnpackMarkup() throws Exception {
042     // create the markupElementsMap map
043     Map markupElementsMap = null;
044 
045     gate.Document doc = null;
046     /*
047     markupElementsMap = new HashMap();
048     // populate it
049     markupElementsMap.put ("h1","Header 1");
050     markupElementsMap.put ("H1","Header 1");
051     markupElementsMap.put ("A","link");
052     markupElementsMap.put ("a","link");
053     */
054   doc = gate.Factory.newDocument(Gate.getUrl("tests/html/test1.htm"));
055 // doc = gate.Factory.newDocument(new URL("http://www"));
056 
057    // get the docFormat that deals with it.
058    gate.DocumentFormat docFormat = gate.DocumentFormat.getDocumentFormat(
059                                                         doc, doc.getSourceUrl()
060                                                         );
061     assertTrue"Bad document Format was produced. HtmlDocumentFormat was expected",
062             docFormat instanceof gate.corpora.HtmlDocumentFormat
063           );
064 
065 
066     // set's the map
067     // Don't need to unpack markup explicitly, as it is already unpacked by
068     // default by newDocument - unpacking it twice causes exceptions
069     //docFormat.setMarkupElementsMap(markupElementsMap);
070     //docFormat.unpackMarkup (doc,"DocumentContent");
071 
072     gate.corpora.TestDocument.verifyNodeIdConsistency(doc);
073 /*
074     // Save it as XML
075     File xmlFile = null;
076     xmlFile = Files.writeTempFile(null);
077 
078     OutputStreamWriter writer = new OutputStreamWriter(
079                     new FileOutputStream(xmlFile),"UTF-8");
080     // Write (test the toXml() method)
081     writer.write(doc.toXml());
082     writer.flush();
083     writer.close();
084 */
085   // testUnpackMarkup()
086 //*
087   public static void main(String[] args){
088     try{
089       Gate.init();
090       TestHtml test = new TestHtml("gicu");
091       test.testUnpackMarkup();
092     catch (Exception e){
093       e.printStackTrace(System.out);
094     }
095   }
096 //*/
097   /** Test suite routine for the test runner */
098   public static Test suite() {
099     return new TestSuite(TestHtml.class);
100   // suite
101 
102 }//class TestHtml