You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/06/27 13:15:03 UTC
svn commit: r958364 - in /click/trunk/click/mock/src/org/apache/click:
MockContainer.java MockContext.java
Author: sabob
Date: Sun Jun 27 11:15:03 2010
New Revision: 958364
URL: http://svn.apache.org/viewvc?rev=958364&view=rev
Log:
added reset method to clear all threadlocal variables
Modified:
click/trunk/click/mock/src/org/apache/click/MockContainer.java
click/trunk/click/mock/src/org/apache/click/MockContext.java
Modified: click/trunk/click/mock/src/org/apache/click/MockContainer.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/MockContainer.java?rev=958364&r1=958363&r2=958364&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/MockContainer.java (original)
+++ click/trunk/click/mock/src/org/apache/click/MockContainer.java Sun Jun 27 11:15:03 2010
@@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
import org.apache.click.servlet.MockSession;
import org.apache.commons.lang.StringUtils;
@@ -466,19 +467,22 @@ public class MockContainer {
if (pageClass == null) {
throw new IllegalArgumentException("pageClass cannot be null");
}
+
try {
- // Cleanup any Context instances still referenced on stack.
- clearContextStack();
- getResponse().reset();
+ // Reset internal state before test
+ reset();
+
String servletPath = getClickServlet().getConfigService().getPagePath(pageClass);
if (servletPath == null) {
throw new IllegalArgumentException("The class " + pageClass.getName()
+ " was not mapped by Click and does not have a"
+ " corresponding template file.");
}
+
getRequest().setServletPath(servletPath);
getClickServlet().service(request, getResponse());
return getPage();
+
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
@@ -649,16 +653,21 @@ public class MockContainer {
}
}
- // -------------------------------------------------------- Package private methods
+ // Package private methods ------------------------------------------------
/**
- * Removes any {@link org.apache.click.Context} instances from the ThradLocal
- * ContextStack.
+ * Reset container internal state.
*
* @see #start()
*/
- void clearContextStack() {
+ void reset() {
Context.getContextStack().clear();
+ HttpServletResponse response = getResponse();
+ if (response != null) {
+ response.reset();
+ }
+ ActionEventDispatcher.getDispatcherStack().clear();
+ CallbackDispatcher.getDispatcherStack().clear();
}
/**
Modified: click/trunk/click/mock/src/org/apache/click/MockContext.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/src/org/apache/click/MockContext.java?rev=958364&r1=958363&r2=958364&view=diff
==============================================================================
--- click/trunk/click/mock/src/org/apache/click/MockContext.java (original)
+++ click/trunk/click/mock/src/org/apache/click/MockContext.java Sun Jun 27 11:15:03 2010
@@ -239,8 +239,8 @@ public class MockContext extends Context
* @param request the mock request
* @param response the mock response
* @param clickServlet the mock clickServlet
- * @param actionEventDispatcher action and behavior dispatcher
- * @param callbackDispatcher the control callback dispatcher
+ * @param actionEventDispatcher action and behavior dispatcher
+ * @param callbackDispatcher the control callback dispatcher
* @return new Context instance
*/
public static MockContext initContext(MockServletConfig servletConfig,