KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > tagTests > HeadTagTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2003 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/HeadTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2003/12/07 23:41:43 $
10
// $Revision: 1.1 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests.tagTests;
28
29 import org.htmlparser.tags.HeadTag;
30 import org.htmlparser.tags.Html;
31 import org.htmlparser.tests.ParserTestCase;
32 import org.htmlparser.util.ParserException;
33
34 public class HeadTagTest extends ParserTestCase
35 {
36     static
37     {
38         System.setProperty ("org.htmlparser.tests.tagTests.HeadTagTest", "HeadTagTest");
39     }
40
41     public HeadTagTest (String JavaDoc name)
42     {
43         super(name);
44     }
45     
46     public void testSimpleHead() throws ParserException {
47         createParser("<HTML><HEAD></HEAD></HTML>");
48         parseAndAssertNodeCount(1);
49         assertTrue(node[0] instanceof Html);
50         Html htmlTag = (Html)node[0];
51         assertTrue(htmlTag.getChild(0) instanceof HeadTag);
52     }
53
54     public void testSimpleHeadWithoutEndTag() throws ParserException {
55         createParser("<HTML><HEAD></HTML>");
56         parseAndAssertNodeCount(1);
57         assertTrue(node[0] instanceof Html);
58         Html htmlTag = (Html)node[0];
59         assertTrue(htmlTag.getChild(0) instanceof HeadTag);
60         HeadTag headTag = (HeadTag)htmlTag.getChild(0);
61         assertEquals("toHtml()","<HEAD></HEAD>",headTag.toHtml());
62         assertEquals("toHtml()","<HTML><HEAD></HEAD></HTML>",htmlTag.toHtml());
63     }
64
65     public void testSimpleHeadWithBody() throws ParserException {
66         createParser("<HTML><HEAD><BODY></HTML>");
67         parseAndAssertNodeCount(1);
68         assertTrue(node[0] instanceof Html);
69         Html htmlTag = (Html)node[0];
70         assertTrue(htmlTag.getChild(0) instanceof HeadTag);
71         //assertTrue(htmlTag.getChild(1) instanceof BodyTag);
72
HeadTag headTag = (HeadTag)htmlTag.getChild(0);
73         assertEquals("toHtml()","<HEAD></HEAD>",headTag.toHtml());
74         assertEquals("toHtml()","<HTML><HEAD></HEAD><BODY></BODY></HTML>",htmlTag.toHtml());
75     }
76 }
77
Popular Tags