You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by gs...@apache.org on 2007/12/02 23:15:28 UTC
svn commit: r600389 - in /wicket/trunk/jdk-1.4/wicket/src:
main/java/org/apache/wicket/protocol/http/
main/java/org/apache/wicket/util/tester/ test/java/org/apache/wicket/
test/java/org/apache/wicket/ajax/
test/java/org/apache/wicket/ajax/markup/html/a...
Author: gseitz
Date: Sun Dec 2 14:15:27 2007
New Revision: 600389
URL: http://svn.apache.org/viewvc?rev=600389&view=rev
Log:
WICKET-1199: fix false positive and wrong ajax related unit tests
NOTE: this is a rather fundamental change/fix to ajax related unit testing.
somebody with more wicket tester knowledge should check the review the changes!
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage2_ajax_expected.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage_ajax_expected.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/DomReadyOrderPage_ajax_expected.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/MockComponent3-expected.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPage-1ExpectedResult.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2-1_ExpectedResult.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanelTest.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=600389&r1=600388&r2=600389&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 Sun Dec 2 14:15:27 2007
@@ -502,12 +502,20 @@
* 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
* Initialized at this point.
+ *
+ * @param isAjax
+ * indicates whether the request should be initialized as an ajax request (ajax
+ * header "Wicket-Ajax" is set)
*/
- public WebRequestCycle setupRequestAndResponse()
+ public WebRequestCycle setupRequestAndResponse(boolean isAjax)
{
servletRequest.initialize();
servletResponse.initialize();
servletRequest.setParameters(parametersForNextRequest);
+ if (isAjax)
+ {
+ servletRequest.addHeader("Wicket-Ajax", "Yes");
+ }
parametersForNextRequest.clear();
wicketRequest = application.newWebRequest(servletRequest);
wicketResponse = application.newWebResponse(servletResponse);
@@ -515,6 +523,16 @@
application.getSessionStore().bind(wicketRequest, wicketSession);
wicketResponse.setAjax(wicketRequest.isAjax());
return requestCycle;
+ }
+
+ /**
+ * 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
+ * Initialized at this point.
+ */
+ public WebRequestCycle setupRequestAndResponse()
+ {
+ return setupRequestAndResponse(false);
}
/**
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java Sun Dec 2 14:15:27 2007
@@ -24,6 +24,8 @@
import java.util.Iterator;
import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
@@ -55,6 +57,7 @@
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.protocol.http.HttpSessionStore;
+import org.apache.wicket.protocol.http.MockHttpServletRequest;
import org.apache.wicket.protocol.http.MockHttpServletResponse;
import org.apache.wicket.protocol.http.MockWebApplication;
import org.apache.wicket.protocol.http.WebApplication;
@@ -256,7 +259,7 @@
// setupRequestAndResponse();
WebRequestCycle cycle = createRequestCycle();
CharSequence url = behavior.getCallbackUrl(false);
- setupRequestAndResponse();
+ setupRequestAndResponse(true);
cycle = createRequestCycle();
getServletRequest().setRequestToRedirectString(url.toString());
processRequestCycle(cycle);
@@ -657,7 +660,7 @@
AjaxLink link = (AjaxLink)linkComponent;
- setupRequestAndResponse();
+ setupRequestAndResponse(true);
RequestCycle requestCycle = createRequestCycle();
AjaxRequestTarget target = new AjaxRequestTarget(link.getPage());
requestCycle.setRequestTarget(target);
@@ -675,7 +678,7 @@
{
AjaxFallbackLink link = (AjaxFallbackLink)linkComponent;
- setupRequestAndResponse();
+ setupRequestAndResponse(true);
RequestCycle requestCycle = createRequestCycle();
AjaxRequestTarget target = new AjaxRequestTarget(link.getPage());
requestCycle.setRequestTarget(target);
@@ -716,7 +719,7 @@
String failMessage = "No form submit behavior found on the submit link. Strange!!";
notNull(failMessage, ajaxFormSubmitBehavior);
- setupRequestAndResponse();
+ setupRequestAndResponse(true);
RequestCycle requestCycle = createRequestCycle();
submitAjaxFormSubmitBehavior(ajaxFormSubmitBehavior);
@@ -1108,11 +1111,21 @@
WebRequestCycle requestCycle;
if (RequestCycle.get() == null)
{
- requestCycle = setupRequestAndResponse();
+ requestCycle = setupRequestAndResponse(true);
}
else
{
requestCycle = (WebRequestCycle)RequestCycle.get();
+ }
+ // when the requestcycle is not created via setupRequestAndResponse(true), it can happen
+ // that the request is not an ajax request -> we have to set the header manually
+ if (!requestCycle.getWebRequest().isAjax())
+ {
+ HttpServletRequest req = requestCycle.getWebRequest().getHttpServletRequest();
+ if (req instanceof MockHttpServletRequest)
+ {
+ ((MockHttpServletRequest)req).addHeader("Wicket-Ajax", "Yes");
+ }
}
// If the event is an FormSubmitBehavior then also "submit" the form
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/TestDetachPageAjaxResult.html Sun Dec 2 14:15:27 2007
@@ -5,4 +5,4 @@
wicketAjaxDebugEnable=true;
/*-->]^]^>*/</script>
-</head>]]></header-contribution><component id="comp1" ><![CDATA[<span wicket:id="comp" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:comp::IBehaviorListener:0:',null,null, function() {return Wicket.$$(this)}.bind(this));" id="comp1">body</span>]]></component></ajax-response>
\ No newline at end of file
+</head>]]></header-contribution><component id="comp1" ><![CDATA[<span onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:comp::IBehaviorListener:0:-1',null,null, function() {return Wicket.$$(this)}.bind(this));" id="comp1">body</span>]]></component></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage2_ajax_expected.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage2_ajax_expected.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage2_ajax_expected.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage2_ajax_expected.html Sun Dec 2 14:15:27 2007
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?><ajax-response><evaluate><![CDATA[prepend();]]></evaluate><header-contribution><![CDATA[<head xmlns:wicket="http://wicket.apache.org">
<link href="../test"/>
<script type="text/javascript" src="javascripturl"></script>
-</head>]]></header-contribution><component id="test17" ><![CDATA[<span wicket:id="test1" id="test17"><wicket:panel>
+</head>]]></header-contribution><component id="test17" ><![CDATA[<span id="test17">
test
-</wicket:panel></span>]]></component><component id="test28" ><![CDATA[<span wicket:id="test2" id="test28"><wicket:panel>
+</span>]]></component><component id="test28" ><![CDATA[<span id="test28">
test
-</wicket:panel></span>]]></component><component id="test39" ><![CDATA[<span wicket:id="test3" id="test39"><wicket:panel>
+</span>]]></component><component id="test39" ><![CDATA[<span id="test39">
test
-</wicket:panel></span>]]></component><header-contribution><![CDATA[<head xmlns:wicket="http://wicket.apache.org">
+</span>]]></component><header-contribution><![CDATA[<head xmlns:wicket="http://wicket.apache.org">
<link href="../test2"/>
<script type="text/javascript" src="javascripturlB"></script>
-</head>]]></header-contribution><component id="btest110" ><![CDATA[<span wicket:id="btest1" id="btest110"><wicket:panel>
+</head>]]></header-contribution><component id="btest110" ><![CDATA[<span id="btest110">
test
-</wicket:panel></span>]]></component><component id="btest211" ><![CDATA[<span wicket:id="btest2" id="btest211"><wicket:panel>
+</span>]]></component><component id="btest211" ><![CDATA[<span id="btest211">
test
-</wicket:panel></span>]]></component><component id="btest312" ><![CDATA[<span wicket:id="btest3" id="btest312"><wicket:panel>
+</span>]]></component><component id="btest312" ><![CDATA[<span id="btest312">
test
-</wicket:panel></span>]]></component><evaluate><![CDATA[domReady();]]></evaluate><evaluate><![CDATA[domReadyB();]]></evaluate><evaluate><![CDATA[append();]]></evaluate><evaluate><![CDATA[onLoad();]]></evaluate><evaluate><![CDATA[onLoadB();]]></evaluate></ajax-response>
\ No newline at end of file
+</span>]]></component><evaluate><![CDATA[domReady();]]></evaluate><evaluate><![CDATA[domReadyB();]]></evaluate><evaluate><![CDATA[append();]]></evaluate><evaluate><![CDATA[onLoad();]]></evaluate><evaluate><![CDATA[onLoadB();]]></evaluate></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage_ajax_expected.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage_ajax_expected.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage_ajax_expected.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/AjaxHeaderContributionPage_ajax_expected.html Sun Dec 2 14:15:27 2007
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><ajax-response><evaluate><![CDATA[prepend();]]></evaluate><header-contribution><![CDATA[<head xmlns:wicket="http://wicket.apache.org">
<link href="../test"/>
<script type="text/javascript" src="javascripturl"></script>
-</head>]]></header-contribution><component id="test14" ><![CDATA[<span wicket:id="test1" id="test14"><wicket:panel>
+</head>]]></header-contribution><component id="test14" ><![CDATA[<span id="test14">
test
-</wicket:panel></span>]]></component><component id="test25" ><![CDATA[<span wicket:id="test2" id="test25"><wicket:panel>
+</span>]]></component><component id="test25" ><![CDATA[<span id="test25">
test
-</wicket:panel></span>]]></component><component id="test36" ><![CDATA[<span wicket:id="test3" id="test36"><wicket:panel>
+</span>]]></component><component id="test36" ><![CDATA[<span id="test36">
test
-</wicket:panel></span>]]></component><evaluate><![CDATA[domReady();]]></evaluate><evaluate><![CDATA[append();]]></evaluate><evaluate><![CDATA[onLoad();]]></evaluate></ajax-response>
\ No newline at end of file
+</span>]]></component><evaluate><![CDATA[domReady();]]></evaluate><evaluate><![CDATA[append();]]></evaluate><evaluate><![CDATA[onLoad();]]></evaluate></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/DomReadyOrderPage_ajax_expected.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/DomReadyOrderPage_ajax_expected.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/DomReadyOrderPage_ajax_expected.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/DomReadyOrderPage_ajax_expected.html Sun Dec 2 14:15:27 2007
@@ -5,4 +5,4 @@
wicketAjaxDebugEnable=true;
/*-->]^]^>*/</script>
-</head>]]></header-contribution><component id="test1" ><![CDATA[<a href="?wicket:interface=:0:test::ILinkListener::" wicket:id="test" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:test::IBehaviorListener:0:',null,null, function() {return Wicket.$$(this)}.bind(this));return !wcall;" id="test1">Test</a>]]></component><evaluate><![CDATA[test1();]]></evaluate><evaluate><![CDATA[test2();]]></evaluate></ajax-response>
\ No newline at end of file
+</head>]]></header-contribution><component id="test1" ><![CDATA[<a href="?wicket:interface=:0:test::ILinkListener::" onclick="var wcall=wicketAjaxGet('?wicket:interface=:0:test::IBehaviorListener:0:-1',null,null, function() {return Wicket.$$(this)}.bind(this));return !wcall;" id="test1">Test</a>]]></component><evaluate><![CDATA[test1();]]></evaluate><evaluate><![CDATA[test2();]]></evaluate></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/MockComponent3-expected.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/MockComponent3-expected.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/MockComponent3-expected.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/MockComponent3-expected.html Sun Dec 2 14:15:27 2007
@@ -1,3 +1,3 @@
<![CDATA[<head xmlns:wicket="http://wicket.apache.org">
-<link href="resources/org.apache.wicket.ajax.MockComponent3/mockStyleSheet3.css" rel="stylesheet" type="text/css" wicket:id="stylesheet"/>
+<link href="resources/org.apache.wicket.ajax.MockComponent3/mockStyleSheet3.css" rel="stylesheet" type="text/css"/>
</head>]]>
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPage-1ExpectedResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPage-1ExpectedResult.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPage-1ExpectedResult.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxLinkWithBorderPage-1ExpectedResult.html Sun Dec 2 14:15:27 2007
@@ -1 +1 @@
-<?xml version="1.0" encoding="UTF-8"?><ajax-response><component id="ajaxLabel1" ><![CDATA[<span wicket:id="ajaxLabel" id="ajaxLabel1">Updated!</span>]]></component></ajax-response>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?><ajax-response><component id="ajaxLabel1" ><![CDATA[<span id="ajaxLabel1">Updated!</span>]]></component></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2-1_ExpectedResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2-1_ExpectedResult.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2-1_ExpectedResult.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/ajaxLink/AjaxPage2-1_ExpectedResult.html Sun Dec 2 14:15:27 2007
@@ -1 +1 @@
-<?xml version="1.0" encoding="UTF-8"?><ajax-response><component id="ajaxLabel" ><![CDATA[<span wicket:id="ajaxLabel" id="ajaxLabel1">BBBBBBB</span>]]></component></ajax-response>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?><ajax-response><component id="ajaxLabel" ><![CDATA[<span id="ajaxLabel1">BBBBBBB</span>]]></component></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPageExpectedResult-1.html Sun Dec 2 14:15:27 2007
@@ -5,4 +5,4 @@
wicketAjaxDebugEnable=true;
/*-->]^]^>*/</script>
-</head>]]></header-contribution><component id="linja11" ><![CDATA[<span wicket:id="linja1" id="linja11">1</span>]]></component><evaluate><![CDATA[setTimeout("var wcall=wicketAjaxGet('?wicket:interface=:0:testPanel:baseSpan:linja1::IActivePageBehaviorListener:0:&wicket:ignoreIfNotActive=true',null,null, function() {var c = Wicket.$('linja11'); return typeof(c) != 'undefined' && c != null}.bind(this));", 2000);]]></evaluate></ajax-response>
\ No newline at end of file
+</head>]]></header-contribution><component id="linja11" ><![CDATA[<span id="linja11">1</span>]]></component><evaluate><![CDATA[setTimeout("var wcall=wicketAjaxGet('?wicket:interface=:0:testPanel:baseSpan:linja1::IActivePageBehaviorListener:0:-1&wicket:ignoreIfNotActive=true',null,null, function() {var c = Wicket.$('linja11'); return typeof(c) != 'undefined' && c != null}.bind(this));", 2000);]]></evaluate></ajax-response>
\ No newline at end of file
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanelTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanelTest.java?rev=600389&r1=600388&r2=600389&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanelTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/ajax/markup/html/componentMap/SimpleTestPanelTest.java Sun Dec 2 14:15:27 2007
@@ -44,7 +44,7 @@
*/
public void testRenderHomePage_2() throws Exception
{
- tester.setupRequestAndResponse();
+ tester.setupRequestAndResponse(true);
executeTest(SimpleTestPage.class, "SimpleTestPageExpectedResult.html");
WebRequestCycle cycle = tester.createRequestCycle();
@@ -54,6 +54,6 @@
// Validate the document
String document = tester.getServletResponse().getDocument();
DiffUtil.validatePage(document, SimpleTestPage.class,
- "SimpleTestPageExpectedResult-1.html", true);
+ "SimpleTestPageExpectedResult-1.html", true);
}
}