KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/scannersTests/BulletListScannerTest.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.Node;
36 import org.htmlparser.StringNode;
37 import org.htmlparser.tags.Bullet;
38 import org.htmlparser.tags.BulletList;
39 import org.htmlparser.tags.CompositeTag;
40 import org.htmlparser.tests.ParserTestCase;
41 import org.htmlparser.util.NodeList;
42 import org.htmlparser.util.ParserException;
43
44 /**
45  * @author Somik Raha
46  *
47  * To change the template for this generated type comment go to
48  * Window>Preferences>Java>Code Generation>Code and Comments
49  */

50 public class BulletListScannerTest extends ParserTestCase
51 {
52
53     public BulletListScannerTest(String JavaDoc name)
54     {
55         super(name);
56     }
57
58     public void testScan() throws ParserException
59     {
60         createParser(
61             "<ul TYPE=DISC>"
62                 + "<ul TYPE=\"DISC\"><li>Energy supply\n"
63                 + " (Campbell) <A HREF=\"/hansard/37th3rd/h20307p.htm#1646\">1646</A>\n"
64                 + " (MacPhail) <A HREF=\"/hansard/37th3rd/h20307p.htm#1646\">1646</A>\n"
65                 + "</ul><A NAME=\"calpinecorp\"></A><B>Calpine Corp.</B>\n"
66                 + "<ul TYPE=\"DISC\"><li>Power plant projects\n"
67                 + " (Neufeld) <A HREF=\"/hansard/37th3rd/h20314p.htm#1985\">1985</A>\n"
68                 + "</ul>"
69                 + "</ul>");
70         parser.registerScanners();
71         parseAndAssertNodeCount(1);
72
73         NodeList nestedBulletLists =
74             ((CompositeTag) node[0]).searchFor(BulletList.class);
75         assertEquals("bullets in first list", 2, nestedBulletLists.size());
76         BulletList firstList = (BulletList) nestedBulletLists.elementAt(0);
77         Bullet firstBullet = (Bullet) firstList.childAt(0);
78         Node firstNodeInFirstBullet = firstBullet.childAt(0);
79         assertType(
80             "first child in bullet",
81             StringNode.class,
82             firstNodeInFirstBullet);
83         assertStringEquals(
84             "expected text",
85             "Energy supply\r\n" + " (Campbell) ",
86             firstNodeInFirstBullet.toPlainTextString());
87     }
88 }
89
Popular Tags