Revision: 659
          http://svn.sourceforge.net/jwebunit/?rev=659&view=rev
Author:   henryju
Date:     2007-01-21 10:51:47 -0800 (Sun, 21 Jan 2007)

Log Message:
-----------
Let beginAt and gotoPage raise an Exception when the server return a bad Http 
response code.

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/exception/TestingEngineResponseException.java
    
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
    branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj

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
        2007-01-21 14:09:57 UTC (rev 658)
+++ 
branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/NavigationTest.java
        2007-01-21 18:51:47 UTC (rev 659)
@@ -4,6 +4,7 @@
  
******************************************************************************/
 package net.sourceforge.jwebunit.tests;
 
+import net.sourceforge.jwebunit.exception.TestingEngineResponseException;
 import net.sourceforge.jwebunit.tests.util.JettySetup;
 import junit.framework.AssertionFailedError;
 import junit.framework.Test;
@@ -47,7 +48,7 @@
        public void testInvalidBeginAt() {
 
                //the testing engines should throw an exception if a 404 Error 
is found.
-        assertFail("beginAt", "/nosuchresource.html");
+        assertException(TestingEngineResponseException.class, "beginAt", new 
Object[] {"/nosuchresource.html"});
 
        }
 

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/exception/TestingEngineResponseException.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/exception/TestingEngineResponseException.java
     2007-01-21 14:09:57 UTC (rev 658)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/exception/TestingEngineResponseException.java
     2007-01-21 18:51:47 UTC (rev 659)
@@ -13,9 +13,9 @@
  * 
  * @author Nicholas Neuberger
  */
-public class TestingEngineResponseException extends Exception {
+public class TestingEngineResponseException extends RuntimeException {
 
-    private int httpStatusCode;
+    private int httpStatusCode = -1;
 
     /**
      * 
@@ -34,8 +34,13 @@
         this.httpStatusCode = httpStatusCode;
     }
 
+    public TestingEngineResponseException(int httpStatusCode, String msg, 
Throwable ex) {
+        super(msg, ex);
+        this.httpStatusCode = httpStatusCode;
+    }
+
     public TestingEngineResponseException(int httpStatusCode, Exception e) {
-        super(e);
+        super("The server return "+httpStatusCode+" HTTP code.", e);
         this.httpStatusCode = httpStatusCode;
     }
 
@@ -61,6 +66,11 @@
         super(ex);
     }
 
+    /**
+     * Return the HTTP status code that throw this Exception or -1 if this 
exception
+     * was not thrown because of HTTP status code.
+     * @return
+     */
     public int getHttpStatusCode() {
         return httpStatusCode;
     }

Modified: 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2007-01-21 14:09:57 UTC (rev 658)
+++ 
branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2007-01-21 18:51:47 UTC (rev 659)
@@ -182,13 +182,11 @@
      * should start with "http://";, "https://"; or "www.".
      * 
      * @param url absolute or relative URL (relative to base URL).
+     * @throws TestingEngineResponseException If something bad happend (404)
      */
-    public void beginAt(String aRelativeURL) {
+    public void beginAt(String aRelativeURL) throws 
TestingEngineResponseException {
         try {
             getTestingEngine().beginAt(createUrl(aRelativeURL, 
getTestContext().getBaseUrl()), testContext);
-        } catch (TestingEngineResponseException e) {
-            Assert.fail("The server returns the code " + e.getHttpStatusCode()
-                    + "\n" + e.getCause().getMessage());
         } catch (MalformedURLException e) {
             Assert.fail(e.getLocalizedMessage());
         }
@@ -2030,12 +2028,11 @@
      * should start with "http://";, "https://"; or "www.".
      * 
      * @param url absolute or relative URL (relative to base URL).
+     * @throws TestingEngineResponseException If something bad happend (404)
      */
-    public void gotoPage(String url) {
+    public void gotoPage(String url) throws TestingEngineResponseException {
         try {
             getTestingEngine().gotoPage(createUrl(url, 
getTestContext().getBaseUrl()));
-        } catch (TestingEngineResponseException e) {
-            Assert.fail("The server returns the code " + 
e.getHttpStatusCode());
         } catch (MalformedURLException e) {
             Assert.fail(e.getLocalizedMessage());
         }

Modified: branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj
===================================================================
--- branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj      
2007-01-21 14:09:57 UTC (rev 658)
+++ branches/1.x/jwebunit-webtestcase-generator/src/main/javacc/Java1.5.jj      
2007-01-21 18:51:47 UTC (rev 659)
@@ -492,6 +492,7 @@
   sb.append("import java.io.PrintStream;\n");
   sb.append("import java.net.URL;\n\n");
   sb.append("import net.sourceforge.jwebunit.api.IJWebUnitDialog;\n");
+  sb.append("import 
net.sourceforge.jwebunit.exception.TestingEngineResponseException;\n");
   sb.append("import net.sourceforge.jwebunit.html.Table;\n");
   sb.append("import net.sourceforge.jwebunit.util.TestContext;\n\n");
   sb.append("import junit.framework.TestCase;\n\n");}


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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to