KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > scannersTests > DivScannerTest


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/scannersTests/DivScannerTest.java,v 1.2 2004/02/11 02:16:58 woolfel Exp $
2
/*
3  * ====================================================================
4  * Copyright 2002-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */

19
20 // The developers of JMeter and Apache are greatful to the developers
21
// of HTMLParser for giving Apache Software Foundation a non-exclusive
22
// license. The performance benefits of HTMLParser are clear and the
23
// users of JMeter will benefit from the hard work the HTMLParser
24
// team. For detailed information about HTMLParser, the project is
25
// hosted on sourceforge at http://htmlparser.sourceforge.net/.
26
//
27
// HTMLParser was originally created by Somik Raha in 2000. Since then
28
// a healthy community of users has formed and helped refine the
29
// design so that it is able to tackle the difficult task of parsing
30
// dirty HTML. Derrick Oswald is the current lead developer and was kind
31
// enough to assist JMeter.
32

33 package org.htmlparser.tests.scannersTests;
34
35 import org.htmlparser.scanners.DivScanner;
36 import org.htmlparser.scanners.InputTagScanner;
37 import org.htmlparser.scanners.TableScanner;
38 import org.htmlparser.tags.Div;
39 import org.htmlparser.tags.InputTag;
40 import org.htmlparser.tags.TableTag;
41 import org.htmlparser.tests.ParserTestCase;
42 import org.htmlparser.util.ParserException;
43
44 public class DivScannerTest extends ParserTestCase
45 {
46
47     public DivScannerTest(String JavaDoc name)
48     {
49         super(name);
50     }
51
52     public void testScan() throws ParserException
53     {
54         createParser("<table><div align=\"left\">some text</div></table>");
55         parser.registerScanners();
56         parser.addScanner(new TableScanner(parser));
57         parser.addScanner(new DivScanner());
58         parseAndAssertNodeCount(1);
59         assertType("node should be table", TableTag.class, node[0]);
60         TableTag tableTag = (TableTag) node[0];
61         Div div = (Div) tableTag.searchFor(Div.class).toNodeArray()[0];
62         assertEquals("div contents", "some text", div.toPlainTextString());
63     }
64
65     /**
66      * Test case for bug #735193 Explicit tag type recognition for CompositTags not working.
67      */

68     public void testInputInDiv() throws ParserException
69     {
70         createParser("<div><INPUT type=\"text\" name=\"X\">Hello</INPUT></div>");
71         parser.addScanner(new DivScanner());
72         parser.addScanner(new InputTagScanner());
73         parseAndAssertNodeCount(1);
74         assertType("node should be div", Div.class, node[0]);
75         Div div = (Div) node[0];
76         assertType("child not input", InputTag.class, div.getChild(0));
77     }
78 }
79
Popular Tags