KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/scannersTests/OptionTagScannerTest.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.scanners.OptionTagScanner;
37 import org.htmlparser.tags.OptionTag;
38 import org.htmlparser.tests.ParserTestCase;
39 import org.htmlparser.util.ParserException;
40
41 public class OptionTagScannerTest extends ParserTestCase
42 {
43
44     private String JavaDoc testHTML =
45         new String JavaDoc(
46             "<OPTION value=\"Google Search\">Google</OPTION>"
47                 + "<OPTION value=\"AltaVista Search\">AltaVista"
48                 + "<OPTION value=\"Lycos Search\"></OPTION>"
49                 + "<OPTION>Yahoo!</OPTION>"
50                 + "<OPTION>\nHotmail</OPTION>"
51                 + "<OPTION>Mailcity\n</OPTION>"
52                 + "<OPTION>\nIndiatimes\n</OPTION>"
53                 + "<OPTION>\nRediff\n</OPTION>\n"
54                 + "<OPTION>Cricinfo");
55     private OptionTagScanner scanner;
56     private Node[] node;
57     private int i;
58
59     public OptionTagScannerTest(String JavaDoc name)
60     {
61         super(name);
62     }
63
64     public void testScan() throws ParserException
65     {
66         scanner = new OptionTagScanner("-i");
67         createParser(testHTML, "http://www.google.com/test/index.html");
68         parser.addScanner(scanner);
69         parseAndAssertNodeCount(9);
70         for (int j = 0; j < i; j++)
71         {
72             assertTrue(
73                 "Node " + j + " should be Option Tag",
74                 node[j] instanceof OptionTag);
75             OptionTag OptionTag = (OptionTag) node[j];
76             assertEquals("Option Scanner", scanner, OptionTag.getThisScanner());
77         }
78     }
79     public static void main(String JavaDoc[] args)
80     {
81         new junit.awtui.TestRunner().start(
82             new String JavaDoc[] { OptionTagScannerTest.class.getName()});
83     }
84
85 }
86
Popular Tags