KickJava   Java API By Example, From Geeks To Geeks.

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


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/DivTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/02 00:49:31 $
10
// $Revision: 1.3 $
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.PrototypicalNodeFactory;
30 import org.htmlparser.Tag;
31 import org.htmlparser.tags.Div;
32 import org.htmlparser.tags.InputTag;
33 import org.htmlparser.tags.TableTag;
34 import org.htmlparser.tests.ParserTestCase;
35 import org.htmlparser.util.ParserException;
36
37 public class DivTagTest extends ParserTestCase
38 {
39     static
40     {
41         System.setProperty ("org.htmlparser.tests.tagTests.DivTagTest", "DivTagTest");
42     }
43
44     public DivTagTest (String JavaDoc name)
45     {
46         super(name);
47     }
48     
49     public void testScan() throws ParserException {
50         createParser("<table><div align=\"left\">some text</div></table>");
51         parseAndAssertNodeCount(1);
52         assertType("node should be table",TableTag.class,node[0]);
53         TableTag tableTag = (TableTag)node[0];
54         Div div = (Div)tableTag.searchFor(Div.class, true).toNodeArray()[0];
55         assertEquals("div contents","some text",div.toPlainTextString());
56     }
57
58     /**
59      * Test case for bug #735193 Explicit tag type recognition for CompositTags not working.
60      */

61     public void testInputInDiv() throws ParserException
62     {
63         createParser("<div><INPUT type=\"text\" name=\"X\">Hello</INPUT></div>");
64         parser.setNodeFactory (
65             new PrototypicalNodeFactory (
66                 new Tag[]
67                 {
68                     new Div (),
69                     new InputTag (),
70                 }));
71         parseAndAssertNodeCount(1);
72         assertType("node should be div",Div.class,node[0]);
73         Div div = (Div)node[0];
74         assertType("child not input",InputTag.class,div.getChild (0));
75     }
76 }
77
Popular Tags