[Jwebunit-development] SF.net SVN: jwebunit: [636] branches/1.x
Brought to you by:
henryju
From: <he...@us...> - 2006-12-05 13:55:35
|
Revision: 636 http://svn.sourceforge.net/jwebunit/?rev=636&view=rev Author: henryju Date: 2006-12-05 05:55:33 -0800 (Tue, 05 Dec 2006) Log Message: ----------- Test redirection with new ThreadedRedirectionHandler. Modified Paths: -------------- branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml 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-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java branches/1.x/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java Added Paths: ----------- branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/RedirectionTest.java branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/RedirectServlet.java branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/RedirectionTest/ branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/RedirectionTest/redirect.html Added: branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/RedirectionTest.java =================================================================== --- branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/RedirectionTest.java (rev 0) +++ branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/RedirectionTest.java 2006-12-05 13:55:33 UTC (rev 636) @@ -0,0 +1,36 @@ +/****************************************************************************** + * jWebUnit project (http://jwebunit.sourceforge.net) * + * Distributed open-source, see full license under LICENCE.txt * + ******************************************************************************/ +package net.sourceforge.jwebunit.tests; + +import junit.framework.Test; +import junit.framework.TestSuite; +import net.sourceforge.jwebunit.tests.util.JettySetup; + +/** + * Test redirection support. + * + * @author Julien Henry + */ +public class RedirectionTest extends JWebUnitAPITestCase { + + public static Test suite() { + Test suite = new TestSuite(RedirectionTest.class); + return new JettySetup(suite); + } + + public void setUp() throws Exception { + super.setUp(); + getTestContext().setBaseUrl(HOST_PATH + "/RedirectionTest"); + } + + public void testRedirection() { + beginAt("/redirect.html"); + assertTitleEquals("Redirected"); + closeBrowser(); + beginAt(HOST_PATH + "/redirect.jsp"); + assertTitleEquals("Redirected"); + } + +} Added: branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/RedirectServlet.java =================================================================== --- branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/RedirectServlet.java (rev 0) +++ branches/1.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/RedirectServlet.java 2006-12-05 13:55:33 UTC (rev 636) @@ -0,0 +1,23 @@ +/****************************************************************************** + * jWebUnit project (http://jwebunit.sourceforge.net) * + * Distributed open-source, see full license under LICENCE.txt * + ******************************************************************************/ +package net.sourceforge.jwebunit.tests.util; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class RedirectServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + response.sendRedirect("/jwebunit/RedirectionTest/redirect.html"); + } + +} Added: branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/RedirectionTest/redirect.html =================================================================== --- branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/RedirectionTest/redirect.html (rev 0) +++ branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/RedirectionTest/redirect.html 2006-12-05 13:55:33 UTC (rev 636) @@ -0,0 +1,9 @@ +<html> + <head> + <title>Redirected</title> + </head> + <body> + <h1>The redirection works</h1> + <p>This page shows that the redirection works like expected.</p> + </body> +</html> \ No newline at end of file Modified: branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml =================================================================== --- branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml 2006-12-01 12:26:12 UTC (rev 635) +++ branches/1.x/jwebunit-commons-tests/src/main/resources/testcases/WEB-INF/web.xml 2006-12-05 13:55:33 UTC (rev 636) @@ -12,6 +12,10 @@ <servlet-name>CookiesServlet</servlet-name> <servlet-class>net.sourceforge.jwebunit.tests.util.CookiesServlet</servlet-class> </servlet> +<servlet> + <servlet-name>RedirectServlet</servlet-name> + <servlet-class>net.sourceforge.jwebunit.tests.util.RedirectServlet</servlet-class> +</servlet> <servlet-mapping> <servlet-name>ParamsServlet</servlet-name> <url-pattern>/params.jsp</url-pattern> @@ -20,6 +24,10 @@ <servlet-name>CookiesServlet</servlet-name> <url-pattern>/cookies.jsp</url-pattern> </servlet-mapping> +<servlet-mapping> + <servlet-name>RedirectServlet</servlet-name> + <url-pattern>/redirect.jsp</url-pattern> +</servlet-mapping> <security-constraint> <web-resource-collection> 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 2006-12-01 12:26:12 UTC (rev 635) +++ branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/exception/TestingEngineResponseException.java 2006-12-05 13:55:33 UTC (rev 636) @@ -16,7 +16,7 @@ public class TestingEngineResponseException extends Exception { private int httpStatusCode; - + /** * */ @@ -26,9 +26,19 @@ public TestingEngineResponseException(int httpStatusCode) { super(); - this.httpStatusCode=httpStatusCode; + this.httpStatusCode = httpStatusCode; } + public TestingEngineResponseException(int httpStatusCode, String msg) { + super(msg); + this.httpStatusCode = httpStatusCode; + } + + public TestingEngineResponseException(int httpStatusCode, Exception e) { + super(e); + this.httpStatusCode = httpStatusCode; + } + /** * @param arg0 */ 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 2006-12-01 12:26:12 UTC (rev 635) +++ branches/1.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java 2006-12-05 13:55:33 UTC (rev 636) @@ -181,7 +181,7 @@ try { getTestingEngine().beginAt(createUrl(aRelativeURL), testContext); } catch (TestingEngineResponseException e) { - Assert.fail("The server returns the code " + e.getHttpStatusCode()); + Assert.fail("The server returns the code " + e.getHttpStatusCode() + "\n" + e.getCause().getMessage()); } } Modified: branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java =================================================================== --- branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java 2006-12-01 12:26:12 UTC (rev 635) +++ branches/1.x/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitDialog.java 2006-12-05 13:55:33 UTC (rev 636) @@ -4,59 +4,17 @@ ******************************************************************************/ package net.sourceforge.jwebunit.htmlunit; -import org.apache.commons.httpclient.Cookie; -import org.apache.commons.httpclient.HttpState; -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.net.ConnectException; -import java.net.InetAddress; -import java.net.URL; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.apache.regexp.RE; -import org.apache.regexp.RESyntaxException; -import org.jaxen.JaxenException; - -import net.sourceforge.jwebunit.api.IJWebUnitDialog; -import net.sourceforge.jwebunit.exception.ExpectedJavascriptAlertException; -import net.sourceforge.jwebunit.exception.ExpectedJavascriptConfirmException; -import net.sourceforge.jwebunit.exception.ExpectedJavascriptPromptException; -import net.sourceforge.jwebunit.exception.TestingEngineResponseException; -import net.sourceforge.jwebunit.exception.UnableToSetFormException; -import net.sourceforge.jwebunit.exception.UnexpectedJavascriptAlertException; -import net.sourceforge.jwebunit.exception.UnexpectedJavascriptConfirmException; -import net.sourceforge.jwebunit.exception.UnexpectedJavascriptPromptException; -import net.sourceforge.jwebunit.html.Cell; -import net.sourceforge.jwebunit.html.Row; -import net.sourceforge.jwebunit.html.Table; -import net.sourceforge.jwebunit.javascript.JavascriptAlert; -import net.sourceforge.jwebunit.javascript.JavascriptConfirm; -import net.sourceforge.jwebunit.javascript.JavascriptPrompt; -import net.sourceforge.jwebunit.util.TestContext; - import com.gargoylesoftware.htmlunit.AlertHandler; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.ConfirmHandler; import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider; +import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.JavaScriptPage; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.PromptHandler; import com.gargoylesoftware.htmlunit.TextPage; +import com.gargoylesoftware.htmlunit.ThreadedRefreshHandler; import com.gargoylesoftware.htmlunit.UnexpectedPage; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebResponse; @@ -64,35 +22,75 @@ import com.gargoylesoftware.htmlunit.WebWindowEvent; import com.gargoylesoftware.htmlunit.WebWindowListener; import com.gargoylesoftware.htmlunit.WebWindowNotFoundException; +import com.gargoylesoftware.htmlunit.html.ClickableElement; import com.gargoylesoftware.htmlunit.html.FrameWindow; +import com.gargoylesoftware.htmlunit.html.HtmlAnchor; +import com.gargoylesoftware.htmlunit.html.HtmlButton; +import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; +import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlFileInput; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput; import com.gargoylesoftware.htmlunit.html.HtmlImageInput; import com.gargoylesoftware.htmlunit.html.HtmlInput; +import com.gargoylesoftware.htmlunit.html.HtmlOption; import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; -import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; +import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlResetInput; +import com.gargoylesoftware.htmlunit.html.HtmlSelect; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; -import com.gargoylesoftware.htmlunit.html.HtmlResetInput; import com.gargoylesoftware.htmlunit.html.HtmlTable; import com.gargoylesoftware.htmlunit.html.HtmlTableCell; -import com.gargoylesoftware.htmlunit.html.HtmlAnchor; -import com.gargoylesoftware.htmlunit.html.HtmlSelect; -import com.gargoylesoftware.htmlunit.html.HtmlOption; -import com.gargoylesoftware.htmlunit.html.HtmlElement; -import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; import com.gargoylesoftware.htmlunit.html.HtmlTableRow; -import com.gargoylesoftware.htmlunit.html.ClickableElement; -import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlTableRow.CellIterator; import com.gargoylesoftware.htmlunit.html.HtmlTextArea; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; -import com.gargoylesoftware.htmlunit.ElementNotFoundException; -import com.gargoylesoftware.htmlunit.html.HtmlTableRow.CellIterator; import com.gargoylesoftware.htmlunit.html.xpath.HtmlUnitXPath; import com.gargoylesoftware.htmlunit.xml.XmlPage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.InetAddress; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import net.sourceforge.jwebunit.api.IJWebUnitDialog; +import net.sourceforge.jwebunit.exception.ExpectedJavascriptAlertException; +import net.sourceforge.jwebunit.exception.ExpectedJavascriptConfirmException; +import net.sourceforge.jwebunit.exception.ExpectedJavascriptPromptException; +import net.sourceforge.jwebunit.exception.TestingEngineResponseException; +import net.sourceforge.jwebunit.exception.UnableToSetFormException; +import net.sourceforge.jwebunit.exception.UnexpectedJavascriptAlertException; +import net.sourceforge.jwebunit.exception.UnexpectedJavascriptConfirmException; +import net.sourceforge.jwebunit.exception.UnexpectedJavascriptPromptException; +import net.sourceforge.jwebunit.html.Cell; +import net.sourceforge.jwebunit.html.Row; +import net.sourceforge.jwebunit.html.Table; +import net.sourceforge.jwebunit.javascript.JavascriptAlert; +import net.sourceforge.jwebunit.javascript.JavascriptConfirm; +import net.sourceforge.jwebunit.javascript.JavascriptPrompt; +import net.sourceforge.jwebunit.util.TestContext; + +import org.apache.commons.httpclient.Cookie; +import org.apache.commons.httpclient.HttpState; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.apache.regexp.RE; +import org.apache.regexp.RESyntaxException; +import org.jaxen.JaxenException; + /** * Acts as the wrapper for HtmlUnit access. A dialog is initialized with a given URL, and maintains conversational state * as the dialog progresses through link navigation, form submission, etc. @@ -132,17 +130,17 @@ private boolean jsEnabled = true; /** - * Javascript alerts + * Javascript alerts. */ private LinkedList expectedJavascriptAlerts = new LinkedList(); /** - * Javascript alerts + * Javascript confirms. */ private LinkedList expectedJavascriptConfirms = new LinkedList(); /** - * Javascript alerts + * Javascript prompts. */ private LinkedList expectedJavascriptPrompts = new LinkedList(); @@ -164,7 +162,7 @@ win = wc.getCurrentWindow(); form = null; } catch (FailingHttpStatusCodeException aException) { - throw new TestingEngineResponseException(aException.getStatusCode()); + throw new TestingEngineResponseException(aException.getStatusCode(), aException); } catch (IOException aException) { throw new RuntimeException(aException); @@ -597,6 +595,8 @@ "4.0", testContext.getUserAgent(), "1.2", 6)); wc.setJavaScriptEnabled(jsEnabled); wc.setThrowExceptionOnScriptError(true); + wc.setRedirectEnabled(true); + //wc.setRefreshHandler(new ThreadedRefreshHandler()); DefaultCredentialsProvider creds = new DefaultCredentialsProvider(); if (getTestContext().hasAuthorization()) { creds.addCredentials(getTestContext().getUser(), getTestContext() Modified: branches/1.x/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java =================================================================== --- branches/1.x/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java 2006-12-01 12:26:12 UTC (rev 635) +++ branches/1.x/jwebunit-htmlunit-plugin/src/test/java/net/sourceforge/jwebunit/htmlunit/JWebUnitTest.java 2006-12-05 13:55:33 UTC (rev 636) @@ -18,19 +18,18 @@ */ public class JWebUnitTest extends TestCase { - /** - * Runs all the tests for jWebUnit. Add each new TestCase by using the - * <code>addTestSuite(Class)</code> method, so that the TestCase's - * <code>suite</code> method <strong>isn't called </strong>. This prevents - * <code>JettySetup</code> from starting the Jetty server twice and - * consequently the error 'port 80xx is already in use'. - * - * @return the <code>TestSuite</code> containing all the tests for - * jWebUnit ready to run utilizing Jetty as testserver. - */ + /** + * Runs all the tests for jWebUnit. Add each new TestCase by using the <code>addTestSuite(Class)</code> method, so + * that the TestCase's <code>suite</code> method <strong>isn't called </strong>. This prevents + * <code>JettySetup</code> from starting the Jetty server twice and consequently the error 'port 80xx is already + * in use'. + * + * @return the <code>TestSuite</code> containing all the tests for jWebUnit ready to run utilizing Jetty as + * testserver. + */ public static Test suite() { TestSuite suite = new TestSuite("Test for net.sourceforge.jwebunit"); - //$JUnit-BEGIN$ + // $JUnit-BEGIN$ suite.addTestSuite(FormSubmissionTest.class); suite.addTestSuite(WebAssertionsTest.class); suite.addTestSuite(FramesAndWindowsTest.class); @@ -49,7 +48,8 @@ suite.addTestSuite(CharsetTest.class); suite.addTestSuite(ButtonAssertionsTest.class); suite.addTestSuite(NonHtmlContentTest.class); - //$JUnit-END$ + suite.addTestSuite(RedirectionTest.class); + // $JUnit-END$ return new JettySetup(suite); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |