001: /******************************************************************************
002: * jWebUnit project (http://jwebunit.sourceforge.net) *
003: * Distributed open-source, see full license under LICENCE.txt *
004: ******************************************************************************/package net.sourceforge.jwebunit.tests;
005:
006: import net.sourceforge.jwebunit.exception.TestingEngineResponseException;
007: import net.sourceforge.jwebunit.tests.util.JettySetup;
008: import junit.framework.AssertionFailedError;
009: import junit.framework.Test;
010: import junit.framework.TestSuite;
011:
012: /**
013: * Test url navigation methods on WebTestCase (starting at a url, navigating
014: * links).
015: *
016: * @author Jim Weaver
017: * @author Wilkes Joiner
018: */
019: public class NavigationTest extends JWebUnitAPITestCase {
020:
021: public static Test suite() {
022: Test suite = new TestSuite(NavigationTest.class);
023: return new JettySetup(suite);
024: }
025:
026: public void setUp() throws Exception {
027: super .setUp();
028: getTestContext().setBaseUrl(HOST_PATH + "/NavigationTest");
029: }
030:
031: public void testBeginAtRelative() {
032: beginAt("/blah.html");
033: }
034:
035: public void testBeginAtAbsolute() {
036: beginAt(HOST_PATH + "/NavigationTest/blah.html");
037: }
038:
039: public void testForwardSlashConfusion() throws Exception {
040: beginAt("/blah.html");
041: beginAt("blah.html");
042: getTestContext().setBaseUrl(HOST_PATH + "/NavigationTest/");
043: beginAt("/blah.html");
044: beginAt("blah.html");
045: }
046:
047: public void testInvalidBeginAt() {
048:
049: //the testing engines should throw an exception if a 404 Error is found.
050: assertException(TestingEngineResponseException.class,
051: "beginAt", new Object[] { "/nosuchresource.html" });
052:
053: }
054:
055: public void testClickLinkWithText() {
056: beginAt("/pageWithLink.html");
057: assertTitleEquals("pageWithLink");
058:
059: clickLinkWithText("an active link");
060: assertTitleEquals("targetPage");
061: }
062:
063: public void testClickLinkWithTextN() {
064: beginAt("/pageWithLink.html");
065: assertTitleEquals("pageWithLink");
066:
067: clickLinkWithText("an active link", 0);
068: assertTitleEquals("targetPage");
069:
070: beginAt("/pageWithLink.html");
071: clickLinkWithText("an active link", 1);
072:
073: assertTitleEquals("targetPage2");
074: beginAt("/pageWithLink.html");
075: try {
076: clickLinkWithText("an active link", 2);
077: fail();
078: } catch (AssertionFailedError expected) {
079: assertEquals(
080: "Link with text [an active link] and index [2] "
081: + "not found in response.", expected
082: .getMessage());
083: }
084: assertTitleEquals("pageWithLink");
085: }
086:
087: public void testClickLinkWithImage() {
088: beginAt("/pageWithLink.html");
089: assertTitleEquals("pageWithLink");
090:
091: clickLinkWithImage("graphic.jpg");
092: assertTitleEquals("targetPage2");
093: }
094:
095: public void testClickLinkByID() {
096: beginAt("/pageWithLink.html");
097: assertTitleEquals("pageWithLink");
098:
099: clickLink("activeID");
100: assertTitleEquals("targetPage");
101: }
102:
103: public void testInvalidClickLink() {
104: beginAt("/pageWithLink.html");
105: assertTitleEquals("pageWithLink");
106:
107: try {
108: clickLinkWithText("no such link");
109: } catch (Throwable t) {
110: return;
111: }
112: fail("Expected exception");
113: }
114:
115: public void testGotoPageRelative() {
116: beginAt("/targetPage.html");
117: assertTitleEquals("targetPage");
118: gotoPage("/targetPage2.html");
119: assertTitleEquals("targetPage2");
120: }
121:
122: public void testGotoPageAbsolute() {
123: beginAt("/targetPage.html");
124: assertTitleEquals("targetPage");
125: gotoPage(HOST_PATH + "/NavigationTest/targetPage2.html");
126: assertTitleEquals("targetPage2");
127: }
128:
129: //For bug 726143
130: public void testLinkWithEscapedText() {
131: beginAt("/pageWithAmpersandInLink.html");
132: assertLinkPresentWithText("Map & Directions");
133: clickLinkWithText("Map & Directions");
134: assertTitleEquals("targetPage");
135: }
136: }
|