1 19 20 33 package org.htmlparser.tests.scannersTests; 34 import java.util.Enumeration ; 35 import java.util.Hashtable ; 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 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 (true), 57 new Boolean (retVal)); 58 } 59 60 public void testScan() throws ParserException 61 { 62 String [][] paramsData = { { "Param1", "Value1" }, { 63 "Name", "Somik" }, { 64 "Age", "23" } 65 }; 66 Hashtable paramsMap = new Hashtable (); 67 String testHTML = 68 new String ("<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 parser.addScanner(new AppletScanner("-a")); 83 84 parseAndAssertNodeCount(2); 85 assertTrue( 86 "Node should be an applet tag", 87 node[0] instanceof AppletTag); 88 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 int cnt = 0; 95 for (Enumeration e = appletTag.getParameterNames(); 96 e.hasMoreElements(); 97 ) 98 { 99 String paramName = (String ) e.nextElement(); 100 String 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 (paramsData.length), 110 new Integer (cnt)); 111 } 112 } 113 | Popular Tags |