Revision: 590
          http://svn.sourceforge.net/jwebunit/?rev=590&view=rev
Author:   henryju
Date:     2006-10-26 08:30:11 -0700 (Thu, 26 Oct 2006)

Log Message:
-----------
Backport from trunk : Add possibility to give absolute URL to beginAt and 
gotoPage. 
(https://sourceforge.net/tracker/?func=detail&atid=497984&aid=1554148&group_id=61302)

Modified Paths:
--------------
    
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    branches/1.x/src/changes/changes.xml

Modified: 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
===================================================================
--- 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
        2006-10-26 15:17:39 UTC (rev 589)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
        2006-10-26 15:30:11 UTC (rev 590)
@@ -28,10 +28,14 @@
                getTestContext().setBaseUrl(HOST_PATH + "/NavigationTest");
        }
 
-       public void testBeginAt() {
+       public void testBeginAtRelative() {
                beginAt("/blah.html");
        }
 
+        public void testBeginAtAbsolute() {
+            beginAt(HOST_PATH + "/NavigationTest/blah.html");
+        }
+
        public void testForwardSlashConfusion() throws Exception {
                beginAt("/blah.html");
                beginAt("blah.html");
@@ -77,16 +81,6 @@
                assertTitleEquals("pageWithLink");
        }
 
-//     public void testClickLinkWithTextAfterText() {  
-//             beginAt("/pageWithLinkWithTextAfterText.html");
-//             clickLinkWithTextAfterText("link text", "First:");
-//             assertTitleEquals("targetPage");
-//
-//             beginAt("/pageWithLinkWithTextAfterText.html");
-//             clickLinkWithTextAfterText("link text", "Second:");
-//             assertTitleEquals("targetPage2");
-//     }
-
        public void testClickLinkWithImage() {
                beginAt("/pageWithLink.html");
                assertTitleEquals("pageWithLink");
@@ -115,13 +109,20 @@
                fail("Expected exception");
        }
 
-       public void testGotoPage() {
+       public void testGotoPageRelative() {
                beginAt("/targetPage.html");
                assertTitleEquals("targetPage");
                gotoPage("/targetPage2.html");
                assertTitleEquals("targetPage2");
        }
 
+       public void testGotoPageAbsolute() {
+               beginAt("/targetPage.html");
+               assertTitleEquals("targetPage");
+                gotoPage(HOST_PATH + "/NavigationTest/targetPage2.html");
+               assertTitleEquals("targetPage2");
+       }
+
        //For bug 726143
        public void testLinkWithEscapedText() {
                beginAt("/pageWithAmpersandInLink.html");

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    2006-10-26 15:17:39 UTC (rev 589)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
    2006-10-26 15:30:11 UTC (rev 590)
@@ -144,10 +144,13 @@
        }
 
        /**
-        * Begin conversation at a url relative to the application root.
-        * 
-        * @param relativeURL
-        */
+         * Begin conversation at a URL absolute or relative to base URL. Use
+         * [EMAIL PROTECTED] TestContext#setBaseUrl(String) 
getTestContext().setBaseUrl(String)}
+         * to define base URL. Absolute URL should start with "http://";, 
"https://"; or "www.".
+         *
+         * @param url
+         *            absolute or relative URL (relative to base URL).
+         */
        public void beginAt(String aRelativeURL) {
                try {
                        getDialog().beginAt(createUrl(aRelativeURL), 
testContext);
@@ -157,10 +160,18 @@
 
        }
 
-       private String createUrl(String aSuffix) {
-               aSuffix = aSuffix.startsWith("/") ? aSuffix.substring(1) : 
aSuffix;
-               return getTestContext().getBaseUrl() + aSuffix;
-       }
+       private String createUrl(String url) {
+            if (url.startsWith("http://";) || url.startsWith("https://";)) {
+                return url;
+            }
+            else if (url.startsWith("www.")) {
+                return "http://"; + url;
+            }
+            else {
+                url = url.startsWith("/") ? url.substring(1) : url;
+                return getTestContext().getBaseUrl() + url;
+            }
+        }
 
        /**
         * Return the value of a web resource based on its key. This translates 
to a
@@ -2055,8 +2066,14 @@
        }
 
        /**
-        * Patch sumbitted by Alex Chaffee.
-        */
+         * Go to the given page like if user has typed the URL manually in the
+         * browser. Use
+         * [EMAIL PROTECTED] TestContext#setBaseUrl(String) 
getTestContext().setBaseUrl(String)}
+         * to define base URL. Absolute URL should start with "http://";, 
"https://"; or "www.".
+         *
+         * @param url
+         *            absolute or relative URL (relative to base URL).
+         */
        public void gotoPage(String url) {
                try {
                        getDialog().gotoPage(createUrl(url));

Modified: branches/1.x/src/changes/changes.xml
===================================================================
--- branches/1.x/src/changes/changes.xml        2006-10-26 15:17:39 UTC (rev 
589)
+++ branches/1.x/src/changes/changes.xml        2006-10-26 15:30:11 UTC (rev 
590)
@@ -8,6 +8,9 @@
     </properties>
     <body>
         <release version="1.4" date="UNKNOW">
+             <action type="fix" dev="Julien Henry" due-to="Joe Athman" 
issue="1554148">
+                beginAt and gotoPage now accept absolute URL beginning with 
"http://";, "https://"; or "www."
+            </action>
             <action type="add" dev="Julien Henry">
                 Add assertJavascriptAlertPresent method to check presence of a 
Javascript alert.
             </action>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to