You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2007/09/18 05:58:54 UTC

svn commit: r576681 - /wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java

Author: jdonnerstag
Date: Mon Sep 17 20:58:53 2007
New Revision: 576681

URL: http://svn.apache.org/viewvc?rev=576681&view=rev
Log:
use application provided page factory

Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java?rev=576681&r1=576680&r2=576681&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java Mon Sep 17 20:58:53 2007
@@ -35,7 +35,6 @@
 import org.apache.wicket.request.target.component.BookmarkablePageRequestTarget;
 import org.apache.wicket.request.target.component.IBookmarkablePageRequestTarget;
 import org.apache.wicket.request.target.component.IPageRequestTarget;
-import org.apache.wicket.session.DefaultPageFactory;
 import org.apache.wicket.settings.IRequestCycleSettings;
 import org.apache.wicket.util.file.WebApplicationPath;
 import org.slf4j.Logger;
@@ -43,39 +42,35 @@
 
 
 /**
- * This class provides a mock implementation of a Wicket HTTP based tester that
- * can be used for testing. It emulates all of the functionality of an
- * HttpServlet in a controlled, single-threaded environment. It is supported
- * with mock objects for WebSession, HttpServletRequest, HttpServletResponse and
- * ServletContext.
+ * This class provides a mock implementation of a Wicket HTTP based tester that can be used for
+ * testing. It emulates all of the functionality of an HttpServlet in a controlled, single-threaded
+ * environment. It is supported with mock objects for WebSession, HttpServletRequest,
+ * HttpServletResponse and ServletContext.
  * <p>
- * In its most basic usage you can just create a new MockWebApplication and
- * provide your Wicket Application object. This should be sufficient to allow
- * you to construct components and pages and so on for testing. To use certain
- * features such as localization you must also call setupRequestAndResponse().
+ * In its most basic usage you can just create a new MockWebApplication and provide your Wicket
+ * Application object. This should be sufficient to allow you to construct components and pages and
+ * so on for testing. To use certain features such as localization you must also call
+ * setupRequestAndResponse().
  * <p>
- * The tester takes an optional path attribute that defines a directory on the
- * disk which will correspond to the root of the WAR bundle. This can then be
- * used for locating non-tester resources.
+ * The tester takes an optional path attribute that defines a directory on the disk which will
+ * correspond to the root of the WAR bundle. This can then be used for locating non-tester
+ * resources.
  * <p>
- * To actually test the processing of a particular page or component you can
- * also call processRequestCycle() to do all the normal work of a Wicket
- * request.
+ * To actually test the processing of a particular page or component you can also call
+ * processRequestCycle() to do all the normal work of a Wicket request.
  * <p>
- * Between calling setupRequestAndResponse() and processRequestCycle() you can
- * get hold of any of the objects for initialisation. The servlet request object
- * has some handy convenience methods for initialising the request to invoke
- * certain types of pages and components.
+ * Between calling setupRequestAndResponse() and processRequestCycle() you can get hold of any of
+ * the objects for initialisation. The servlet request object has some handy convenience methods for
+ * initialising the request to invoke certain types of pages and components.
  * <p>
- * After completion of processRequestCycle() you will probably just be testing
- * component states. However, you also have full access to the response document
- * (or binary data) and result codes via the servlet response object.
+ * After completion of processRequestCycle() you will probably just be testing component states.
+ * However, you also have full access to the response document (or binary data) and result codes via
+ * the servlet response object.
  * <p>
  * IMPORTANT NOTES
  * <ul>
- * <li>This harness is SINGLE THREADED - there is only one global session. For
- * multi-threaded testing you must do integration testing with a full tester
- * server.
+ * <li>This harness is SINGLE THREADED - there is only one global session. For multi-threaded
+ * testing you must do integration testing with a full tester server.
  * </ul>
  * 
  * @author Chris Turner
@@ -125,15 +120,14 @@
 	 * @param application
 	 *            The wicket application object
 	 * @param path
-	 *            The absolute path on disk to the web tester contents (e.g. war
-	 *            root) - may be null
+	 *            The absolute path on disk to the web tester contents (e.g. war root) - may be null
 	 * @see org.apache.wicket.protocol.http.MockServletContext
 	 */
 	public MockWebApplication(final WebApplication application, final String path)
 	{
 		this.application = application;
 
-		this.context = newServletContext(path);
+		context = newServletContext(path);
 
 		filter = new WicketFilter()
 		{
@@ -189,14 +183,13 @@
 		Application.set(this.application);
 
 		// Construct mock session, request and response
-		this.servletSession = new MockHttpSession(this.context);
-		this.servletRequest = new MockHttpServletRequest(this.application, this.servletSession,
-				this.context);
-		this.servletResponse = new MockHttpServletResponse();
+		servletSession = new MockHttpSession(context);
+		servletRequest = new MockHttpServletRequest(this.application, servletSession, context);
+		servletResponse = new MockHttpServletResponse();
 
 		// Construct request and response using factories
-		this.wicketRequest = this.application.newWebRequest(this.servletRequest);
-		this.wicketResponse = this.application.newWebResponse(this.servletResponse);
+		wicketRequest = this.application.newWebRequest(servletRequest);
+		wicketResponse = this.application.newWebResponse(servletResponse);
 
 		// Create request cycle
 		createRequestCycle();
@@ -222,13 +215,12 @@
 	 * Used to create a new mock servlet context.
 	 * 
 	 * @param path
-	 *            The absolute path on disk to the web tester contents (e.g. war
-	 *            root) - may be null
+	 *            The absolute path on disk to the web tester contents (e.g. war root) - may be null
 	 * @return ServletContext
 	 */
 	public ServletContext newServletContext(final String path)
 	{
-		return new MockServletContext(this.application, path);
+		return new MockServletContext(application, path);
 	}
 
 	/**
@@ -238,7 +230,7 @@
 	 */
 	public final WebApplication getApplication()
 	{
-		return this.application;
+		return application;
 	}
 
 	/**
@@ -334,7 +326,7 @@
 
 		if (component instanceof Page)
 		{
-			this.lastRenderedPage = (Page)component;
+			lastRenderedPage = (Page)component;
 		}
 		postProcessRequestCycle(cycle);
 	}
@@ -360,8 +352,7 @@
 	}
 
 	/**
-	 * Create and process the request cycle using the current request and
-	 * response information.
+	 * Create and process the request cycle using the current request and response information.
 	 */
 	public void processRequestCycle()
 	{
@@ -369,8 +360,7 @@
 	}
 
 	/**
-	 * Create and process the request cycle using the current request and
-	 * response information.
+	 * Create and process the request cycle using the current request and response information.
 	 * 
 	 * @param cycle
 	 */
@@ -401,21 +391,21 @@
 			// transparently
 			final MockHttpServletResponse httpResponse = (MockHttpServletResponse)cycle
 					.getWebResponse().getHttpServletResponse();
-	
+
 			if (httpResponse.isRedirect())
 			{
-				this.lastRenderedPage = generateLastRenderedPage(cycle);
-	
-				MockHttpServletRequest newHttpRequest = new MockHttpServletRequest(this.application,
-						servletSession, this.application.getServletContext());
+				lastRenderedPage = generateLastRenderedPage(cycle);
+
+				MockHttpServletRequest newHttpRequest = new MockHttpServletRequest(application,
+						servletSession, application.getServletContext());
 				newHttpRequest.setRequestToRedirectString(httpResponse.getRedirectLocation());
-				wicketRequest = this.application.newWebRequest(newHttpRequest);
-	
+				wicketRequest = application.newWebRequest(newHttpRequest);
+
 				cycle = createRequestCycle();
 				cycle.request();
 			}
 		}
-		this.lastRenderedPage = generateLastRenderedPage(cycle);
+		lastRenderedPage = generateLastRenderedPage(cycle);
 
 		Session.set(getWicketSession());
 
@@ -453,12 +443,13 @@
 					PageParameters parameters = pageClassRequestTarget.getPageParameters();
 					if (parameters == null || parameters.size() == 0)
 					{
-						newLastRenderedPage = new DefaultPageFactory().newPage(pageClass);
+						newLastRenderedPage = application.getSessionSettings().getPageFactory()
+								.newPage(pageClass);
 					}
 					else
 					{
-						newLastRenderedPage = new DefaultPageFactory().newPage(pageClass,
-								parameters);
+						newLastRenderedPage = application.getSessionSettings().getPageFactory()
+								.newPage(pageClass, parameters);
 					}
 				}
 			}
@@ -466,15 +457,14 @@
 
 		if (newLastRenderedPage == null)
 		{
-			newLastRenderedPage = this.lastRenderedPage;
+			newLastRenderedPage = lastRenderedPage;
 		}
 
 		return newLastRenderedPage;
 	}
 
 	/**
-	 * Create and process the request cycle using the current request and
-	 * response information.
+	 * Create and process the request cycle using the current request and response information.
 	 * 
 	 * @return A new and initialized WebRequestCyle
 	 */
@@ -486,7 +476,7 @@
 				wicketResponse);
 
 		// Construct session
-		this.wicketSession = (WebSession)Session.findOrCreate();
+		wicketSession = (WebSession)Session.findOrCreate();
 
 		// Set request cycle so it won't detach automatically and clear messages
 		// we want to check
@@ -495,9 +485,9 @@
 	}
 
 	/**
-	 * Reset the request and the response back to a starting state and recreate
-	 * the necessary wicket request, response and session objects. The request
-	 * and response objects can be accessed and initialised at this point.
+	 * Reset the request and the response back to a starting state and recreate the necessary wicket
+	 * request, response and session objects. The request and response objects can be accessed and
+	 * initialised at this point.
 	 */
 	public WebRequestCycle setupRequestAndResponse()
 	{
@@ -505,10 +495,10 @@
 		servletResponse.initialize();
 		servletRequest.setParameters(parametersForNextRequest);
 		parametersForNextRequest.clear();
-		this.wicketRequest = this.application.newWebRequest(servletRequest);
-		this.wicketResponse = this.application.newWebResponse(servletResponse);
+		wicketRequest = application.newWebRequest(servletRequest);
+		wicketResponse = application.newWebResponse(servletResponse);
 		WebRequestCycle requestCycle = createRequestCycle();
-		this.application.getSessionStore().bind(wicketRequest, wicketSession);
+		application.getSessionStore().bind(wicketRequest, wicketSession);
 		wicketResponse.setAjax(wicketRequest.isAjax());
 		return requestCycle;
 	}