|
What this is
Other links
The source code
// $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/scannersTests/FormScannerTest.java,v 1.2 2004/02/11 02:16:58 woolfel Exp $
/*
* ====================================================================
* Copyright 2002-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// The developers of JMeter and Apache are greatful to the developers
// of HTMLParser for giving Apache Software Foundation a non-exclusive
// license. The performance benefits of HTMLParser are clear and the
// users of JMeter will benefit from the hard work the HTMLParser
// team. For detailed information about HTMLParser, the project is
// hosted on sourceforge at http://htmlparser.sourceforge.net/.
//
// HTMLParser was originally created by Somik Raha in 2000. Since then
// a healthy community of users has formed and helped refine the
// design so that it is able to tackle the difficult task of parsing
// dirty HTML. Derrick Oswald is the current lead developer and was kind
// enough to assist JMeter.
package org.htmlparser.tests.scannersTests;
import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.RemarkNode;
import org.htmlparser.scanners.FormScanner;
import org.htmlparser.scanners.LinkScanner;
import org.htmlparser.tags.FormTag;
import org.htmlparser.tags.InputTag;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.tags.TextareaTag;
import org.htmlparser.tests.ParserTestCase;
import org.htmlparser.util.ParserException;
import org.htmlparser.util.SimpleNodeIterator;
public class FormScannerTest extends ParserTestCase
{
public static final String FORM_HTML =
"";
public static final String EXPECTED_FORM_HTML_FORMLINE =
"";
public static final String EXPECTED_FORM_HTML =
EXPECTED_FORM_HTML_FORMLINE + EXPECTED_FORM_HTML_REST_OF_FORM;
public FormScannerTest(String name)
{
super(name);
}
public void testEvaluate()
{
String line1 =
"form method=\"post\" onsubmit=\"return implementsearch()\" name=frmsearch id=form";
String line2 =
"FORM method=\"post\" onsubmit=\"return implementsearch()\" name=frmsearch id=form";
String line3 =
"Form method=\"post\" onsubmit=\"return implementsearch()\" name=frmsearch id=form";
FormScanner formScanner = new FormScanner("", Parser.createParser(""));
assertTrue("Line 1", formScanner.evaluate(line1, null));
assertTrue("Line 2", formScanner.evaluate(line2, null));
assertTrue("Line 3", formScanner.evaluate(line3, null));
}
public void assertTypeNameSize(
String description,
String type,
String name,
String size,
InputTag inputTag)
{
assertEquals(
description + " type",
type,
inputTag.getAttribute("TYPE"));
assertEquals(
description + " name",
name,
inputTag.getAttribute("NAME"));
assertEquals(
description + " size",
size,
inputTag.getAttribute("SIZE"));
}
public void assertTypeNameValue(
String description,
String type,
String name,
String value,
InputTag inputTag)
{
assertEquals(
description + " type",
type,
inputTag.getAttribute("TYPE"));
assertEquals(
description + " name",
name,
inputTag.getAttribute("NAME"));
assertEquals(
description + " value",
value,
inputTag.getAttribute("VALUE"));
}
public void testScan() throws ParserException
{
createParser(FORM_HTML, "http://www.google.com/test/index.html");
parser.addScanner(new FormScanner("", parser));
parseAndAssertNodeCount(1);
assertTrue("Node 0 should be Form Tag", node[0] instanceof FormTag);
FormTag formTag = (FormTag) node[0];
assertStringEquals("Method", FormTag.POST, formTag.getFormMethod());
assertStringEquals(
"Location",
"http://www.google.com/test/do_login.php",
formTag.getFormLocation());
assertStringEquals("Name", "login_form", formTag.getFormName());
InputTag nameTag = formTag.getInputTag("name");
InputTag passwdTag = formTag.getInputTag("passwd");
InputTag submitTag = formTag.getInputTag("submit");
InputTag dummyTag = formTag.getInputTag("dummy");
assertNotNull("Input Name Tag should not be null", nameTag);
assertNotNull("Input Password Tag should not be null", passwdTag);
assertNotNull("Input Submit Tag should not be null", submitTag);
assertNull("Input dummy tag should be null", dummyTag);
assertTypeNameSize("Input Name Tag", "text", "name", "20", nameTag);
assertTypeNameSize(
"Input Password Tag",
"password",
"passwd",
"20",
passwdTag);
assertTypeNameValue(
"Input Submit Tag",
"submit",
"submit",
"Login",
submitTag);
TextareaTag textAreaTag = formTag.getTextAreaTag("Description");
assertNotNull("Text Area Tag should have been found", textAreaTag);
assertEquals(
"Text Area Tag Contents",
"Contents of TextArea",
textAreaTag.getValue());
assertNull("Should have been null", formTag.getTextAreaTag("junk"));
assertStringEquals("toHTML", EXPECTED_FORM_HTML, formTag.toHtml());
}
public void testScanFormWithNoEnding() throws Exception
{
createParser(
"\n" + "And now, the good stuff:\n" + " |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.