KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/scannersTests/BulletScannerTest.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.tags.Bullet;
37 import org.htmlparser.tests.ParserTestCase;
38 import org.htmlparser.util.NodeIterator;
39 import org.htmlparser.util.ParserException;
40
41
42 public class BulletScannerTest extends ParserTestCase
43 {
44
45     public BulletScannerTest(String JavaDoc name)
46     {
47         super(name);
48     }
49
50     public void testBulletFound() throws Exception JavaDoc
51     {
52         createParser(
53             "<LI><A HREF=\"collapseHierarchy.html\">Collapse Hierarchy</A>\n"
54                 + "</LI>");
55         parser.registerScanners();
56         parseAndAssertNodeCount(1);
57         assertType("should be a bullet", Bullet.class, node[0]);
58     }
59
60     public void testOutOfMemoryBug() throws ParserException
61     {
62         createParser(
63             "<html>"
64                 + "<head>"
65                 + "<title>Foo</title>"
66                 + "</head>"
67                 + "<body>"
68                 + " <ul>"
69                 + " <li>"
70                 + " <a HREF=\"http://foo.com/c.html\">bibliographies on:"
71                 + " <ul>"
72                 + " <li>chironomidae</li>"
73                 + " </ul>"
74                 + " </a>"
75                 + " </li>"
76                 + " </ul>"
77                 + ""
78                 + "</body>"
79                 + "</html>");
80         parser.registerScanners();
81         for (NodeIterator i = parser.elements(); i.hasMoreNodes();)
82         {
83             Node node = i.nextNode();
84             System.out.println(node.toHtml());
85         }
86     }
87
88     public void testNonEndedBullets() throws ParserException
89     {
90         createParser(
91             "<li>forest practices legislation penalties for non-compliance\n"
92                 + " (Kwan) <A HREF=\"/hansard/37th3rd/h21107a.htm#4384\">4384-5</A>\n"
93                 + "<li>passenger rail service\n"
94                 + " (MacPhail) <A HREF=\"/hansard/37th3rd/h21021p.htm#3904\">3904</A>\n"
95                 + "<li>referendum on principles for treaty negotiations\n"
96                 + " (MacPhail) <A HREF=\"/hansard/37th3rd/h20313p.htm#1894\">1894</A>\n"
97                 + "<li>transportation infrastructure projects\n"
98                 + " (MacPhail) <A HREF=\"/hansard/37th3rd/h21022a.htm#3945\">3945-7</A>\n"
99                 + "<li>tuition fee freeze");
100         parser.registerScanners();
101         parseAndAssertNodeCount(5);
102         for (int i = 0; i < nodeCount; i++)
103         {
104             assertType("node " + i, Bullet.class, node[i]);
105         }
106     }
107 }
108
Popular Tags