[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit WebLinkTest.java,1.23,1.24
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-09-13 14:17:28
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv23945/test/com/meterware/httpunit Modified Files: WebLinkTest.java Log Message: Make link searching mechanism more generic Index: WebLinkTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebLinkTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebLinkTest.java 15 Aug 2002 18:29:08 -0000 1.23 +++ WebLinkTest.java 13 Sep 2002 14:17:26 -0000 1.24 @@ -61,6 +61,7 @@ "have <a href=\"/other.html\" id=\"activeID\">an <b>active</b> link</A>\n" + " and <a name=here>an anchor</a>\n" + "<a href=\"basic.html\" name=\"nextLink\"><IMG SRC=\"/images/arrow.gif\" ALT=\"Next -->\" WIDTH=1 HEIGHT=4></a>\n" + + "<a href=\"another.html\" name=\"myLink\">some text</a>\n" + "</body></html>\n" ); WebConversation wc = new WebConversation(); @@ -80,8 +81,8 @@ public void testLinks() throws Exception { WebLink[] links = _simplePage.getLinks(); - assertNotNull( links ); - assertEquals( 2, links.length ); + assertNotNull( "Found no links", links ); + assertEquals( "number of links in page", 3, links.length ); } @@ -118,6 +119,24 @@ HttpUnitOptions.setImagesTreatedAsAltText( false ); link = _simplePage.getLinkWith( "Next -->" ); assertNull( "the image link was found based on its hidden alt attribute", link ); + } + + + public void testCustomMatching() throws Exception { + WebLink link = _simplePage.getFirstMatchingLink( WebLink.MATCH_URL_STRING, "nothing" ); + assertNull( "Non-existent link should not have been found", link ); + + link = _simplePage.getFirstMatchingLink( WebLink.MATCH_URL_STRING, "/other.html" ); + assertNotNull( "an active link was not found", link ); + assertEquals( "active link text", "an active link", link.asText() ); + + link = _simplePage.getFirstMatchingLink( WebLink.MATCH_URL_STRING, "basic" ); + assertNotNull( "the image link was not found", link ); + assertEquals( "image link URL", getHostPath() + "/basic.html", link.getRequest().getURL().toExternalForm() ); + + WebLink[] links = _simplePage.getMatchingLinks( WebLink.MATCH_URL_STRING, "other.ht" ); + assertNotNull( "No link array returned", links ); + assertEquals( "Number of links with URL containing 'other.ht'", 2, links.length ); } |