KickJava   Java API By Example, From Geeks To Geeks.

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


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/CompositeTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/05/24 16:18:33 $
10
// $Revision: 1.17 $
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.Node;
30 import org.htmlparser.Text;
31 import org.htmlparser.tags.CompositeTag;
32 import org.htmlparser.tags.TableColumn;
33 import org.htmlparser.tags.TableRow;
34 import org.htmlparser.tags.TableTag;
35 import org.htmlparser.tests.ParserTestCase;
36 import org.htmlparser.util.ParserException;
37
38
39 public class CompositeTagTest extends ParserTestCase {
40
41     static
42     {
43         System.setProperty ("org.htmlparser.tests.tagTests.CompositeTagTest", "CompositeTagTest");
44     }
45
46     public CompositeTagTest(String JavaDoc name) {
47         super(name);
48     }
49
50     public void testDigupStringNode() throws ParserException {
51         createParser(
52             "<table>" +
53                 "<table>" +
54                     "<tr>" +
55                     "<td>" +
56                     "Hello World" +
57                     "</td>" +
58                     "</tr>" +
59                 "</table>" +
60             "</table>"
61         );
62         parseAndAssertNodeCount(1);
63         TableTag tableTag = (TableTag)node[0];
64         Text[] stringNode =
65             tableTag.digupStringNode("Hello World");
66
67         assertEquals("number of string nodes",1,stringNode.length);
68         assertNotNull("should have found string node",stringNode);
69         Node parent = stringNode[0].getParent();
70         assertType("should be column",TableColumn.class,parent);
71         parent = parent.getParent();
72         assertType("should be row",TableRow.class,parent);
73         parent = parent.getParent();
74         assertType("should be table",TableTag.class,parent);
75         parent = parent.getParent();
76         assertType("should be table again",TableTag.class,parent);
77         assertSame("should be original table",tableTag,parent);
78     }
79
80     public void testFindPositionOf() throws ParserException {
81         createParser(
82             "<table>" +
83                 "<table>" +
84                     "<tr>" +
85                     "<td>" +
86                     "Hi There<a><b>sdsd</b>" +
87                     "Hello World" +
88                     "</td>" +
89                     "</tr>" +
90                 "</table>" +
91             "</table>"
92         );
93         parseAndAssertNodeCount(1);
94         TableTag tableTag = (TableTag)node[0];
95         Text [] stringNode =
96             tableTag.digupStringNode("Hello World");
97
98         assertEquals("number of string nodes",1,stringNode.length);
99         assertNotNull("should have found string node",stringNode);
100         CompositeTag parent = (CompositeTag)stringNode[0].getParent();
101         int pos = parent.findPositionOf(stringNode[0]);
102         /* a(b(),string("sdsd"),/b(),string("Hello World")) */
103         /* 0 1 2 3 */
104         assertEquals("position",3,pos);
105     }
106 }
107
Popular Tags