1 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 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 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
|