KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/scannersTests/AppletScannerTest.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 import java.util.Enumeration JavaDoc;
35 import java.util.Hashtable JavaDoc;
36
37 import org.htmlparser.scanners.AppletScanner;
38 import org.htmlparser.tags.AppletTag;
39 import org.htmlparser.tests.ParserTestCase;
40 import org.htmlparser.util.ParserException;
41
42 public class AppletScannerTest extends ParserTestCase
43 {
44
45     public AppletScannerTest(String JavaDoc name)
46     {
47         super(name);
48     }
49
50     public void testEvaluate()
51     {
52         AppletScanner scanner = new AppletScanner("-a");
53         boolean retVal = scanner.evaluate(" Applet ", null);
54         assertEquals(
55             "Evaluation of APPLET tag",
56             new Boolean JavaDoc(true),
57             new Boolean JavaDoc(retVal));
58     }
59
60     public void testScan() throws ParserException
61     {
62         String JavaDoc[][] paramsData = { { "Param1", "Value1" }, {
63                 "Name", "Somik" }, {
64                 "Age", "23" }
65         };
66         Hashtable JavaDoc paramsMap = new Hashtable JavaDoc();
67         String JavaDoc testHTML =
68             new String JavaDoc("<APPLET CODE=Myclass.class ARCHIVE=test.jar CODEBASE=www.kizna.com>\n");
69         for (int i = 0; i < paramsData.length; i++)
70         {
71             testHTML += "<PARAM NAME=\""
72                 + paramsData[i][0]
73                 + "\" VALUE=\""
74                 + paramsData[i][1]
75                 + "\">\n";
76             paramsMap.put(paramsData[i][0], paramsData[i][1]);
77         }
78         testHTML += "</APPLET>\n" + "</HTML>";
79         createParser(testHTML);
80
81         // Register the applet scanner
82
parser.addScanner(new AppletScanner("-a"));
83
84         parseAndAssertNodeCount(2);
85         assertTrue(
86             "Node should be an applet tag",
87             node[0] instanceof AppletTag);
88         // Check the data in the applet tag
89
AppletTag appletTag = (AppletTag) node[0];
90         assertEquals("Class Name", "Myclass.class", appletTag.getAppletClass());
91         assertEquals("Archive", "test.jar", appletTag.getArchive());
92         assertEquals("Codebase", "www.kizna.com", appletTag.getCodeBase());
93         // Check the params data
94
int cnt = 0;
95         for (Enumeration JavaDoc e = appletTag.getParameterNames();
96             e.hasMoreElements();
97             )
98         {
99             String JavaDoc paramName = (String JavaDoc) e.nextElement();
100             String JavaDoc paramValue = appletTag.getAttribute(paramName);
101             assertEquals(
102                 "Param " + cnt + " value",
103                 paramsMap.get(paramName),
104                 paramValue);
105             cnt++;
106         }
107         assertEquals(
108             "Number of params",
109             new Integer JavaDoc(paramsData.length),
110             new Integer JavaDoc(cnt));
111     }
112 }
113
Popular Tags