You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by da...@apache.org on 2015/08/14 10:16:50 UTC

wicket git commit: Added test case for WICKET-5960

Repository: wicket
Updated Branches:
  refs/heads/master 8fbe6c7d5 -> 02d586477


Added test case for WICKET-5960


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/02d58647
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/02d58647
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/02d58647

Branch: refs/heads/master
Commit: 02d586477a0e9dabf82ab839bd53499c1b78d616
Parents: 8fbe6c7
Author: Martijn Dashorst <ma...@gmail.com>
Authored: Fri Aug 14 10:16:30 2015 +0200
Committer: Martijn Dashorst <ma...@gmail.com>
Committed: Fri Aug 14 10:16:30 2015 +0200

----------------------------------------------------------------------
 .../wicket/request/cycle/RerenderPageTest.java  | 52 +++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/02d58647/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPageTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPageTest.java b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPageTest.java
index 6546c6e..21af8c4 100644
--- a/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPageTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/request/cycle/RerenderPageTest.java
@@ -16,11 +16,13 @@
  */
 package org.apache.wicket.request.cycle;
 
+import static org.hamcrest.CoreMatchers.containsString;
+
 import org.apache.wicket.core.request.mapper.MountedMapper;
+import org.apache.wicket.protocol.http.mock.MockHttpServletResponse;
 import org.apache.wicket.request.cycle.RerenderPage.Supplier;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.wicket.util.tester.WicketTestCase;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -69,4 +71,52 @@ public class RerenderPageTest extends WicketTestCase
 		// due to the mentioned issue, no headers are rendered at all.
 		tester.assertContains("<!-- I should be present 2 -->");
 	}
+
+	/**
+	 * Another test case for WICKET-5960.
+	 * 
+	 * When an AJAX update was performed, the next normal request would still find the page left
+	 * with the PartialHtmlHeaderContainer causing an empty {@code 
+	 * <head>} section to be rendered. This test case walks Wicket through this scenario.
+	 */
+	@Test
+	public void nonAjaxRequestAfterAjaxUpdatedComponentShouldHaveHtmlHeadSection()
+	{
+		// perform a normal render of the page
+		tester.startPage(RerenderAjaxPage.class);
+		tester.assertRenderedPage(RerenderAjaxPage.class);
+
+		MockHttpServletResponse firstResponseBeforeAjaxUpdate = tester.getLastResponse();
+
+		// call an ajax event that updates a component
+		tester.executeAjaxEvent("form:username", "blur");
+		tester.assertComponentOnAjaxResponse("feedback");
+
+		// perform a normal render of the page (in this case submitting the form which triggers a
+		// feedback error
+		tester.submitForm("form");
+
+		// record the response for later reference
+		MockHttpServletResponse normalResponseAfterAjaxUpdate = tester.getLastResponse();
+
+		// submit the form again to ascertain if the HTML head section was restored upon the second
+		// render
+		tester.submitForm("form");
+
+		// record the response for later reference
+		MockHttpServletResponse secondNormalResponse = tester.getLastResponse();
+
+		// assert that the first response indeed got the correct <head> section
+		assertThat(firstResponseBeforeAjaxUpdate.getDocument(),
+			containsString(RerenderAjaxPage.HEAD_TEXT));
+
+		// assert that the second normal response after the AJAX update indeed got the correct
+		// <head> section (this worked while the bug was still present)
+		assertThat(secondNormalResponse.getDocument(), containsString(RerenderAjaxPage.HEAD_TEXT));
+
+		// assert that the first normal response after the AJAX update indeed got the correct
+		// <head> section (this failed while the bug was still present)
+		assertThat(normalResponseAfterAjaxUpdate.getDocument(),
+			containsString(RerenderAjaxPage.HEAD_TEXT));
+	}
 }