You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jb...@apache.org on 2007/03/14 14:08:22 UTC

svn commit: r518123 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket: WicketTestCase.java markup/html/link/DownloadLinkTest.java protocol/http/WebResponseExceptionsTest.java

Author: jbq
Date: Wed Mar 14 06:08:21 2007
New Revision: 518123

URL: http://svn.apache.org/viewvc?view=rev&rev=518123
Log:
Adding utility methods in WicketTestCase

Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/WicketTestCase.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/DownloadLinkTest.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/protocol/http/WebResponseExceptionsTest.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/WicketTestCase.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/WicketTestCase.java?view=diff&rev=518123&r1=518122&r2=518123
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/WicketTestCase.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/WicketTestCase.java Wed Mar 14 06:08:21 2007
@@ -18,6 +18,7 @@
 
 import junit.framework.TestCase;
 import wicket.behavior.AbstractAjaxBehavior;
+import wicket.protocol.http.MockHttpServletResponse;
 import wicket.util.tester.WicketTester;
 
 /**
@@ -54,6 +55,7 @@
 	{
 		tester = new WicketTester();
 	}
+
 	protected void tearDown() throws Exception
 	{
 		tester.destroy();
@@ -67,8 +69,7 @@
 	 * @param filename
 	 * @throws Exception
 	 */
-	protected void executeTest(final Class pageClass, final String filename)
-			throws Exception
+	protected void executeTest(final Class pageClass, final String filename) throws Exception
 	{
 		System.out.println("=== " + pageClass.getName() + " ===");
 
@@ -112,5 +113,45 @@
 
 		tester.executeBehavior(behavior);
 		tester.assertResultPage(pageClass, filename);
+	}
+
+	protected String getContentType()
+	{
+		return ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse())
+				.getHeader("Content-Type");
+	}
+
+	protected int getContentLength()
+	{
+		String contentLength = ((MockHttpServletResponse)tester.getWicketResponse()
+				.getHttpServletResponse()).getHeader("Content-Length");
+		if (contentLength == null)
+			throw new WicketRuntimeException("No Content-Length header found");
+		return Integer.parseInt(contentLength);
+	}
+
+	protected String getLastModified()
+	{
+		return ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse())
+				.getHeader("Last-Modified");
+	}
+
+	protected String getContentDisposition()
+	{
+		return ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse())
+				.getHeader("Content-Disposition");
+	}
+
+	protected void assertAjaxLocation()
+	{
+		assertNull("Location header should *not* be present when using Ajax",
+				((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse())
+						.getRedirectLocation());
+		String ajaxLocation = ((MockHttpServletResponse)tester.getWicketResponse()
+				.getHttpServletResponse()).getHeader("Ajax-Location");
+		assertNotNull("Ajax-Location header should be present when using Ajax", ajaxLocation);
+		int statusCode = ((MockHttpServletResponse)tester.getWicketResponse()
+				.getHttpServletResponse()).getStatus();
+		assertEquals(200, statusCode);
 	}
 }

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/DownloadLinkTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/DownloadLinkTest.java?view=diff&rev=518123&r1=518122&r2=518123
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/DownloadLinkTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/markup/html/link/DownloadLinkTest.java Wed Mar 14 06:08:21 2007
@@ -64,22 +64,4 @@
 		log.debug("Content-Type: " + getContentType());
 		assertTrue(getContentType().startsWith(APPLICATION_X_CUSTOM));
 	}
-
-	private String getContentType()
-	{
-		return ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse())
-				.getHeader("Content-Type");
-	}
-
-	private int getContentLength()
-	{
-		return Integer.parseInt(((MockHttpServletResponse)tester.getWicketResponse()
-				.getHttpServletResponse()).getHeader("Content-Length"));
-	}
-
-	private String getContentDisposition()
-	{
-		return ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse())
-				.getHeader("Content-Disposition");
-	}
 }

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/protocol/http/WebResponseExceptionsTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/protocol/http/WebResponseExceptionsTest.java?view=diff&rev=518123&r1=518122&r2=518123
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/protocol/http/WebResponseExceptionsTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/wicket/protocol/http/WebResponseExceptionsTest.java Wed Mar 14 06:08:21 2007
@@ -16,15 +16,11 @@
  */
 package wicket.protocol.http;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import wicket.WicketTestCase;
 import wicket.ajax.AjaxEventBehavior;
 import wicket.ajax.markup.html.AjaxLink;
 import wicket.settings.IExceptionSettings;
 import wicket.settings.IRequestCycleSettings;
-import wicket.util.tester.WicketTester;
 
 /**
  * Test exceptions thrown during request
@@ -33,8 +29,6 @@
  */
 public class WebResponseExceptionsTest extends WicketTestCase
 {
-	private static final Log log = LogFactory.getLog(WebResponseExceptionsTest.class);
-
 	public void testInternalErrorPage()
 	{
 		tester.startPage(TestErrorPage.class);
@@ -58,7 +52,7 @@
 		WebRequestCycle cycle = tester.createRequestCycle();
 		cycle.request();
 
-		assertAjaxLocation(tester);
+		assertAjaxLocation();
 	}
 
 	public void testBufferedExceptionErrorPage() {
@@ -102,15 +96,6 @@
 		WebRequestCycle cycle = tester.createRequestCycle();
 		cycle.request();
 
-		assertAjaxLocation(tester);
-	}
-
-	private void assertAjaxLocation(WicketTester tester) {
-		assertNull("Location header should *not* be present when using Ajax", ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse()).getRedirectLocation());
-		String ajaxLocation = ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse()).getHeader("Ajax-Location");
-		log.debug(ajaxLocation);
-		assertNotNull("Ajax-Location header should be present when using Ajax", ajaxLocation);
-		int statusCode = ((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse()).getStatus();
-		assertEquals(200, statusCode);
+		assertAjaxLocation();
 	}
 }