You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martijn Dashorst <ma...@gmail.com> on 2008/09/16 23:59:19 UTC

WICKET-1582 blocked by WICKET-254

I tried to 'fix' 1582, but it appears to be blocked by WICKET-254.

Short summary:

wicket 1582: WicketTester#clickLink() doesn't do the same as
WicketTester#executeAjaxEvent()

This is easily fixed by performing setupRequestAndResponse() at the
start of executeAjaxEvent, which makes this method act in line with
all other WicketTester methods.

this kills WICKET-254 functionality and fails
WicketTesterTest#testToggleAjaxFormButton()

>From an API consistency, I'd suggest fixing 1582 and see how we can
accomodate 254, if at all. However, 1582 is easily worked around by
letting users call setupRequestAndResponse() themselves...

Any ideas? (Timo: you filed 254, perhaps you have some insights?)

Martijn
-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

Re: WICKET-1582 blocked by WICKET-254

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 16 Sep 2008, Martijn Dashorst wrote:
> I tried to 'fix' 1582, but it appears to be blocked by WICKET-254.
> 
> Short summary:
> 
> wicket 1582: WicketTester#clickLink() doesn't do the same as
> WicketTester#executeAjaxEvent()
> 
> This is easily fixed by performing setupRequestAndResponse() at the
> start of executeAjaxEvent, which makes this method act in line with
> all other WicketTester methods.
> 
> this kills WICKET-254 functionality and fails
> WicketTesterTest#testToggleAjaxFormButton()
> 
> From an API consistency, I'd suggest fixing 1582 and see how we can
> accomodate 254, if at all. However, 1582 is easily worked around by
> letting users call setupRequestAndResponse() themselves...
> 
> Any ideas? (Timo: you filed 254, perhaps you have some insights?)

Hmm, it was so long ago :)

But I find it a bit odd that RequestCycle is set at all in 
the beginning, after doing just startPage. Why is there a 
(non-ajax) RequestCycle present in the first place?

When testing ajax behaviours, you often have to do things 
(such as setting request parameters) to the request of the 
current RequestCycle before executing the ajax event, so I'm
afraid that a lot of those tests would break if the existing 
RequestCycle would not be conserved in executeAjaxEvent :(

It would be nicer if executeAjaxEvent could force the existing
response, if any, to be ajax. The problem there is that there 
the isAjax() check should be moved to some object whose state 
you can toggle -- now it's just done on the response String 
and messing up with it gets messy (see inlined patch).

So: If 1582 is fixed by resetting the existing RequestCycle, 
at least it should be overridable somehow for those that want 
to keep their old ajax tests working, e.g. by making a 
protected WebRequestCycle resolveRequestCycle() or something 
like that in BaseWicketTester.

Best wishes,
Timo



Index: jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
===================================================================
--- jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java	(revision 696557)
+++ jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java	Thu Sep 18 08:18:30 EEST 2008
@@ -23,6 +23,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.io.IOException;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -85,8 +86,9 @@
 {
 	/** log. */
 	private static final Logger log = LoggerFactory.getLogger(BaseWicketTester.class);
+    private static final String AJAX_RESPONSE_START = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ajax-response>";
 
-	/**
+    /**
 	 * @author jcompagner
 	 */
 	private static final class TestPageSource implements ITestPageSource
@@ -1015,8 +1017,8 @@
 		// Test that the previous response was actually a AJAX response
 		failMessage = "The Previous response was not an AJAX response. "
 			+ "You need to execute an AJAX event, using clickLink, before using this assert";
-		boolean isAjaxResponse = ajaxResponse.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ajax-response>");
+        boolean isAjaxResponse = isAjaxResponse(ajaxResponse);
-		result = isTrue(failMessage, isAjaxResponse);
+        result = isTrue(failMessage, isAjaxResponse);
 		if (result.wasFailed())
 		{
 			return result;
@@ -1040,7 +1042,12 @@
 		return isTrue(failMessage, isComponentInAjaxResponse);
 	}
 
+    private boolean isAjaxResponse(String response)
+    {
+        return response.startsWith(AJAX_RESPONSE_START);
+    }
+
-	/**
+    /**
 	 * Simulates the firing of an Ajax event.
 	 * 
 	 * @see #executeAjaxEvent(Component, String)
@@ -1152,7 +1159,22 @@
 			}
 		}
 
+        if (!isAjaxResponse(getServletResponse().getDocument()))
+        {
+            String originalResponse = getServletResponse().getDocument();
+            getServletResponse().resetBuffer();
+            getServletResponse().initialize();
+            try
+            {
+                getServletResponse().getWriter().append(AJAX_RESPONSE_START);
+                getServletResponse().getWriter().append(originalResponse);
+            } catch (IOException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+
-		// If the event is an FormSubmitBehavior then also "submit" the form
+        // If the event is an FormSubmitBehavior then also "submit" the form
 		if (ajaxEventBehavior instanceof AjaxFormSubmitBehavior)
 		{
 			AjaxFormSubmitBehavior ajaxFormSubmitBehavior = (AjaxFormSubmitBehavior)ajaxEventBehavior;