KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > tagTests > BaseHrefTagTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/BaseHrefTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/02 00:49:31 $
10
// $Revision: 1.41 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests.tagTests;
28
29 import org.htmlparser.PrototypicalNodeFactory;
30 import org.htmlparser.Tag;
31 import org.htmlparser.tags.BaseHrefTag;
32 import org.htmlparser.tags.LinkTag;
33 import org.htmlparser.tags.TitleTag;
34 import org.htmlparser.tests.ParserTestCase;
35 import org.htmlparser.util.ParserException;
36
37 public class BaseHrefTagTest extends ParserTestCase {
38
39     static
40     {
41         System.setProperty ("org.htmlparser.tests.tagTests.BaseHrefTagTest", "BaseHrefTagTest");
42     }
43
44     public BaseHrefTagTest(String JavaDoc name) {
45         super(name);
46     }
47
48     public void testConstruction() {
49         BaseHrefTag baseRefTag = new BaseHrefTag ();
50         baseRefTag.setBaseUrl ("http://www.abc.com");
51         assertEquals("Expected Base URL","http://www.abc.com",baseRefTag.getBaseUrl());
52     }
53
54     public void testScan() throws ParserException{
55         createParser("<html><head><TITLE>test page</TITLE><BASE HREF=\"http://www.abc.com/\"><a HREF=\"home.cfm\">Home</a>...</html>","http://www.google.com/test/index.html");
56         parser.setNodeFactory (
57             new PrototypicalNodeFactory (
58                 new Tag[]
59                 {
60                     new TitleTag (),
61                     new LinkTag (),
62                     new BaseHrefTag (),
63                 }));
64         parseAndAssertNodeCount(7);
65         assertTrue("Base href tag should be the 4th tag", node[3] instanceof BaseHrefTag);
66         BaseHrefTag baseRefTag = (BaseHrefTag)node[3];
67         assertEquals("Base HREF Url","http://www.abc.com/",baseRefTag.getBaseUrl());
68     }
69
70     public void testNotHREFBaseTag() throws ParserException
71     {
72         String JavaDoc html = "<base target=\"_top\">";
73         createParser(html);
74         parseAndAssertNodeCount(1);
75         assertTrue("Should be a base tag but was "+node[0].getClass().getName(),node[0] instanceof BaseHrefTag);
76         BaseHrefTag baseTag = (BaseHrefTag)node[0];
77         assertStringEquals("Base Tag HTML", html, baseTag.toHtml());
78     }
79
80 }
81
Popular Tags