|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
Other links
The source code
// $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/tagTests/LinkTagTest.java,v 1.2 2004/02/11 02:16:57 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.tagTests;
import org.htmlparser.Parser;
import org.htmlparser.scanners.LinkScanner;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.tags.data.CompositeTagData;
import org.htmlparser.tags.data.LinkData;
import org.htmlparser.tags.data.TagData;
import org.htmlparser.tests.ParserTestCase;
import org.htmlparser.util.ParserException;
public class LinkTagTest extends ParserTestCase
{
public LinkTagTest(String name)
{
super(name);
}
/**
* The bug being reproduced is this :
* <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000
* vLink=#551a8b>
* The above line is incorrectly parsed in that, the BODY tag is not identified.
* Creation date: (6/17/2001 4:01:06 PM)
*/
public void testLinkNodeBug() throws ParserException
{
createParser(
"abcd",
"http://www.google.com/test/index.html");
// Register the image scanner
parser.addScanner(new LinkScanner("-l"));
parseAndAssertNodeCount(1);
// The node should be an HTMLLinkTag
assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);
LinkTag linkNode = (LinkTag) node[0];
assertEquals(
"The image locn",
"http://www.google.com/test.html",
linkNode.getLink());
}
/**
* The bug being reproduced is this :
* <BODY aLink=#ff0000 bgColor=#ffffff link=#0000cc onload=setfocus() text=#000000
* vLink=#551a8b>
* The above line is incorrectly parsed in that, the BODY tag is not identified.
* Creation date: (6/17/2001 4:01:06 PM)
*/
public void testLinkNodeBug2() throws ParserException
{
createParser(
"abcd",
"http://www.google.com/test/test/index.html");
// Register the image scanner
parser.addScanner(new LinkScanner("-l"));
parseAndAssertNodeCount(1);
// The node should be an HTMLLinkTag
assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);
LinkTag linkNode = (LinkTag) node[0];
assertEquals(
"The image locn",
"http://www.google.com/test.html",
linkNode.getLink());
}
/**
* The bug being reproduced is this :
* When a url ends with a slash, and the link begins with a slash,the parser puts two slashes
* This bug was submitted by Roget Kjensrud
* Creation date: (6/17/2001 4:01:06 PM)
*/
public void testLinkNodeBug3() throws ParserException
{
createParser("abcd", "http://www.cj.com/");
// Register the image scanner
parser.addScanner(new LinkScanner("-l"));
parseAndAssertNodeCount(1);
// The node should be an HTMLLinkTag
assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);
LinkTag linkNode = (LinkTag) node[0];
assertEquals(
"Link incorrect",
"http://www.cj.com/mylink.html",
linkNode.getLink());
}
/**
* The bug being reproduced is this :
* Simple url without index.html, doesent get appended to link
* This bug was submitted by Roget Kjensrud
* Creation date: (6/17/2001 4:01:06 PM)
*/
public void testLinkNodeBug4() throws ParserException
{
createParser("abcd", "http://www.cj.com");
// Register the image scanner
parser.addScanner(new LinkScanner("-l"));
parseAndAssertNodeCount(1);
// The node should be an HTMLLinkTag
assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);
LinkTag linkNode = (LinkTag) node[0];
assertEquals(
"Link incorrect!!",
"http://www.cj.com/mylink.html",
linkNode.getLink());
}
public void testLinkNodeBug5() throws ParserException
{
createParser(
"µ§°O ¬Ûï ³q°T¿ý ",
"http://www.cj.com");
Parser.setLineSeparator("\r\n");
// Register the image scanner
parser.addScanner(new LinkScanner("-l"));
parseAndAssertNodeCount(6);
// The node should be an LinkTag
assertTrue("Node should be a LinkTag", node[0] instanceof LinkTag);
LinkTag linkNode = (LinkTag) node[2];
assertStringEquals(
"Link incorrect!!",
"http://photo.kimo.com.tw",
linkNode.getLink());
assertEquals(
"Link beginning",
new Integer(48),
new Integer(linkNode.elementBegin()));
assertEquals(
"Link ending",
new Integer(38),
new Integer(linkNode.elementEnd()));
LinkTag linkNode2 = (LinkTag) node[4];
assertStringEquals(
"Link incorrect!!",
"http://address.kimo.com.tw",
linkNode2.getLink());
assertEquals(
"Link beginning",
new Integer(46),
new Integer(linkNode2.elementBegin()));
assertEquals(
"Link ending",
new Integer(42),
new Integer(linkNode2.elementEnd()));
}
/**
* This bug occurs when there is a null pointer exception thrown while scanning a tag using LinkScanner.
* Creation date: (7/1/2001 2:42:13 PM)
*/
public void testLinkNodeBugNullPointerException() throws ParserException
{
createParser(
"
|