⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linktagtest.java

📁 html to xml convertor
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        assertEquals("Tag Contents",html,tag.toHtml());        assertEquals("Node 0 should have one child", 1, tag.getChildren ().size ());        assertTrue("The child should be a string node", tag.getChildren ().elementAt (0) instanceof Text);        Text stringNode = (Text)tag.getChildren ().elementAt (0);        assertEquals("Text Contents","Revision",stringNode.getText());    }    /**     * Test suggested by Cedric Rosa     * A really bad link tag sends parser into infinite loop     */    public void testBrokenLink() throws ParserException {        createParser(            "<a href=\"faq.html\">" +                "<br>\n"+                "<img src=\"images/46revues.gif\" " +                     "width=\"100\" " +                     "height=\"46\" " +                     "border=\"0\" " +                     "alt=\"Rejoignez revues.org!\" " +                     "align=\"middle\">",            "http://www.yahoo.com"        );        parseAndAssertNodeCount(1);        assertTrue("Node 0 should be a link tag",node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag)node[0];        assertNotNull(linkTag.toString());    }    public void testLinkDataContents() throws ParserException {        createParser("<a href=\"http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689\" target=\"_new\"><img src=\"http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif\" width=468 height=60 border=\"0\" alt=\"See Signs in Theaters 8-2 - Starring Mel Gibson\" align=><font face=\"verdana,arial,helvetica\" SIZE=\"1\"><b></b></font></a>","http://transfer.go.com");        parser.setNodeFactory (            new PrototypicalNodeFactory (                new Tag[] {                    new LinkTag (),                    new ImageTag (),                }));        parseAndAssertNodeCount(1);        assertTrue("Node 0 should be a link tag",node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag)node[0];        assertEquals("Link URL","http://transfer.go.com/cgi/atransfer.pl?goto=http://www.signs.movies.com&name=114332&srvc=nws&context=283&guid=4AD5723D-C802-4310-A388-0B24E1A79689",linkTag.getLink());        assertEquals("Link Text","",linkTag.getLinkText());        Node [] containedNodes = new Node[10];        int i=0;        for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) {            containedNodes[i++] = e.nextNode();        }        assertEquals("There should be 5 contained nodes in the link tag",5,i);        assertTrue("First contained node should be an image tag",containedNodes[0] instanceof ImageTag);        ImageTag imageTag = (ImageTag)containedNodes[0];        assertEquals("Image Location","http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif",imageTag.getImageURL());        assertEquals("Image Height","60",imageTag.getAttribute("HEIGHT"));        assertEquals("Image Width","468",imageTag.getAttribute("WIDTH"));        assertEquals("Image Border","0",imageTag.getAttribute("BORDER"));        assertEquals("Image Alt","See Signs in Theaters 8-2 - Starring Mel Gibson",imageTag.getAttribute("ALT"));        assertTrue("Second contained node should be Tag",containedNodes[1] instanceof Tag);        Tag tag1 = (Tag)containedNodes[1];        assertEquals("Tag Contents","font face=\"verdana,arial,helvetica\" SIZE=\"1\"",tag1.getText());        assertTrue("Third contained node should be Tag",containedNodes[2] instanceof Tag);        Tag tag2 = (Tag)containedNodes[2];        assertEquals("Tag Contents","b",tag2.getText());        assertTrue("Fourth contained node should be a Tag",containedNodes[3] instanceof Tag);        Tag tag = (Tag)containedNodes[3];        assertTrue("Fourth contained node should be an EndTag",tag.isEndTag ());        assertEquals("Fourth Tag contents","/b",tag.getText());        assertTrue("Fifth contained node should be a Tag",containedNodes[4] instanceof Tag);        tag = (Tag)containedNodes[4];        assertTrue("Fifth contained node should be an EndTag",tag.isEndTag ());        assertEquals("Fifth Tag contents","/font",tag.getText());    }    public void testBaseRefLink() throws ParserException {        createParser("<html>\n"+            "<head>\n"+            "<TITLE>test page</TITLE>\n"+            "<BASE HREF=\"http://www.abc.com/\">\n"+            "<a href=\"home.cfm\">Home</a>\n"+            "...\n"+            "</html>","http://transfer.go.com");        parseAndAssertNodeCount(1);        assertTrue("Node 1 should be a HTML tag", node[0] instanceof Html);        Html html = (Html)node[0];        assertTrue("Html tag should have 2 children", 2 == html.getChildCount ());        assertTrue("Html 2nd child should be HEAD tag", html.getChild (1) instanceof HeadTag);        HeadTag head = (HeadTag)html.getChild (1);        assertTrue("Head tag should have 7 children", 7 == head.getChildCount ());        assertTrue("Head 6th child should be a link tag", head.getChild (5) instanceof LinkTag);        LinkTag linkTag = (LinkTag)head.getChild (5);        assertEquals("Resolved Link","http://www.abc.com/home.cfm",linkTag.getLink());        assertEquals("Resolved Link Text","Home",linkTag.getLinkText());    }    /**     * This is a reproduction of bug 617228, reported by     * Stephen J. Harrington. When faced with a link like :     * &lt;A     * HREF="/cgi-bin/view_search?query_text=postdate&gt;20020701&txt_clr=White&bg_clr=Red&url=http://loc     * al     * host/Testing/Report     * 1.html"&gt;20020702 Report 1&lt;/A&gt;     *     * parser is unable to handle the link correctly due to the greater than     * symbol being confused to be the end of the tag.     */    public void testQueryLink() throws ParserException {        createParser("<A \n"+        "HREF=\"/cgi-bin/view_search?query_text=postdate>20020701&txt_clr=White&bg_clr=Red&url=http://localhost/Testing/Report1.html\">20020702 Report 1</A>","http://transfer.go.com");        parseAndAssertNodeCount(1);        assertTrue("Node 1 should be a link tag",node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag)node[0];        assertStringEquals("Resolved Link","http://transfer.go.com/cgi-bin/view_search?query_text=postdate>20020701&txt_clr=White&bg_clr=Red&url=http://localhost/Testing/Report1.html",linkTag.getLink());        assertEquals("Resolved Link Text","20020702 Report 1",linkTag.getLinkText());    }    public void testNotMailtoLink() throws ParserException {        createParser("<A HREF=\"mailto.html\">not@for.real</A>","http://www.cj.com/");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        assertEquals("Link Plain Text", "not@for.real", linkTag.toPlainTextString());        assertTrue("Link is not a mail link", !linkTag.isMailLink());    }    public void testMailtoLink() throws ParserException {        createParser("<A HREF=\"mailto:this@is.real\">this@is.real</A>","http://www.cj.com/");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        assertEquals("Link Plain Text", "this@is.real", linkTag.toPlainTextString());        assertTrue("Link is a mail link", linkTag.isMailLink());    }    public void testJavascriptLink() throws ParserException {        createParser("<A HREF=\"javascript:alert('hello');\">say hello</A>","http://www.cj.com/");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        assertEquals("Link Plain Text", "say hello", linkTag.toPlainTextString());        assertTrue("Link is a Javascript command", linkTag.isJavascriptLink());    }    public void testNotJavascriptLink() throws ParserException {        createParser("<A HREF=\"javascript_not.html\">say hello</A>","http://www.cj.com/");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        assertEquals("Link Plain Text", "say hello", linkTag.toPlainTextString());        assertTrue("Link is not a Javascript command", !linkTag.isJavascriptLink());    }    public void testFTPLink() throws ParserException {        createParser("<A HREF=\"ftp://some.where.it\">my ftp</A>","http://www.cj.com/");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        assertEquals("Link Plain Text", "my ftp", linkTag.toPlainTextString());        assertTrue("Link is a FTP site", linkTag.isFTPLink());    }    public void testNotFTPLink() throws ParserException {        createParser("<A HREF=\"ftp.html\">my ftp</A>","http://www.cj.com/");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        assertEquals("Link Plain Text", "my ftp", linkTag.toPlainTextString());        assertTrue("Link is not a FTP site", !linkTag.isFTPLink());    }    public void testRelativeLinkNotHTMLBug() throws ParserException {        createParser("<A HREF=\"newpage.html\">New Page</A>","http://www.mysite.com/books/some.asp");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        assertEquals("Link","http://www.mysite.com/books/newpage.html",linkTag.getLink());    }    public void testBadImageInLinkBug() throws ParserException {        createParser("<a href=\"registration.asp?EventID=1272\"><img border=\"0\" src=\"\\images\\register.gif\"</a>","http://www.fedpage.com/Event.asp?EventID=1272");        parseAndAssertNodeCount(1);        assertTrue("Node should be a HTMLLinkTag", node[0] instanceof LinkTag);        LinkTag linkTag = (LinkTag) node[0];        // Get the image tag from the link        Node insideNodes [] = new Node[10];        int j =0 ;        for (SimpleNodeIterator e = linkTag.children();e.hasMoreNodes();) {            insideNodes[j++]= e.nextNode();        }        assertEquals("Number of contained internal nodes",1,j);        assertTrue(insideNodes[0] instanceof ImageTag);        ImageTag imageTag = (ImageTag)insideNodes[0];        assertEquals("Image Tag Location","http://www.fedpage.com/images\\register.gif",imageTag.getImageURL());    }    /**     * This is an attempt to reproduce bug 677874     * reported by James Moliere. A link tag of the form     * <code>     * <a class=rlbA href=/news/866201.asp?0sl=-     * 32>Shoe bomber handed life sentence</a>     * </code>     * is not parsed correctly. The second '=' sign in the link causes     * the parser to treat it as a seperate attribute     */    public void testLinkContainsEqualTo() throws Exception {        createParser(            "<a class=rlbA href=/news/866201.asp?0sl=-" +            "32>Shoe bomber handed life sentence</a>"        );        parseAndAssertNodeCount(1);        assertType("node type",LinkTag.class,node[0]);        LinkTag linkTag = (LinkTag)node[0];        assertStringEquals(            "link text",            "Shoe bomber handed life sentence",            linkTag.getLinkText()        );        assertStringEquals(            "link url",            "/news/866201.asp?0sl=-32",            linkTag.getLink()        );    }    /**     * Bug report by Cory Seefurth     * @throws Exception     */    public void _testLinkWithJSP() throws Exception {        createParser(            "<a href=\"<%=Application(\"sURL\")% " +            ">/literature/index.htm\">Literature</a>"        );        parseAndAssertNodeCount(1);        assertType("should be link tag",LinkTag.class,node[0]);        LinkTag linkTag = (LinkTag)node[0];        assertStringEquals("expected link","<%=Application(\"sURL\")%>/literature/index.htm",linkTag.getLink());    }    public void testTagSymbolsInLinkText() throws Exception {        createParser(            "<a href=\"/cataclysm/Langy-AnEmpireReborn-Ch2.shtml#story\"" +            "><< An Empire Reborn: Chapter 2 <<</a>"        );        parseAndAssertNodeCount(1);        assertType("node",LinkTag.class, node[0]);        LinkTag linkTag = (LinkTag)node[0];        assertEquals("link text","<< An Empire Reborn: Chapter 2 <<",linkTag.getLinkText());    }    /**     * See bug #813838 links not parsed correctly     */    public void testPlainText() throws Exception    {        String html = "<a href=Cities/><b>Cities</b></a>";        createParser (html);        parseAndAssertNodeCount (1);        assertType("node", LinkTag.class, node[0]);        LinkTag linkTag = (LinkTag)node[0];        assertEquals ("plain text", "Cities", linkTag.toPlainTextString ());    }    /**     * See bug #982175 False Positives on &reg; entity     */    public void testCharacterReferenceInLink() throws Exception    {        String html = "<a href=\"http://www.someplace.com/somepage.html?&region=us\">Search By Region</a>" +	        "<a href=\"http://www.someplace.com/somepage.html?&region=&destination=184\">Search by Destination</a>";        createParser (html);        parseAndAssertNodeCount (2);        assertType("node", LinkTag.class, node[0]);        LinkTag linkTag = (LinkTag)node[0];        assertEquals ("link", "http://www.someplace.com/somepage.html?&region=us", linkTag.getLink());        assertType("node", LinkTag.class, node[1]);        linkTag = (LinkTag)node[1];        assertEquals ("link", "http://www.someplace.com/somepage.html?&region=&destination=184", linkTag.getLink());    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -