You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/04/26 11:02:55 UTC

[01/11] git commit: WICKET-5147 cookie handling wickettester bugfix and tests

Updated Branches:
  refs/heads/master 43237280a -> 8df9d9920


WICKET-5147 cookie handling wickettester bugfix and tests


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

Branch: refs/heads/master
Commit: 2dc6b4fe0f9ca3610972fa62af6968953898eab1
Parents: 2350b7a
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Tue Apr 23 00:15:52 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Tue Apr 23 00:15:52 2013 +0200

----------------------------------------------------------------------
 .../wicket/util/tester/BaseWicketTester.java       |   15 +-
 .../wicket/util/tester/WicketTesterTest.java       |  250 ++++++++++++++-
 .../cookies/CollectAllRequestCookiesPage.java      |   43 +++
 .../apache/wicket/util/tester/cookies/EndPage.java |   28 ++
 .../wicket/util/tester/cookies/SetCookiePage.java  |   54 +++
 5 files changed, 378 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/2dc6b4fe/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index af80fd0..5c164e2 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -369,8 +369,6 @@ public class BaseWicketTester
 			request.setServerPort(lastRequest.getServerPort());
 		}
 
-		transferRequestCookies();
-
 		response = new MockHttpServletResponse(request);
 
 		// Preserve response cookies in redirects
@@ -478,19 +476,16 @@ public class BaseWicketTester
 					}
 					else
 					{
-						boolean newlyCreated = true;
-						for (Cookie oldCookie : lastRequestCookies)
+						Iterator<Cookie> cookieIterator = lastRequestCookies.iterator();
+						while (cookieIterator.hasNext())
 						{
+							Cookie oldCookie = cookieIterator.next();
 							if (Cookies.isEqual(cookie, oldCookie))
 							{
-								newlyCreated = false;
-								break;
+								cookieIterator.remove();
 							}
 						}
-						if (newlyCreated)
-						{
-							lastRequestCookies.add(cookie);
-						}
+						lastRequestCookies.add(cookie);
 					}
 				}
 			}

http://git-wip-us.apache.org/repos/asf/wicket/blob/2dc6b4fe/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
index cedd26d..8ffcdb0 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
@@ -17,8 +17,10 @@
 package org.apache.wicket.util.tester;
 
 import java.util.Collection;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
@@ -51,6 +53,7 @@ import org.apache.wicket.markup.html.link.ResourceLink;
 import org.apache.wicket.markup.html.pages.AccessDeniedPage;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.protocol.http.mock.Cookies;
 import org.apache.wicket.request.IRequestHandler;
 import org.apache.wicket.request.IRequestParameters;
 import org.apache.wicket.request.Url;
@@ -73,6 +76,9 @@ import org.apache.wicket.util.tester.apps_1.SuccessPage;
 import org.apache.wicket.util.tester.apps_1.ViewBook;
 import org.apache.wicket.util.tester.apps_6.LinkPage;
 import org.apache.wicket.util.tester.apps_6.ResultPage;
+import org.apache.wicket.util.tester.cookies.CollectAllRequestCookiesPage;
+import org.apache.wicket.util.tester.cookies.EndPage;
+import org.apache.wicket.util.tester.cookies.SetCookiePage;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -1053,7 +1059,7 @@ public class WicketTesterTest extends WicketTestCase
 		assertEquals(cookieAge, cookie2.getMaxAge());
 
 		// assert that the cookie will be preserved for the next request
-		assertEquals(cookieValue, tester.getRequest().getCookie(cookieName).getValue());
+		assertEquals(cookieValue, tester.getLastRequest().getCookie(cookieName).getValue());
 	}
 
 	/**
@@ -1341,7 +1347,7 @@ public class WicketTesterTest extends WicketTestCase
 		// The cookie should be in each following request unless the server code
 		// schedules it for removal it with cookie.setMaxAge(0)
 		Assert.assertEquals("The cookie should be in each following request",
-				1, tester.getRequest().getCookies().length);
+				1, tester.getLastRequest().getCookies().length);
 	}
 
 	/**
@@ -1368,4 +1374,244 @@ public class WicketTesterTest extends WicketTestCase
 
 		Assert.assertEquals(cookieValue, responseCookie.getValue());
 	}
+	
+	/**
+	 * There are some expectations about wicket tester cookie handling which should match as 
+	 * best as it can be with a real client server request response cycle:
+	 * - all valid cookies set before a request is made should appear in the wicket request
+	 * - all cookies set in the response should appear in the tester response after the request is made
+	 * - all cookies set in the response should appear even after a redirect response is made until the final response is written to the client
+	 * - all valid cookies from the last response should be added or should overwrite the next request cookies
+	 *
+	 * https://issues.apache.org/jira/browse/WICKET-5147
+	 */
+	@Test
+	public void wicketTesterCookieHandlingWithoutRedirect() {
+		// no cookies set
+		CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage();
+		Assert.assertTrue("no cookie in first request",collectingPage.getCookies().isEmpty());
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+		
+		// set cookie on request
+		Cookie cookieA = newCookie("a","1",1);
+		tester.getRequest().addCookie(cookieA);
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage, cookieA);
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+
+		// cookies from last request should appear on following requests
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage, cookieA);
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+
+		// cookie will be overwritten if response will do so
+		Cookie newCookieA = newCookie("a","newValue",1);
+		setCookieInResponse(newCookieA);
+		lastResponseShouldHaveTheseCookies(newCookieA);
+		
+		// cookies from last response then should appear on following requests
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage, newCookieA);
+		lastResponseDoesNotHaveAnyCookies();
+		
+		// cookies from requests will be deleted if the response will do so
+		Cookie removeCookieA = newCookie("a","removeMe",0);
+		setCookieInResponse(removeCookieA);
+		lastResponseShouldHaveTheseCookies(removeCookieA);
+		responseDoesNotHaveAnyCookies();
+		
+		// no cookies in next request while last cookie was deleted
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage);
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+	}
+
+	/**
+	 * @see WicketTesterTest#wicketTesterCookieHandlingWithoutRedirect()
+	 *  
+	 * https://issues.apache.org/jira/browse/WICKET-5147
+	 */
+	@Test
+	public void wicketTesterCookieHandlingWithRedirect() {
+		// set cookie in response then redirect to other page
+		Cookie newCookieA = newCookie("a","newValue",1);
+		setCookieInResponseAndRedirect(newCookieA);
+		lastResponseShouldHaveTheseCookies(newCookieA);
+
+		// cookie in response after redirect should appear in next request
+		CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage,newCookieA);
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+		
+		// set cookie on request and overwrite in response then redirect to other page
+		Cookie cookieA = newCookie("a","1",1);
+		newCookieA = newCookie("a","newValue",1);
+		tester.getRequest().addCookie(cookieA);
+		setCookieInResponseAndRedirect(newCookieA);
+		lastResponseShouldHaveTheseCookies(newCookieA);
+		
+		// cookie in response after redirect should appear in next request
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage,newCookieA);
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+		
+		// set cookie on request and remove it in response then redirect to other page
+		cookieA = newCookie("a","1",1);
+		newCookieA = newCookie("a","newValue",0);
+		tester.getRequest().addCookie(cookieA);
+		setCookieInResponseAndRedirect(newCookieA);
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+		
+		// no cookies left
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage);
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+	}
+	
+	/**
+	 * creates a new cookie with maxAge set
+	 * @param name name
+	 * @param value value
+	 * @param maxAge maxAge
+	 * @return a cookie
+	 */
+	private static Cookie newCookie(String name,String value, int maxAge) {
+		Cookie cookie = new Cookie(name,value);
+		cookie.setMaxAge(maxAge);
+		return cookie;
+	}
+	
+	/**
+	 * start a page which collects all cookies from request 
+	 * @return the page
+	 */
+	private CollectAllRequestCookiesPage collectAllRequestCookiesOnThisPage()
+	{
+		return tester.startPage(CollectAllRequestCookiesPage.class);
+	}
+
+	/**
+	 * start a page which set a cookie in response
+	 * @param cookie cookie
+	 */
+	private void setCookieInResponse(Cookie cookie)
+	{
+		tester.startPage(new SetCookiePage(cookie));
+	}
+
+	/**
+	 * start a page which set a cookie in response and then redirect to different page
+	 * @param cookie cookie
+	 */
+	private void setCookieInResponseAndRedirect(Cookie cookie)
+	{
+		tester.startPage(new SetCookiePage(cookie,EndPage.class));
+	}
+
+	/**
+	 * check cookies collected by page
+	 * @param page page
+	 * @param cookies cookies
+	 */
+	private void requestOnPageShouldHaveTheseCookies(CollectAllRequestCookiesPage page, Cookie...cookies) {
+		listShouldMatchAll(page.getCookies(), cookies);
+	}
+
+	/**
+	 * check if every cookie is found in the list and no cookie is left 
+	 * @param cookieList cookie list
+	 * @param cookies cookies to check
+	 */
+	private void listShouldMatchAll(List<Cookie> cookieList, Cookie... cookies)
+	{
+		Map<String, Cookie> cookieMap = cookiesFromList(cookieList);
+		for (Cookie cookie : cookies) {
+			Cookie removed = cookieMap.remove(cookie.getName());
+			Assert.assertNotNull("Cookie "+cookie.getName(),removed);
+			Assert.assertTrue("Cookie "+cookie.getName()+" matches",Cookies.isEqual(cookie, removed));
+		}
+		Assert.assertTrue("no cookies left "+asString(cookieMap),cookieMap.isEmpty());
+	}
+	
+	/**
+	 * make cookie map more readable
+	 * @param cookieMap cookie map
+	 * @return string
+	 */
+	private static String asString(Map<String, Cookie> cookieMap)
+	{
+		StringBuilder sb=new StringBuilder();
+		sb.append("{");
+		for (Map.Entry<String, Cookie> e : cookieMap.entrySet()) {
+			sb.append(e.getKey()).append("=").append(asString(e.getValue()));
+			sb.append(",");
+		}
+		sb.append("}");
+		return sb.toString();
+	}
+
+	/**
+	 * make cookie more readable
+	 * @param c cookie
+	 * @return string
+	 */
+	private static String asString(Cookie c)
+	{
+		StringBuilder sb=new StringBuilder();
+		sb.append("[");
+		sb.append("name=").append(c.getName()).append(",");
+		sb.append("value=").append(c.getValue()).append(",");
+		sb.append("maxAge=").append(c.getMaxAge());
+		sb.append("]");
+		return sb.toString();
+	}
+
+	/**
+	 * check last response cookies
+	 * @param cookies cookies
+	 */
+	private void lastResponseShouldHaveTheseCookies(Cookie...cookies) {
+		listShouldMatchAll(tester.getLastResponse().getCookies(), cookies);
+	}
+	
+	/**
+	 * response should not have any cookies
+	 */
+	private void lastResponseDoesNotHaveAnyCookies()
+	{
+		listShouldMatchAll(tester.getLastResponse().getCookies());
+	}
+	
+	/**
+	 * response should not have any cookies
+	 */
+	private void responseDoesNotHaveAnyCookies()
+	{
+		listShouldMatchAll(tester.getResponse().getCookies());
+	}
+	
+	/**
+	 * create a cookie map based on cookie name
+	 * @param cookies cookie list
+	 * @return as map
+	 * @throws RuntimeException if more than one cookie with the same name
+	 */
+	private static Map<String,Cookie> cookiesFromList(List<Cookie> cookies) {
+		Map<String, Cookie> ret = new LinkedHashMap<String, Cookie>();
+		for (Cookie cookie : cookies) {
+			Cookie oldValue = ret.put(cookie.getName(), cookie);
+			if (oldValue!=null) {
+				throw new RuntimeException("Cookie with name "+cookie.getName()+"("+asString(oldValue)+") allready in map "+asString(ret));
+			}
+		}
+		return ret;
+	}
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/2dc6b4fe/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/CollectAllRequestCookiesPage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/CollectAllRequestCookiesPage.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/CollectAllRequestCookiesPage.java
new file mode 100644
index 0000000..9e0e6f5
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/CollectAllRequestCookiesPage.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.tester.cookies;
+
+import java.util.List;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.wicket.request.http.WebRequest;
+import org.apache.wicket.util.tester.DummyHomePage;
+
+/**
+ * a page collection all request cookies
+ * @author mosmann
+ */
+public class CollectAllRequestCookiesPage extends DummyHomePage
+{
+	private List<Cookie> cookies;
+
+	public CollectAllRequestCookiesPage()
+	{
+		cookies = ((WebRequest) getRequest()).getCookies();
+	}
+	
+	public List<Cookie> getCookies()
+	{
+		return cookies;
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/2dc6b4fe/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/EndPage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/EndPage.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/EndPage.java
new file mode 100644
index 0000000..4bed69f
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/EndPage.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.tester.cookies;
+
+import org.apache.wicket.util.tester.DummyHomePage;
+
+/**
+ * simple page as request cycle end point
+ * @author mosmann
+ */
+public class EndPage extends DummyHomePage
+{
+
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/2dc6b4fe/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
new file mode 100644
index 0000000..0887d02
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.tester.cookies;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.request.http.WebResponse;
+import org.apache.wicket.util.tester.DummyHomePage;
+
+/**
+ * a page which sets cookies and makes an optional redirect
+ * @author mosmann
+ */
+public class SetCookiePage extends DummyHomePage
+{
+	private final Cookie cookie;
+	private final Class<? extends Page> redirectToPageClass;
+
+	public SetCookiePage(Cookie cookie,Class<? extends Page> redirectToPageClass)
+	{
+		this.cookie = cookie;
+		this.redirectToPageClass = redirectToPageClass;
+	}
+	
+	public SetCookiePage(Cookie cookie)
+	{
+		this(cookie,null);
+	}
+	
+	protected void onInitialize() {
+		super.onInitialize();
+		WebResponse response = (WebResponse) getResponse();
+		response.addCookie(cookie);
+		
+		if (redirectToPageClass!=null) {
+			setResponsePage(redirectToPageClass);
+		}
+	};
+}


[05/11] git commit: WICKET-5147 comment fixed

Posted by mg...@apache.org.
WICKET-5147 comment fixed


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

Branch: refs/heads/master
Commit: 79bba93b8b2f57bd9ee327288d2c4176d802ab81
Parents: 42b9d50
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Fri Apr 26 01:32:02 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Fri Apr 26 01:32:02 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/util/tester/WicketTester.java    |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/79bba93b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
index 3786693..8f17548 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
@@ -150,7 +150,7 @@ import org.slf4j.LoggerFactory;
  * - all valid cookies set before a request is made (tester.getRequest().addCookie()) should
  *   appear in the page request
  * - all cookies set in the response should appear in the last response (tester.getLastResponse()) 
- *   after the request is made 
+ *   after the request is made (expired cookies and others)
  * - all cookies set in the response should appear even after a redirect response is made
  *   until the final response (tester.getLastResponse()) is written to the client (wicket tester) 
  * - all valid cookies (maxAge!=0) from the last response should be added to


[07/11] git commit: WICKET-5147 eclipse prefs changed

Posted by mg...@apache.org.
WICKET-5147 eclipse prefs changed


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

Branch: refs/heads/master
Commit: d9c2d4085b14f7e5735ba800f4fc9bb0a0a9a96e
Parents: 170a174
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Fri Apr 26 01:40:08 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Fri Apr 26 01:40:08 2013 +0200

----------------------------------------------------------------------
 wicket-core/.settings/org.eclipse.jdt.ui.prefs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/d9c2d408/wicket-core/.settings/org.eclipse.jdt.ui.prefs
----------------------------------------------------------------------
diff --git a/wicket-core/.settings/org.eclipse.jdt.ui.prefs b/wicket-core/.settings/org.eclipse.jdt.ui.prefs
index 93e472a..1f00276 100644
--- a/wicket-core/.settings/org.eclipse.jdt.ui.prefs
+++ b/wicket-core/.settings/org.eclipse.jdt.ui.prefs
@@ -1,3 +1,4 @@
+#Fri Nov 05 09:40:42 PDT 2010
 comment_clear_blank_lines=false
 comment_format_comments=true
 comment_format_header=true
@@ -21,7 +22,6 @@ sp_cleanup.add_missing_deprecated_annotations=true
 sp_cleanup.add_missing_methods=false
 sp_cleanup.add_missing_nls_tags=false
 sp_cleanup.add_missing_override_annotations=true
-sp_cleanup.add_missing_override_annotations_interface_methods=false
 sp_cleanup.add_serial_version_id=false
 sp_cleanup.always_use_blocks=true
 sp_cleanup.always_use_parentheses_in_expressions=false


[03/11] git commit: Merge remote-tracking branch 'upstream/master' into bugfix-WICKET-5147-cookies-wickettester-second-try

Posted by mg...@apache.org.
Merge remote-tracking branch 'upstream/master' into bugfix-WICKET-5147-cookies-wickettester-second-try


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

Branch: refs/heads/master
Commit: 184e51e99c9774ca3cdff6a1d7568d63ef19c5dd
Parents: e87c847 4323728
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Tue Apr 23 00:34:04 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Tue Apr 23 00:34:04 2013 +0200

----------------------------------------------------------------------
 archetypes/quickstart/pom.xml                      |    2 +-
 .../src/main/resources/archetype-resources/pom.xml |    2 +-
 pom.xml                                            |   52 ++++----
 testing/wicket-common-tests/pom.xml                |    2 +-
 testing/wicket-threadtest/pom.xml                  |    2 +-
 wicket-auth-roles/pom.xml                          |    2 +-
 wicket-cdi/pom.xml                                 |    2 +-
 wicket-core/pom.xml                                |    2 +-
 .../org/apache/wicket/DefaultExceptionMapper.java  |    5 +-
 .../src/main/java/org/apache/wicket/Page.java      |    2 +
 .../wicket/ajax/res/js/wicket-ajax-jquery.js       |   99 +++++++++++----
 .../apache/wicket/page/AbstractPageManager.java    |    4 -
 .../apache/wicket/protocol/http/WicketFilter.java  |   28 ++++-
 .../request/cycle/PageRequestHandlerTracker.java   |    7 +
 .../html/ajaxLink/AjaxLinkPageExpectedResult.html  |    2 +-
 .../AjaxLinkWithBorderPageExpectedResult.html      |    2 +-
 .../html/ajaxLink/AjaxPage2_ExpectedResult.html    |    2 +-
 .../html/basic/SimplePageExpectedResult_13.html    |    2 +-
 .../border/HideableBorderPage_ExpectedResult.html  |    2 +-
 .../panel/InlinePanelPageExpectedResult_7.html     |    2 +-
 .../panel/InlinePanelPageExpectedResult_8.html     |    2 +-
 wicket-core/src/test/js/ajax.js                    |   23 ++++
 wicket-core/src/test/js/all.html                   |    1 +
 .../js/data/ajax/twoEvaluationsWithIdentifier.xml  |   18 +++
 wicket-datetime/pom.xml                            |    2 +-
 wicket-devutils/pom.xml                            |    2 +-
 wicket-examples/pom.xml                            |    2 +-
 wicket-experimental/pom.xml                        |    2 +-
 wicket-experimental/wicket-atmosphere/pom.xml      |    4 +-
 wicket-experimental/wicket-bean-validation/pom.xml |    4 +-
 wicket-experimental/wicket-bootstrap/pom.xml       |    4 +-
 wicket-experimental/wicket-examples-parent/pom.xml |    4 +-
 .../wicket-examples-jar/pom.xml                    |    4 +-
 .../wicket-examples-war/pom.xml                    |    4 +-
 .../wicket-native-websocket/pom.xml                |    4 +-
 .../wicket-native-websocket-core/pom.xml           |    4 +-
 .../wicket-native-websocket-jetty/pom.xml          |    4 +-
 .../wicket-native-websocket-jetty9/pom.xml         |    4 +-
 .../wicket-native-websocket-tomcat/pom.xml         |    4 +-
 wicket-extensions/pom.xml                          |    2 +-
 wicket-guice/pom.xml                               |    2 +-
 wicket-ioc/pom.xml                                 |    2 +-
 wicket-jmx/pom.xml                                 |    2 +-
 wicket-objectssizeof-agent/pom.xml                 |    2 +-
 wicket-request/pom.xml                             |    4 +-
 wicket-spring/pom.xml                              |    2 +-
 wicket-util/pom.xml                                |    2 +-
 wicket-velocity/pom.xml                            |    2 +-
 wicket/pom.xml                                     |    2 +-
 49 files changed, 229 insertions(+), 112 deletions(-)
----------------------------------------------------------------------



[09/11] git commit: WICKET-5147 moved test for cookie handling to WicketTesterCookieTest

Posted by mg...@apache.org.
WICKET-5147 moved test for cookie handling to WicketTesterCookieTest


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

Branch: refs/heads/master
Commit: 2ca43b47ab32ed0e4b6c2590bb77674368f0eb58
Parents: a02b2b6
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Fri Apr 26 07:46:32 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Fri Apr 26 07:46:32 2013 +0200

----------------------------------------------------------------------
 .../wicket/util/tester/WicketTesterCookieTest.java |  459 +++++++++++++++
 .../wicket/util/tester/WicketTesterTest.java       |  430 +--------------
 2 files changed, 460 insertions(+), 429 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/2ca43b47/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
new file mode 100644
index 0000000..3266604
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
@@ -0,0 +1,459 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.tester;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.protocol.http.mock.Cookies;
+import org.apache.wicket.util.tester.apps_1.CreateBook;
+import org.apache.wicket.util.tester.cookies.CollectAllRequestCookiesPage;
+import org.apache.wicket.util.tester.cookies.EndPage;
+import org.apache.wicket.util.tester.cookies.SetCookiePage;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * test code for wicket tester cookie handling
+ * 
+ * @author mosmann
+ */
+public class WicketTesterCookieTest extends WicketTestCase
+{
+	/**
+	 *
+	 */
+	@Test
+	public void cookieIsFoundWhenAddedToRequest()
+	{
+		tester.getRequest().addCookie(new Cookie("name", "value"));
+		assertEquals("value", tester.getRequest().getCookie("name").getValue());
+	}
+
+	/**
+	 *
+	 */
+	@Test
+	public void cookieIsFoundWhenAddedToResponse()
+	{
+		tester.startPage(CreateBook.class);
+		tester.getLastResponse().addCookie(new Cookie("name", "value"));
+		Collection<Cookie> cookies = tester.getLastResponse().getCookies();
+		assertEquals(cookies.iterator().next().getValue(), "value");
+	}
+	
+	/**
+	 * Tests that setting a cookie with age > 0 before creating the page will survive after the
+	 * rendering of the page and it will be used for the next request cycle.
+	 */
+	@Test
+	public void transferCookies()
+	{
+		String cookieName = "wicket4289Name";
+		String cookieValue = "wicket4289Value";
+		int cookieAge = 1; // age > 0 => the cookie will be preserved for the the next request cycle
+
+		Cookie cookie = new Cookie(cookieName, cookieValue);
+		cookie.setMaxAge(cookieAge);
+		tester.getRequest().addCookie(cookie);
+
+		CookiePage page = new CookiePage(cookieName, cookieValue);
+
+		tester.startPage(page);
+
+		// assert that the cookie was in the response
+		List<Cookie> cookies = tester.getLastResponse().getCookies();
+		assertEquals(1, cookies.size());
+		Cookie cookie2 = cookies.get(0);
+		assertEquals(cookieName, cookie2.getName());
+		assertEquals(cookieValue, cookie2.getValue());
+		assertEquals(cookieAge, cookie2.getMaxAge());
+
+		// assert that the cookie will be preserved for the next request
+		assertEquals(cookieValue, tester.getRequest().getCookie(cookieName).getValue());
+	}
+
+	/**
+	 * Tests that setting a cookie with age == 0 will not be stored after the request cycle.
+	 */
+	@Test
+	public void dontTransferCookiesWithNegativeAge()
+	{
+		String cookieName = "wicket4289Name";
+		String cookieValue = "wicket4289Value";
+		int cookieAge = 0; // age = 0 => do not store it
+
+		Cookie cookie = new Cookie(cookieName, cookieValue);
+		cookie.setMaxAge(cookieAge);
+		tester.getRequest().addCookie(cookie);
+
+		CookiePage page = new CookiePage(cookieName, cookieValue);
+
+		tester.startPage(page);
+
+		// assert that the cookie is not preserved for the next request cycle
+		assertNull(tester.getRequest().getCookies());
+	}
+
+	/**
+	 * Tests that setting a cookie with age < 0 will not be stored after the request cycle.
+	 */
+	@Test
+	public void dontTransferCookiesWithZeroAge()
+	{
+		String cookieName = "wicket4289Name";
+		String cookieValue = "wicket4289Value";
+		int cookieAge = 0; // age == 0 => delete the cookie
+
+		Cookie cookie = new Cookie(cookieName, cookieValue);
+		cookie.setMaxAge(cookieAge);
+		tester.getRequest().addCookie(cookie);
+
+		CookiePage page = new CookiePage(cookieName, cookieValue);
+
+		tester.startPage(page);
+
+		// assert that the cookie is not preserved for the next request cycle
+		assertNull(tester.getRequest().getCookies());
+	}
+
+	/**
+	 * A cookie set in the request headers should not be
+	 * expected in the response headers unless the page
+	 * sets it explicitly.
+	 *
+	 * https://issues.apache.org/jira/browse/WICKET-4989
+	 */
+	@Test
+	public void cookieSetInRequestShouldNotBeInResponse()
+	{
+		//start and render the test page
+		tester.getRequest().addCookie(new Cookie("dummy", "sample"));
+		tester.startPage(tester.getApplication().getHomePage());
+
+		//assert rendered page class
+		tester.assertRenderedPage(tester.getApplication().getHomePage());
+
+		Assert.assertEquals("The cookie should not be in the response unless explicitly set",
+				0, tester.getLastResponse().getCookies().size());
+
+		// The cookie should be in each following request unless the server code
+		// schedules it for removal it with cookie.setMaxAge(0)
+		Assert.assertEquals("The cookie should be in each following request",
+				1, tester.getRequest().getCookies().length);
+	}
+
+	/**
+	 * The response cookie should not be the same instance as the request
+	 * cookie.
+	 *
+	 * https://issues.apache.org/jira/browse/WICKET-4989
+	 */
+	@Test
+	public void doNotReuseTheSameInstanceOfTheCookieForRequestAndResponse()
+	{
+		//start and render the test page
+		String cookieName = "cookieName";
+		String cookieValue = "cookieValue";
+		Cookie requestCookie = new Cookie(cookieName, cookieValue);
+		tester.getRequest().addCookie(requestCookie);
+		tester.startPage(new CookiePage(cookieName, cookieValue));
+
+		//assert rendered page class
+		tester.assertRenderedPage(CookiePage.class);
+
+		Cookie responseCookie = tester.getLastResponse().getCookies().get(0);
+		requestCookie.setValue("valueChanged");
+
+		Assert.assertEquals(cookieValue, responseCookie.getValue());
+	}
+
+	/**
+	 * @see WicketTester
+	 * 
+	 * TODO add a cookie to request, which should override cookie from last response and last request
+	 * https://issues.apache.org/jira/browse/WICKET-5147
+	 */
+	@Test
+	public void wicketTesterCookieHandlingWithoutRedirect() {
+		// no cookies set
+		CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage();
+		Assert.assertTrue("no cookie in first request",collectingPage.getCookies().isEmpty());
+		lastResponseDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
+		
+		// set cookie on request
+		Cookie firstCookie = newCookie("a","firstValue",1);
+		tester.getRequest().addCookie(firstCookie);
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie);
+		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(firstCookie);
+		responseDoesNotHaveAnyCookies();
+
+		// cookies from last request should appear on following requests
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie);
+		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(firstCookie);
+		responseDoesNotHaveAnyCookies();
+
+		// cookie will be overwritten if response will do so
+		Cookie cookieSetInResponse = newCookie("a","overwriteWithNewValue",1);
+		setCookieInResponse(cookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(cookieSetInResponse);
+		requestShouldHaveTheseCookies(cookieSetInResponse);
+		
+		// cookies from last response then should appear on following requests
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage, cookieSetInResponse);
+		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(cookieSetInResponse);
+		
+		// cookies from requests will be deleted if the response will do so
+		Cookie expiredCookieSetInResponse = newCookie("a","removeMe",0);
+		setCookieInResponse(expiredCookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(expiredCookieSetInResponse);
+		responseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
+		
+		// no cookies in next request while last cookie was deleted
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage);
+		lastResponseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+	}
+
+	/**
+	 * @see WicketTesterTest#wicketTesterCookieHandlingWithoutRedirect()
+	 *  
+	 * https://issues.apache.org/jira/browse/WICKET-5147
+	 */
+	@Test
+	public void wicketTesterCookieHandlingWithRedirect() {
+		// set cookie in response then redirect to other page
+		Cookie firstCookie = newCookie("a","firstValue",1);
+		setCookieInResponseAndRedirect(firstCookie);
+		lastResponseShouldHaveTheseCookies(firstCookie);
+		requestShouldHaveTheseCookies(firstCookie);
+
+		// cookie in response after redirect should appear in next request
+		CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage,firstCookie);
+		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(firstCookie);
+		responseDoesNotHaveAnyCookies();
+		
+		// set cookie on request and overwrite in response then redirect to other page
+		Cookie cookieSetInRequest = newCookie("a","valueFromRequest",1);
+		Cookie cookieSetInResponse = newCookie("a","overwriteInResponse",1);
+		tester.getRequest().addCookie(cookieSetInRequest);
+		setCookieInResponseAndRedirect(cookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(cookieSetInResponse);
+		requestShouldHaveTheseCookies(cookieSetInResponse);
+		
+		// cookie in response after redirect should appear in next request
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage,cookieSetInResponse);
+		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(cookieSetInResponse);
+		responseDoesNotHaveAnyCookies();
+		
+		// set cookie on request and remove it in response then redirect to other page
+		Cookie nextCookieSetInRequest = newCookie("a","nextValueFromRequest",1);
+		Cookie nextCookieSetInResponse = newCookie("a","newValue",0);
+		tester.getRequest().addCookie(nextCookieSetInRequest);
+		setCookieInResponseAndRedirect(nextCookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(nextCookieSetInResponse);
+		requestDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+		
+		// no cookies left
+		collectingPage = collectAllRequestCookiesOnThisPage();
+		requestOnPageShouldHaveTheseCookies(collectingPage);
+		lastResponseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
+		responseDoesNotHaveAnyCookies();
+	}
+	
+	/**
+	 * creates a new cookie with maxAge set
+	 * @param name name
+	 * @param value value
+	 * @param maxAge maxAge
+	 * @return a cookie
+	 */
+	private static Cookie newCookie(String name,String value, int maxAge) {
+		Cookie cookie = new Cookie(name,value);
+		cookie.setMaxAge(maxAge);
+		return cookie;
+	}
+	
+	/**
+	 * start a page which collects all cookies from request 
+	 * @return the page
+	 */
+	private CollectAllRequestCookiesPage collectAllRequestCookiesOnThisPage()
+	{
+		return tester.startPage(CollectAllRequestCookiesPage.class);
+	}
+
+	/**
+	 * start a page which set a cookie in response
+	 * @param cookie cookie
+	 */
+	private void setCookieInResponse(Cookie cookie)
+	{
+		tester.startPage(new SetCookiePage(cookie));
+	}
+
+	/**
+	 * start a page which set a cookie in response and then redirect to different page
+	 * @param cookie cookie
+	 */
+	private void setCookieInResponseAndRedirect(Cookie cookie)
+	{
+		tester.startPage(new SetCookiePage(cookie,EndPage.class));
+	}
+
+	/**
+	 * check cookies collected by page
+	 * @param page page
+	 * @param cookies cookies
+	 */
+	private void requestOnPageShouldHaveTheseCookies(CollectAllRequestCookiesPage page, Cookie...cookies) {
+		listShouldMatchAll(page.getCookies(), cookies);
+	}
+
+	/**
+	 * check cookies in current request
+	 * @param page page
+	 * @param cookies cookies
+	 */
+	private void requestShouldHaveTheseCookies(Cookie...cookies) {
+		Cookie[] cookieFromRequest = tester.getRequest().getCookies();
+		listShouldMatchAll(cookieFromRequest!=null ? Arrays.asList(cookieFromRequest) : new ArrayList<Cookie>(), cookies);
+	}
+	
+	/**
+	 * check if every cookie is found in the list and no cookie is left 
+	 * @param cookieList cookie list
+	 * @param cookies cookies to check
+	 */
+	private void listShouldMatchAll(List<Cookie> cookieList, Cookie... cookies)
+	{
+		Map<String, Cookie> cookieMap = cookiesFromList(cookieList);
+		for (Cookie cookie : cookies) {
+			Cookie removed = cookieMap.remove(cookie.getName());
+			Assert.assertNotNull("Cookie "+cookie.getName(),removed);
+			Assert.assertTrue("Cookie "+cookie.getName()+" matches",Cookies.isEqual(cookie, removed));
+		}
+		Assert.assertTrue("no cookies left "+asString(cookieMap),cookieMap.isEmpty());
+	}
+	
+	/**
+	 * make cookie map more readable
+	 * @param cookieMap cookie map
+	 * @return string
+	 */
+	private static String asString(Map<String, Cookie> cookieMap)
+	{
+		StringBuilder sb=new StringBuilder();
+		sb.append("{");
+		for (Map.Entry<String, Cookie> e : cookieMap.entrySet()) {
+			sb.append(e.getKey()).append("=").append(asString(e.getValue()));
+			sb.append(",");
+		}
+		sb.append("}");
+		return sb.toString();
+	}
+
+	/**
+	 * make cookie more readable
+	 * @param c cookie
+	 * @return string
+	 */
+	private static String asString(Cookie c)
+	{
+		StringBuilder sb=new StringBuilder();
+		sb.append("[");
+		sb.append("name=").append(c.getName()).append(",");
+		sb.append("value=").append(c.getValue()).append(",");
+		sb.append("maxAge=").append(c.getMaxAge());
+		sb.append("]");
+		return sb.toString();
+	}
+
+	/**
+	 * check last response cookies
+	 * @param cookies cookies
+	 */
+	private void lastResponseShouldHaveTheseCookies(Cookie...cookies) {
+		listShouldMatchAll(tester.getLastResponse().getCookies(), cookies);
+	}
+	
+	/**
+	 * response should not have any cookies
+	 */
+	private void lastResponseDoesNotHaveAnyCookies()
+	{
+		listShouldMatchAll(tester.getLastResponse().getCookies());
+	}
+	
+	/**
+	 * response should not have any cookies
+	 */
+	private void responseDoesNotHaveAnyCookies()
+	{
+		listShouldMatchAll(tester.getResponse().getCookies());
+	}
+	
+	/**
+	 * request should not have any cookies
+	 */
+	private void requestDoesNotHaveAnyCookies()
+	{
+		requestShouldHaveTheseCookies();
+	}
+	
+	/**
+	 * create a cookie map based on cookie name
+	 * @param cookies cookie list
+	 * @return as map
+	 * @throws RuntimeException if more than one cookie with the same name
+	 */
+	private static Map<String,Cookie> cookiesFromList(List<Cookie> cookies) {
+		Map<String, Cookie> ret = new LinkedHashMap<String, Cookie>();
+		for (Cookie cookie : cookies) {
+			Cookie oldValue = ret.put(cookie.getName(), cookie);
+			if (oldValue!=null) {
+				throw new RuntimeException("Cookie with name "+cookie.getName()+"("+asString(oldValue)+") allready in map "+asString(ret));
+			}
+		}
+		return ret;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/2ca43b47/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
index 2e937f5..2014c94 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
@@ -16,15 +16,9 @@
  */
 package org.apache.wicket.util.tester;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 
-import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
 
 import junit.framework.AssertionFailedError;
@@ -55,7 +49,6 @@ import org.apache.wicket.markup.html.link.ResourceLink;
 import org.apache.wicket.markup.html.pages.AccessDeniedPage;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.protocol.http.WebApplication;
-import org.apache.wicket.protocol.http.mock.Cookies;
 import org.apache.wicket.request.IRequestHandler;
 import org.apache.wicket.request.IRequestParameters;
 import org.apache.wicket.request.Url;
@@ -78,17 +71,11 @@ import org.apache.wicket.util.tester.apps_1.SuccessPage;
 import org.apache.wicket.util.tester.apps_1.ViewBook;
 import org.apache.wicket.util.tester.apps_6.LinkPage;
 import org.apache.wicket.util.tester.apps_6.ResultPage;
-import org.apache.wicket.util.tester.cookies.CollectAllRequestCookiesPage;
-import org.apache.wicket.util.tester.cookies.EndPage;
-import org.apache.wicket.util.tester.cookies.SetCookiePage;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import sun.security.provider.certpath.OCSPResponse.ResponseStatus;
-
 /**
- * 
+ * @see WicketTesterCookieTest for cookie related test
  * @author Juergen Donnerstag
  */
 public class WicketTesterTest extends WicketTestCase
@@ -914,28 +901,6 @@ public class WicketTesterTest extends WicketTestCase
 	}
 
 	/**
-	 *
-	 */
-	@Test
-	public void cookieIsFoundWhenAddedToRequest()
-	{
-		tester.getRequest().addCookie(new Cookie("name", "value"));
-		assertEquals("value", tester.getRequest().getCookie("name").getValue());
-	}
-
-	/**
-	 *
-	 */
-	@Test
-	public void cookieIsFoundWhenAddedToResponse()
-	{
-		tester.startPage(CreateBook.class);
-		tester.getLastResponse().addCookie(new Cookie("name", "value"));
-		Collection<Cookie> cookies = tester.getLastResponse().getCookies();
-		assertEquals(cookies.iterator().next().getValue(), "value");
-	}
-
-	/**
 	 * Test for WICKET-3123
 	 */
 	@Test
@@ -1036,81 +1001,6 @@ public class WicketTesterTest extends WicketTestCase
 	}
 
 	/**
-	 * Tests that setting a cookie with age > 0 before creating the page will survive after the
-	 * rendering of the page and it will be used for the next request cycle.
-	 */
-	@Test
-	public void transferCookies()
-	{
-		String cookieName = "wicket4289Name";
-		String cookieValue = "wicket4289Value";
-		int cookieAge = 1; // age > 0 => the cookie will be preserved for the the next request cycle
-
-		Cookie cookie = new Cookie(cookieName, cookieValue);
-		cookie.setMaxAge(cookieAge);
-		tester.getRequest().addCookie(cookie);
-
-		CookiePage page = new CookiePage(cookieName, cookieValue);
-
-		tester.startPage(page);
-
-		// assert that the cookie was in the response
-		List<Cookie> cookies = tester.getLastResponse().getCookies();
-		assertEquals(1, cookies.size());
-		Cookie cookie2 = cookies.get(0);
-		assertEquals(cookieName, cookie2.getName());
-		assertEquals(cookieValue, cookie2.getValue());
-		assertEquals(cookieAge, cookie2.getMaxAge());
-
-		// assert that the cookie will be preserved for the next request
-		assertEquals(cookieValue, tester.getRequest().getCookie(cookieName).getValue());
-	}
-
-	/**
-	 * Tests that setting a cookie with age == 0 will not be stored after the request cycle.
-	 */
-	@Test
-	public void dontTransferCookiesWithNegativeAge()
-	{
-		String cookieName = "wicket4289Name";
-		String cookieValue = "wicket4289Value";
-		int cookieAge = 0; // age = 0 => do not store it
-
-		Cookie cookie = new Cookie(cookieName, cookieValue);
-		cookie.setMaxAge(cookieAge);
-		tester.getRequest().addCookie(cookie);
-
-		CookiePage page = new CookiePage(cookieName, cookieValue);
-
-		tester.startPage(page);
-
-		// assert that the cookie is not preserved for the next request cycle
-		assertNull(tester.getRequest().getCookies());
-	}
-
-	/**
-	 * Tests that setting a cookie with age < 0 will not be stored after the request cycle.
-	 */
-	@Test
-	public void dontTransferCookiesWithZeroAge()
-	{
-		String cookieName = "wicket4289Name";
-		String cookieValue = "wicket4289Value";
-		int cookieAge = 0; // age == 0 => delete the cookie
-
-		Cookie cookie = new Cookie(cookieName, cookieValue);
-		cookie.setMaxAge(cookieAge);
-		tester.getRequest().addCookie(cookie);
-
-		CookiePage page = new CookiePage(cookieName, cookieValue);
-
-		tester.startPage(page);
-
-		// assert that the cookie is not preserved for the next request cycle
-		assertNull(tester.getRequest().getCookies());
-	}
-
-	/**
 	 * Tests if the access-denied-page is rendered if a page is rerendered for which you don't have
 	 * permission anymore
 	 */
@@ -1327,322 +1217,4 @@ public class WicketTesterTest extends WicketTestCase
 		tester.submitForm(page.form);
 		assertEquals(null, page.text);
 	}
-
-	/**
-	 * A cookie set in the request headers should not be
-	 * expected in the response headers unless the page
-	 * sets it explicitly.
-	 *
-	 * https://issues.apache.org/jira/browse/WICKET-4989
-	 */
-	@Test
-	public void cookieSetInRequestShouldNotBeInResponse()
-	{
-		//start and render the test page
-		tester.getRequest().addCookie(new Cookie("dummy", "sample"));
-		tester.startPage(tester.getApplication().getHomePage());
-
-		//assert rendered page class
-		tester.assertRenderedPage(tester.getApplication().getHomePage());
-
-		Assert.assertEquals("The cookie should not be in the response unless explicitly set",
-				0, tester.getLastResponse().getCookies().size());
-
-		// The cookie should be in each following request unless the server code
-		// schedules it for removal it with cookie.setMaxAge(0)
-		Assert.assertEquals("The cookie should be in each following request",
-				1, tester.getRequest().getCookies().length);
-	}
-
-	/**
-	 * The response cookie should not be the same instance as the request
-	 * cookie.
-	 *
-	 * https://issues.apache.org/jira/browse/WICKET-4989
-	 */
-	@Test
-	public void doNotReuseTheSameInstanceOfTheCookieForRequestAndResponse()
-	{
-		//start and render the test page
-		String cookieName = "cookieName";
-		String cookieValue = "cookieValue";
-		Cookie requestCookie = new Cookie(cookieName, cookieValue);
-		tester.getRequest().addCookie(requestCookie);
-		tester.startPage(new CookiePage(cookieName, cookieValue));
-
-		//assert rendered page class
-		tester.assertRenderedPage(CookiePage.class);
-
-		Cookie responseCookie = tester.getLastResponse().getCookies().get(0);
-		requestCookie.setValue("valueChanged");
-
-		Assert.assertEquals(cookieValue, responseCookie.getValue());
-	}
-	
-	/**
-	 * @see WicketTester
-	 * 
-	 * TODO add a cookie to request, which should override cookie from last response and last request
-	 * https://issues.apache.org/jira/browse/WICKET-5147
-	 */
-	@Test
-	public void wicketTesterCookieHandlingWithoutRedirect() {
-		// no cookies set
-		CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage();
-		Assert.assertTrue("no cookie in first request",collectingPage.getCookies().isEmpty());
-		lastResponseDoesNotHaveAnyCookies();
-		responseDoesNotHaveAnyCookies();
-		requestDoesNotHaveAnyCookies();
-		
-		// set cookie on request
-		Cookie firstCookie = newCookie("a","firstValue",1);
-		tester.getRequest().addCookie(firstCookie);
-		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie);
-		lastResponseDoesNotHaveAnyCookies();
-		requestShouldHaveTheseCookies(firstCookie);
-		responseDoesNotHaveAnyCookies();
-
-		// cookies from last request should appear on following requests
-		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie);
-		lastResponseDoesNotHaveAnyCookies();
-		requestShouldHaveTheseCookies(firstCookie);
-		responseDoesNotHaveAnyCookies();
-
-		// cookie will be overwritten if response will do so
-		Cookie cookieSetInResponse = newCookie("a","overwriteWithNewValue",1);
-		setCookieInResponse(cookieSetInResponse);
-		lastResponseShouldHaveTheseCookies(cookieSetInResponse);
-		requestShouldHaveTheseCookies(cookieSetInResponse);
-		
-		// cookies from last response then should appear on following requests
-		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage, cookieSetInResponse);
-		lastResponseDoesNotHaveAnyCookies();
-		requestShouldHaveTheseCookies(cookieSetInResponse);
-		
-		// cookies from requests will be deleted if the response will do so
-		Cookie expiredCookieSetInResponse = newCookie("a","removeMe",0);
-		setCookieInResponse(expiredCookieSetInResponse);
-		lastResponseShouldHaveTheseCookies(expiredCookieSetInResponse);
-		responseDoesNotHaveAnyCookies();
-		requestDoesNotHaveAnyCookies();
-		
-		// no cookies in next request while last cookie was deleted
-		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage);
-		lastResponseDoesNotHaveAnyCookies();
-		requestDoesNotHaveAnyCookies();
-		responseDoesNotHaveAnyCookies();
-	}
-
-	/**
-	 * @see WicketTesterTest#wicketTesterCookieHandlingWithoutRedirect()
-	 *  
-	 * https://issues.apache.org/jira/browse/WICKET-5147
-	 */
-	@Test
-	public void wicketTesterCookieHandlingWithRedirect() {
-		// set cookie in response then redirect to other page
-		Cookie firstCookie = newCookie("a","firstValue",1);
-		setCookieInResponseAndRedirect(firstCookie);
-		lastResponseShouldHaveTheseCookies(firstCookie);
-		requestShouldHaveTheseCookies(firstCookie);
-
-		// cookie in response after redirect should appear in next request
-		CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage,firstCookie);
-		lastResponseDoesNotHaveAnyCookies();
-		requestShouldHaveTheseCookies(firstCookie);
-		responseDoesNotHaveAnyCookies();
-		
-		// set cookie on request and overwrite in response then redirect to other page
-		Cookie cookieSetInRequest = newCookie("a","valueFromRequest",1);
-		Cookie cookieSetInResponse = newCookie("a","overwriteInResponse",1);
-		tester.getRequest().addCookie(cookieSetInRequest);
-		setCookieInResponseAndRedirect(cookieSetInResponse);
-		lastResponseShouldHaveTheseCookies(cookieSetInResponse);
-		requestShouldHaveTheseCookies(cookieSetInResponse);
-		
-		// cookie in response after redirect should appear in next request
-		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage,cookieSetInResponse);
-		lastResponseDoesNotHaveAnyCookies();
-		requestShouldHaveTheseCookies(cookieSetInResponse);
-		responseDoesNotHaveAnyCookies();
-		
-		// set cookie on request and remove it in response then redirect to other page
-		Cookie nextCookieSetInRequest = newCookie("a","nextValueFromRequest",1);
-		Cookie nextCookieSetInResponse = newCookie("a","newValue",0);
-		tester.getRequest().addCookie(nextCookieSetInRequest);
-		setCookieInResponseAndRedirect(nextCookieSetInResponse);
-		lastResponseShouldHaveTheseCookies(nextCookieSetInResponse);
-		requestDoesNotHaveAnyCookies();
-		responseDoesNotHaveAnyCookies();
-		
-		// no cookies left
-		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage);
-		lastResponseDoesNotHaveAnyCookies();
-		requestDoesNotHaveAnyCookies();
-		responseDoesNotHaveAnyCookies();
-	}
-	
-	/**
-	 * creates a new cookie with maxAge set
-	 * @param name name
-	 * @param value value
-	 * @param maxAge maxAge
-	 * @return a cookie
-	 */
-	private static Cookie newCookie(String name,String value, int maxAge) {
-		Cookie cookie = new Cookie(name,value);
-		cookie.setMaxAge(maxAge);
-		return cookie;
-	}
-	
-	/**
-	 * start a page which collects all cookies from request 
-	 * @return the page
-	 */
-	private CollectAllRequestCookiesPage collectAllRequestCookiesOnThisPage()
-	{
-		return tester.startPage(CollectAllRequestCookiesPage.class);
-	}
-
-	/**
-	 * start a page which set a cookie in response
-	 * @param cookie cookie
-	 */
-	private void setCookieInResponse(Cookie cookie)
-	{
-		tester.startPage(new SetCookiePage(cookie));
-	}
-
-	/**
-	 * start a page which set a cookie in response and then redirect to different page
-	 * @param cookie cookie
-	 */
-	private void setCookieInResponseAndRedirect(Cookie cookie)
-	{
-		tester.startPage(new SetCookiePage(cookie,EndPage.class));
-	}
-
-	/**
-	 * check cookies collected by page
-	 * @param page page
-	 * @param cookies cookies
-	 */
-	private void requestOnPageShouldHaveTheseCookies(CollectAllRequestCookiesPage page, Cookie...cookies) {
-		listShouldMatchAll(page.getCookies(), cookies);
-	}
-
-	/**
-	 * check cookies in current request
-	 * @param page page
-	 * @param cookies cookies
-	 */
-	private void requestShouldHaveTheseCookies(Cookie...cookies) {
-		Cookie[] cookieFromRequest = tester.getRequest().getCookies();
-		listShouldMatchAll(cookieFromRequest!=null ? Arrays.asList(cookieFromRequest) : new ArrayList<Cookie>(), cookies);
-	}
-	
-	/**
-	 * check if every cookie is found in the list and no cookie is left 
-	 * @param cookieList cookie list
-	 * @param cookies cookies to check
-	 */
-	private void listShouldMatchAll(List<Cookie> cookieList, Cookie... cookies)
-	{
-		Map<String, Cookie> cookieMap = cookiesFromList(cookieList);
-		for (Cookie cookie : cookies) {
-			Cookie removed = cookieMap.remove(cookie.getName());
-			Assert.assertNotNull("Cookie "+cookie.getName(),removed);
-			Assert.assertTrue("Cookie "+cookie.getName()+" matches",Cookies.isEqual(cookie, removed));
-		}
-		Assert.assertTrue("no cookies left "+asString(cookieMap),cookieMap.isEmpty());
-	}
-	
-	/**
-	 * make cookie map more readable
-	 * @param cookieMap cookie map
-	 * @return string
-	 */
-	private static String asString(Map<String, Cookie> cookieMap)
-	{
-		StringBuilder sb=new StringBuilder();
-		sb.append("{");
-		for (Map.Entry<String, Cookie> e : cookieMap.entrySet()) {
-			sb.append(e.getKey()).append("=").append(asString(e.getValue()));
-			sb.append(",");
-		}
-		sb.append("}");
-		return sb.toString();
-	}
-
-	/**
-	 * make cookie more readable
-	 * @param c cookie
-	 * @return string
-	 */
-	private static String asString(Cookie c)
-	{
-		StringBuilder sb=new StringBuilder();
-		sb.append("[");
-		sb.append("name=").append(c.getName()).append(",");
-		sb.append("value=").append(c.getValue()).append(",");
-		sb.append("maxAge=").append(c.getMaxAge());
-		sb.append("]");
-		return sb.toString();
-	}
-
-	/**
-	 * check last response cookies
-	 * @param cookies cookies
-	 */
-	private void lastResponseShouldHaveTheseCookies(Cookie...cookies) {
-		listShouldMatchAll(tester.getLastResponse().getCookies(), cookies);
-	}
-	
-	/**
-	 * response should not have any cookies
-	 */
-	private void lastResponseDoesNotHaveAnyCookies()
-	{
-		listShouldMatchAll(tester.getLastResponse().getCookies());
-	}
-	
-	/**
-	 * response should not have any cookies
-	 */
-	private void responseDoesNotHaveAnyCookies()
-	{
-		listShouldMatchAll(tester.getResponse().getCookies());
-	}
-	
-	/**
-	 * request should not have any cookies
-	 */
-	private void requestDoesNotHaveAnyCookies()
-	{
-		requestShouldHaveTheseCookies();
-	}
-	
-	/**
-	 * create a cookie map based on cookie name
-	 * @param cookies cookie list
-	 * @return as map
-	 * @throws RuntimeException if more than one cookie with the same name
-	 */
-	private static Map<String,Cookie> cookiesFromList(List<Cookie> cookies) {
-		Map<String, Cookie> ret = new LinkedHashMap<String, Cookie>();
-		for (Cookie cookie : cookies) {
-			Cookie oldValue = ret.put(cookie.getName(), cookie);
-			if (oldValue!=null) {
-				throw new RuntimeException("Cookie with name "+cookie.getName()+"("+asString(oldValue)+") allready in map "+asString(ret));
-			}
-		}
-		return ret;
-	}
 }


[11/11] git commit: WICKET-5147 WicketTester MockHttpRequest.getCookies very slow / OutOfMemory

Posted by mg...@apache.org.
WICKET-5147 WicketTester MockHttpRequest.getCookies very slow / OutOfMemory

Minor formatting improvements.


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

Branch: refs/heads/master
Commit: 8df9d9920452cef32c1ded2e0d7fc551b730ad0b
Parents: 714f81a
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri Apr 26 11:02:20 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Fri Apr 26 11:02:20 2013 +0200

----------------------------------------------------------------------
 .../protocol/http/mock/CookieCollection.java       |   20 +++--------
 .../apache/wicket/protocol/http/mock/Cookies.java  |    3 +-
 .../wicket/util/tester/BaseWicketTester.java       |   12 +++---
 .../wicket/util/tester/WicketTesterCookieTest.java |   26 ++++++++-------
 .../wicket/util/tester/cookies/SetCookiePage.java  |    4 ++-
 5 files changed, 30 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
index d316450..ec89916 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
@@ -32,8 +32,8 @@ import org.apache.wicket.protocol.http.mock.Cookies.Key;
  */
 public class CookieCollection
 {
-	Map<Cookies.Key, Cookie> cookies = new LinkedHashMap<Cookies.Key, Cookie>();
-	Map<Cookies.Key, Cookie> expiredCookies = new LinkedHashMap<Cookies.Key, Cookie>();
+	private final Map<Cookies.Key, Cookie> cookies = new LinkedHashMap<Cookies.Key, Cookie>();
+	private final Map<Cookies.Key, Cookie> expiredCookies = new LinkedHashMap<Cookies.Key, Cookie>();
 
 	/**
 	 * add cookie to collection
@@ -45,7 +45,7 @@ public class CookieCollection
 	{
 		Key key = Cookies.keyOf(cookie);
 		Cookie copyOfCookie = Cookies.copyOf(cookie);
-		if (isExpired(cookie))
+		if (Cookies.isExpired(cookie))
 		{
 			expiredCookies.put(key, copyOfCookie);
 			cookies.remove(key);
@@ -63,7 +63,9 @@ public class CookieCollection
 	public void addAll(Cookie[] cookies)
 	{
 		if (cookies != null)
+		{
 			addAll(Arrays.asList(cookies));
+		}
 	}
 
 	/**
@@ -112,16 +114,4 @@ public class CookieCollection
 		return ret;
 	}
 
-	/**
-	 * detect if this cookie is expired
-	 * 
-	 * @param cookie
-	 * @return true, if expired
-	 */
-	public static boolean isExpired(Cookie cookie)
-	{
-		return cookie.getMaxAge() == 0;
-	}
-
-
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
index e660772..54ecb97 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
@@ -43,7 +43,7 @@ public final class Cookies
 	 */
 	public static Cookie copyOf(Cookie cookie)
 	{
-		return cookie != null ? (Cookie)cookie.clone() : null;
+		return cookie != null ? (Cookie) cookie.clone() : null;
 	}
 
 	/**
@@ -96,6 +96,7 @@ public final class Cookies
 
 		protected Key(Cookie cookie)
 		{
+			Args.notNull(cookie, "cookie");
 			name = cookie.getName();
 			path = cookie.getPath();
 			domain = cookie.getDomain();

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index cc28aa5..28dfb2a 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -29,7 +29,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -99,7 +98,6 @@ import org.apache.wicket.protocol.http.IMetaDataBufferingWebResponse;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.http.WicketFilter;
 import org.apache.wicket.protocol.http.mock.CookieCollection;
-import org.apache.wicket.protocol.http.mock.Cookies;
 import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
 import org.apache.wicket.protocol.http.mock.MockHttpServletResponse;
 import org.apache.wicket.protocol.http.mock.MockHttpSession;
@@ -382,7 +380,7 @@ public class BaseWicketTester
 			List<Cookie> lastResponseCookies = lastResponse.getCookies();
 			if (lastResponse.isRedirect()) 
 			{
-				CookieCollection responseCookies=new CookieCollection();
+				CookieCollection responseCookies = new CookieCollection();
 				
 				// if the last request is a redirect, all cookies from last response should appear in current reponse
 				// this call will filter duplicates
@@ -394,7 +392,8 @@ public class BaseWicketTester
 				
 				// copy all request cookies from last request to the new request because of redirect handling
 				// this way, the cookie will be send to the next requested page
-				if (lastRequest!=null) {
+				if (lastRequest != null)
+				{
 					CookieCollection requestCookies=new CookieCollection();
 					// this call will filter duplicates
 					requestCookies.addAll(lastRequest.getCookies());
@@ -407,8 +406,9 @@ public class BaseWicketTester
 				// - copy last request cookies to collection
 				// - copy last response cookies to collection
 				// - set only the not expired cookies to the next request
-				CookieCollection cookies=new CookieCollection();				
-				if (lastRequest!=null) {
+				CookieCollection cookies = new CookieCollection();
+				if (lastRequest != null)
+				{
 					// this call will filter duplicates
 					cookies.addAll(lastRequest.getCookies());
 				}

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
index 3266604..13facf0 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java
@@ -248,7 +248,7 @@ public class WicketTesterCookieTest extends WicketTestCase
 	}
 
 	/**
-	 * @see WicketTesterTest#wicketTesterCookieHandlingWithoutRedirect()
+	 * @see WicketTesterCookieTest#wicketTesterCookieHandlingWithoutRedirect()
 	 *  
 	 * https://issues.apache.org/jira/browse/WICKET-5147
 	 */
@@ -350,7 +350,6 @@ public class WicketTesterCookieTest extends WicketTestCase
 
 	/**
 	 * check cookies in current request
-	 * @param page page
 	 * @param cookies cookies
 	 */
 	private void requestShouldHaveTheseCookies(Cookie...cookies) {
@@ -382,12 +381,12 @@ public class WicketTesterCookieTest extends WicketTestCase
 	private static String asString(Map<String, Cookie> cookieMap)
 	{
 		StringBuilder sb=new StringBuilder();
-		sb.append("{");
+		sb.append('{');
 		for (Map.Entry<String, Cookie> e : cookieMap.entrySet()) {
-			sb.append(e.getKey()).append("=").append(asString(e.getValue()));
+			sb.append(e.getKey()).append('=').append(asString(e.getValue()));
 			sb.append(",");
 		}
-		sb.append("}");
+		sb.append('}');
 		return sb.toString();
 	}
 
@@ -399,11 +398,11 @@ public class WicketTesterCookieTest extends WicketTestCase
 	private static String asString(Cookie c)
 	{
 		StringBuilder sb=new StringBuilder();
-		sb.append("[");
-		sb.append("name=").append(c.getName()).append(",");
-		sb.append("value=").append(c.getValue()).append(",");
+		sb.append('[');
+		sb.append("name=").append(c.getName()).append(',');
+		sb.append("value=").append(c.getValue()).append(',');
 		sb.append("maxAge=").append(c.getMaxAge());
-		sb.append("]");
+		sb.append(']');
 		return sb.toString();
 	}
 
@@ -447,10 +446,13 @@ public class WicketTesterCookieTest extends WicketTestCase
 	 */
 	private static Map<String,Cookie> cookiesFromList(List<Cookie> cookies) {
 		Map<String, Cookie> ret = new LinkedHashMap<String, Cookie>();
-		for (Cookie cookie : cookies) {
+		for (Cookie cookie : cookies)
+		{
 			Cookie oldValue = ret.put(cookie.getName(), cookie);
-			if (oldValue!=null) {
-				throw new RuntimeException("Cookie with name "+cookie.getName()+"("+asString(oldValue)+") allready in map "+asString(ret));
+			if (oldValue != null)
+			{
+				throw new RuntimeException(String.format("Cookie with name '%s' ('%s') already in map %s",
+						cookie.getName(), asString(oldValue), asString(ret)));
 			}
 		}
 		return ret;

http://git-wip-us.apache.org/repos/asf/wicket/blob/8df9d992/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
index 0887d02..dd2c49b 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/cookies/SetCookiePage.java
@@ -44,10 +44,12 @@ public class SetCookiePage extends DummyHomePage
 	
 	protected void onInitialize() {
 		super.onInitialize();
+
 		WebResponse response = (WebResponse) getResponse();
 		response.addCookie(cookie);
 		
-		if (redirectToPageClass!=null) {
+		if (redirectToPageClass != null)
+		{
 			setResponsePage(redirectToPageClass);
 		}
 	};


[10/11] git commit: WICKET-5147 code formating

Posted by mg...@apache.org.
WICKET-5147 code formating


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

Branch: refs/heads/master
Commit: 714f81a89a518b6b5dd047539eaaf664aa2c42cc
Parents: 2ca43b4
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Fri Apr 26 07:48:11 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Fri Apr 26 07:48:11 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/protocol/http/mock/Cookies.java  |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/714f81a8/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
index adc7be7..e660772 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
@@ -59,7 +59,8 @@ public final class Cookies
 	}
 
 	/**
-	 * Checks whether two cookies are equal. See http://www.ietf.org/rfc/rfc2109.txt, p.4.3.3
+	 * Checks whether two cookies are equal. 
+	 * See http://www.ietf.org/rfc/rfc2109.txt, p.4.3.3
 	 * 
 	 * @param c1
 	 *            the first cookie


[04/11] git commit: WICKET-5147 cookie handling now with cookies visible in request

Posted by mg...@apache.org.
WICKET-5147 cookie handling now with cookies visible in request


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

Branch: refs/heads/master
Commit: 42b9d50bf3c92b37560f63f1dd52eac07f4838a4
Parents: 184e51e
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Fri Apr 26 01:23:29 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Fri Apr 26 01:23:29 2013 +0200

----------------------------------------------------------------------
 wicket-core/.settings/org.eclipse.jdt.ui.prefs     |    4 +-
 .../protocol/http/mock/CookieCollection.java       |  127 +++++++++++++++
 .../apache/wicket/protocol/http/mock/Cookies.java  |   99 +++++++++++-
 .../protocol/http/mock/MockHttpServletRequest.java |   16 +-
 .../wicket/util/tester/BaseWicketTester.java       |  102 ++++--------
 .../apache/wicket/util/tester/WicketTester.java    |    4 +-
 .../wicket/util/tester/WicketTesterTest.java       |   92 ++++++++----
 7 files changed, 331 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/42b9d50b/wicket-core/.settings/org.eclipse.jdt.ui.prefs
----------------------------------------------------------------------
diff --git a/wicket-core/.settings/org.eclipse.jdt.ui.prefs b/wicket-core/.settings/org.eclipse.jdt.ui.prefs
index 1f00276..108d88d 100644
--- a/wicket-core/.settings/org.eclipse.jdt.ui.prefs
+++ b/wicket-core/.settings/org.eclipse.jdt.ui.prefs
@@ -1,4 +1,3 @@
-#Fri Nov 05 09:40:42 PDT 2010
 comment_clear_blank_lines=false
 comment_format_comments=true
 comment_format_header=true
@@ -10,7 +9,7 @@ comment_line_length=80
 comment_new_line_for_parameter=true
 comment_separate_root_tags=true
 eclipse.preferences.version=1
-editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false
 formatter_profile=_Wicket
 formatter_settings_version=11
 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
@@ -22,6 +21,7 @@ sp_cleanup.add_missing_deprecated_annotations=true
 sp_cleanup.add_missing_methods=false
 sp_cleanup.add_missing_nls_tags=false
 sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=false
 sp_cleanup.add_serial_version_id=false
 sp_cleanup.always_use_blocks=true
 sp_cleanup.always_use_parentheses_in_expressions=false

http://git-wip-us.apache.org/repos/asf/wicket/blob/42b9d50b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
new file mode 100644
index 0000000..d316450
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/CookieCollection.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.protocol.http.mock;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.wicket.protocol.http.mock.Cookies.Key;
+
+/**
+ * cookie collection utility
+ * @author mosmann
+ */
+public class CookieCollection
+{
+	Map<Cookies.Key, Cookie> cookies = new LinkedHashMap<Cookies.Key, Cookie>();
+	Map<Cookies.Key, Cookie> expiredCookies = new LinkedHashMap<Cookies.Key, Cookie>();
+
+	/**
+	 * add cookie to collection
+	 *   if cookie is expired, it will be moved to expired cookie set
+	 *   overwrite existing cookie with new value 
+	 * @param cookie a cookie
+	 */
+	public void add(Cookie cookie)
+	{
+		Key key = Cookies.keyOf(cookie);
+		Cookie copyOfCookie = Cookies.copyOf(cookie);
+		if (isExpired(cookie))
+		{
+			expiredCookies.put(key, copyOfCookie);
+			cookies.remove(key);
+		}
+		else
+		{
+			cookies.put(key, copyOfCookie);
+		}
+	}
+
+	/**
+	 * calls add on each cookie
+	 * @param cookies array of cookies
+	 */
+	public void addAll(Cookie[] cookies)
+	{
+		if (cookies != null)
+			addAll(Arrays.asList(cookies));
+	}
+
+	/**
+	 * calls add on each cookie
+	 * @param cookies list of cookies
+	 */
+	public void addAll(List<Cookie> cookies)
+	{
+		for (Cookie cookie : cookies)
+		{
+			add(cookie);
+		}
+	}
+
+	/**
+	 * list of non expired cookies
+	 * @return as list
+	 */
+	public List<Cookie> asList()
+	{
+		ArrayList<Cookie> ret = new ArrayList<Cookie>();
+		ret.addAll(cookies.values());
+		return ret;
+	}
+
+	/**
+	 * list of expired cookies
+	 * @return as list
+	 */
+	public List<Cookie> expiredAsList()
+	{
+		ArrayList<Cookie> ret = new ArrayList<Cookie>();
+		ret.addAll(expiredCookies.values());
+		return ret;
+	}
+
+	/**
+	 * list of all cookies, expired or not
+	 * @return as list
+	 */
+	public List<Cookie> allAsList()
+	{
+		ArrayList<Cookie> ret = new ArrayList<Cookie>();
+		ret.addAll(cookies.values());
+		ret.addAll(expiredCookies.values());
+		return ret;
+	}
+
+	/**
+	 * detect if this cookie is expired
+	 * 
+	 * @param cookie
+	 * @return true, if expired
+	 */
+	public static boolean isExpired(Cookie cookie)
+	{
+		return cookie.getMaxAge() == 0;
+	}
+
+
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/42b9d50b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
index d3a8a6e..f785ecb 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
@@ -16,8 +16,14 @@
  */
 package org.apache.wicket.protocol.http.mock;
 
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
 import javax.servlet.http.Cookie;
 
+import org.apache.wicket.protocol.http.mock.Cookies.Key;
 import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.lang.Objects;
 
@@ -45,6 +51,16 @@ public final class Cookies
 	}
 
 	/**
+	 * creates a key based on the property for cookie equality
+	 * @param cookie cookie
+	 * @return key
+	 */
+	public static Key keyOf(Cookie cookie)
+	{
+		return new Key(cookie);
+	}
+	
+	/**
 	 * Checks whether two cookies are equal.
 	 * See http://www.ietf.org/rfc/rfc2109.txt, p.4.3.3
 	 *
@@ -59,8 +75,85 @@ public final class Cookies
 		Args.notNull(c1, "c1");
 		Args.notNull(c2, "c2");
 
-		return c1.getName().equals(c2.getName()) &&
-				Objects.isEqual(c1.getPath(), c2.getPath()) &&
-				Objects.isEqual(c1.getDomain(), c2.getDomain());
+//		return c1.getName().equals(c2.getName()) &&
+//				Objects.isEqual(c1.getPath(), c2.getPath()) &&
+//				Objects.isEqual(c1.getDomain(), c2.getDomain());
+		return new Key(c1).equals(new Key(c2));
 	}
+	
+	/**
+	 * detect if this cookie is expired
+	 * @param cookie
+	 * @return
+	 */
+	public static boolean isExpired(Cookie cookie)
+	{
+		return cookie.getMaxAge() == 0;
+	}
+	
+	public static class Key implements Serializable {
+		
+		private final String name;
+		private final String path;
+		private final String domain;
+
+		protected Key(Cookie cookie) {
+			this.name=cookie.getName();
+			this.path=cookie.getPath();
+			this.domain=cookie.getDomain();
+		}
+
+		@Override
+		public int hashCode()
+		{
+			final int prime = 31;
+			int result = 1;
+			result = prime * result + ((domain == null) ? 0 : domain.hashCode());
+			result = prime * result + ((name == null) ? 0 : name.hashCode());
+			result = prime * result + ((path == null) ? 0 : path.hashCode());
+			return result;
+		}
+
+		@Override
+		public boolean equals(Object obj)
+		{
+			if (this == obj)
+				return true;
+			if (obj == null)
+				return false;
+			if (getClass() != obj.getClass())
+				return false;
+			Key other = (Key)obj;
+			if (domain == null)
+			{
+				if (other.domain != null)
+					return false;
+			}
+			else if (!domain.equals(other.domain))
+				return false;
+			if (name == null)
+			{
+				if (other.name != null)
+					return false;
+			}
+			else if (!name.equals(other.name))
+				return false;
+			if (path == null)
+			{
+				if (other.path != null)
+					return false;
+			}
+			else if (!path.equals(other.path))
+				return false;
+			return true;
+		}
+		
+		@Override
+		public String toString()
+		{
+			return name+";"+domain+"/"+path;
+		}
+		
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/42b9d50b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
index 8c1a123..82c3923 100755
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequest.java
@@ -30,6 +30,7 @@ import java.text.DateFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.Enumeration;
@@ -161,7 +162,7 @@ public class MockHttpServletRequest implements HttpServletRequest
 
 	private final ServletContext context;
 
-	private final List<Cookie> cookies = new ArrayList<Cookie>();
+	private final Map<Cookies.Key,Cookie> cookies = new LinkedHashMap<Cookies.Key, Cookie>();
 
 	private final ValueMap headers = new ValueMap();
 
@@ -217,7 +218,7 @@ public class MockHttpServletRequest implements HttpServletRequest
 	 */
 	public void addCookie(final Cookie cookie)
 	{
-		cookies.add(cookie);
+		cookies.put(Cookies.keyOf(cookie),cookie);
 	}
 
 	/**
@@ -478,16 +479,13 @@ public class MockHttpServletRequest implements HttpServletRequest
 	@Override
 	public Cookie[] getCookies()
 	{
-		if (cookies.size() == 0)
+		if (cookies.isEmpty())
 		{
 			return null;
 		}
-		Cookie[] result = new Cookie[cookies.size()];
-		for (int i = 0; i < cookies.size(); i++)
-		{
-			result[i] = Cookies.copyOf(cookies.get(i));
-		}
-		return result;
+		List<Cookie> cookieValues = new ArrayList<Cookie>();
+		cookieValues.addAll(cookies.values());
+		return cookieValues.toArray(new Cookie[cookieValues.size()]);
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/wicket/blob/42b9d50b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index 5c164e2..cc28aa5 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -98,6 +98,7 @@ import org.apache.wicket.page.IPageManagerContext;
 import org.apache.wicket.protocol.http.IMetaDataBufferingWebResponse;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.protocol.http.WicketFilter;
+import org.apache.wicket.protocol.http.mock.CookieCollection;
 import org.apache.wicket.protocol.http.mock.Cookies;
 import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
 import org.apache.wicket.protocol.http.mock.MockHttpServletResponse;
@@ -376,16 +377,44 @@ public class BaseWicketTester
 		// Wicket tests assert that a cookie is in the response,
 		// even after redirects (see org.apache.wicket.util.cookies.SetCookieAndRedirectTest.statefulPage())
 		// They should assert that the cookie is in the next *request*
-		if (lastResponse != null && lastResponse.isRedirect())
+		if (lastResponse != null)
 		{
 			List<Cookie> lastResponseCookies = lastResponse.getCookies();
-			for (Cookie cookie : lastResponseCookies)
+			if (lastResponse.isRedirect()) 
 			{
-				if (cookie.getMaxAge() != 0)
+				CookieCollection responseCookies=new CookieCollection();
+				
+				// if the last request is a redirect, all cookies from last response should appear in current reponse
+				// this call will filter duplicates
+				responseCookies.addAll(lastResponseCookies);
+				for (Cookie cookie : responseCookies.allAsList())
 				{
-					// max-age==0 are already handled in #transferRequestCookies() above
 					response.addCookie(cookie);
 				}
+				
+				// copy all request cookies from last request to the new request because of redirect handling
+				// this way, the cookie will be send to the next requested page
+				if (lastRequest!=null) {
+					CookieCollection requestCookies=new CookieCollection();
+					// this call will filter duplicates
+					requestCookies.addAll(lastRequest.getCookies());
+					request.addCookies(requestCookies.asList());
+				}
+			} 
+			else
+			{
+				// if the last response is not a redirect 
+				// - copy last request cookies to collection
+				// - copy last response cookies to collection
+				// - set only the not expired cookies to the next request
+				CookieCollection cookies=new CookieCollection();				
+				if (lastRequest!=null) {
+					// this call will filter duplicates
+					cookies.addAll(lastRequest.getCookies());
+				}
+				// this call will filter duplicates
+				cookies.addAll(lastResponseCookies);
+				request.addCookies(cookies.asList());
 			}
 		}
 
@@ -433,69 +462,6 @@ public class BaseWicketTester
 	}
 
 	/**
-	 * Simulates browser behavior by preserving all non-removed cookies from
-	 * the previous request.
-	 * A cookie is removed if the response contains a cookie with the same
-	 * name, path and domain and max-age=0
-	 */
-	private void transferRequestCookies()
-	{
-		List<Cookie> lastRequestCookies = new ArrayList<Cookie>();
-
-		// copy all cookies from the previous request
-		if (lastRequest != null && lastRequest.getCookies() != null)
-		{
-			for (Cookie lastRequestCookie : lastRequest.getCookies())
-			{
-				lastRequestCookies.add(lastRequestCookie);
-			}
-		}
-
-		// filter out all removed cookies
-		if (lastResponse != null)
-		{
-			List<Cookie> cookies = lastResponse.getCookies();
-			if (cookies != null)
-			{
-				for (Cookie cookie : cookies)
-				{
-					// maxAge == -1 -> means session cookie
-					// maxAge == 0 -> delete the cookie
-					// maxAge > 0 -> the cookie will expire after this age
-					if (cookie.getMaxAge() == 0)
-					{
-						Iterator<Cookie> cookieIterator = lastRequestCookies.iterator();
-						while (cookieIterator.hasNext())
-						{
-							Cookie lastRequestCookie = cookieIterator.next();
-							if (Cookies.isEqual(lastRequestCookie, cookie))
-							{
-								cookieIterator.remove();
-							}
-						}
-					}
-					else
-					{
-						Iterator<Cookie> cookieIterator = lastRequestCookies.iterator();
-						while (cookieIterator.hasNext())
-						{
-							Cookie oldCookie = cookieIterator.next();
-							if (Cookies.isEqual(cookie, oldCookie))
-							{
-								cookieIterator.remove();
-							}
-						}
-						lastRequestCookies.add(cookie);
-					}
-				}
-			}
-		}
-
-		// transfer only the non-removed ones
-		request.addCookies(lastRequestCookies);
-	}
-
-	/**
 	 * @param servletWebRequest
 	 * @return servlet web response
 	 */
@@ -681,8 +647,6 @@ public class BaseWicketTester
 
 		try
 		{
-			transferRequestCookies();
-
 			applyRequest();
 			requestCycle.scheduleRequestHandlerAfterCurrent(null);
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/42b9d50b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
index aaec246..3786693 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
@@ -153,8 +153,8 @@ import org.slf4j.LoggerFactory;
  *   after the request is made 
  * - all cookies set in the response should appear even after a redirect response is made
  *   until the final response (tester.getLastResponse()) is written to the client (wicket tester) 
- * - all valid cookies (maxAge!=0) from the last response should be added or should overwrite 
- *   the next request cookies (not visible in tester.getRequest().getCookies())
+ * - all valid cookies (maxAge!=0) from the last response should be added to
+ *   the next request cookies (tester.getRequest().getCookies())
  * 
  * 
  * TODO General: Example usage of FormTester

http://git-wip-us.apache.org/repos/asf/wicket/blob/42b9d50b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
index 2087a3f..2e937f5 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.wicket.util.tester;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -83,6 +85,8 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import sun.security.provider.certpath.OCSPResponse.ResponseStatus;
+
 /**
  * 
  * @author Juergen Donnerstag
@@ -1059,7 +1063,7 @@ public class WicketTesterTest extends WicketTestCase
 		assertEquals(cookieAge, cookie2.getMaxAge());
 
 		// assert that the cookie will be preserved for the next request
-		assertEquals(cookieValue, tester.getLastRequest().getCookie(cookieName).getValue());
+		assertEquals(cookieValue, tester.getRequest().getCookie(cookieName).getValue());
 	}
 
 	/**
@@ -1347,7 +1351,7 @@ public class WicketTesterTest extends WicketTestCase
 		// The cookie should be in each following request unless the server code
 		// schedules it for removal it with cookie.setMaxAge(0)
 		Assert.assertEquals("The cookie should be in each following request",
-				1, tester.getLastRequest().getCookies().length);
+				1, tester.getRequest().getCookies().length);
 	}
 
 	/**
@@ -1378,6 +1382,7 @@ public class WicketTesterTest extends WicketTestCase
 	/**
 	 * @see WicketTester
 	 * 
+	 * TODO add a cookie to request, which should override cookie from last response and last request
 	 * https://issues.apache.org/jira/browse/WICKET-5147
 	 */
 	@Test
@@ -1387,41 +1392,48 @@ public class WicketTesterTest extends WicketTestCase
 		Assert.assertTrue("no cookie in first request",collectingPage.getCookies().isEmpty());
 		lastResponseDoesNotHaveAnyCookies();
 		responseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
 		
 		// set cookie on request
-		Cookie cookieA = newCookie("a","1",1);
-		tester.getRequest().addCookie(cookieA);
+		Cookie firstCookie = newCookie("a","firstValue",1);
+		tester.getRequest().addCookie(firstCookie);
 		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage, cookieA);
+		requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie);
 		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(firstCookie);
 		responseDoesNotHaveAnyCookies();
 
 		// cookies from last request should appear on following requests
 		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage, cookieA);
+		requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie);
 		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(firstCookie);
 		responseDoesNotHaveAnyCookies();
 
 		// cookie will be overwritten if response will do so
-		Cookie newCookieA = newCookie("a","newValue",1);
-		setCookieInResponse(newCookieA);
-		lastResponseShouldHaveTheseCookies(newCookieA);
+		Cookie cookieSetInResponse = newCookie("a","overwriteWithNewValue",1);
+		setCookieInResponse(cookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(cookieSetInResponse);
+		requestShouldHaveTheseCookies(cookieSetInResponse);
 		
 		// cookies from last response then should appear on following requests
 		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage, newCookieA);
+		requestOnPageShouldHaveTheseCookies(collectingPage, cookieSetInResponse);
 		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(cookieSetInResponse);
 		
 		// cookies from requests will be deleted if the response will do so
-		Cookie removeCookieA = newCookie("a","removeMe",0);
-		setCookieInResponse(removeCookieA);
-		lastResponseShouldHaveTheseCookies(removeCookieA);
+		Cookie expiredCookieSetInResponse = newCookie("a","removeMe",0);
+		setCookieInResponse(expiredCookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(expiredCookieSetInResponse);
 		responseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
 		
 		// no cookies in next request while last cookie was deleted
 		collectingPage = collectAllRequestCookiesOnThisPage();
 		requestOnPageShouldHaveTheseCookies(collectingPage);
 		lastResponseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
 		responseDoesNotHaveAnyCookies();
 	}
 
@@ -1433,41 +1445,47 @@ public class WicketTesterTest extends WicketTestCase
 	@Test
 	public void wicketTesterCookieHandlingWithRedirect() {
 		// set cookie in response then redirect to other page
-		Cookie newCookieA = newCookie("a","newValue",1);
-		setCookieInResponseAndRedirect(newCookieA);
-		lastResponseShouldHaveTheseCookies(newCookieA);
+		Cookie firstCookie = newCookie("a","firstValue",1);
+		setCookieInResponseAndRedirect(firstCookie);
+		lastResponseShouldHaveTheseCookies(firstCookie);
+		requestShouldHaveTheseCookies(firstCookie);
 
 		// cookie in response after redirect should appear in next request
 		CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage,newCookieA);
+		requestOnPageShouldHaveTheseCookies(collectingPage,firstCookie);
 		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(firstCookie);
 		responseDoesNotHaveAnyCookies();
 		
 		// set cookie on request and overwrite in response then redirect to other page
-		Cookie cookieA = newCookie("a","1",1);
-		newCookieA = newCookie("a","newValue",1);
-		tester.getRequest().addCookie(cookieA);
-		setCookieInResponseAndRedirect(newCookieA);
-		lastResponseShouldHaveTheseCookies(newCookieA);
+		Cookie cookieSetInRequest = newCookie("a","valueFromRequest",1);
+		Cookie cookieSetInResponse = newCookie("a","overwriteInResponse",1);
+		tester.getRequest().addCookie(cookieSetInRequest);
+		setCookieInResponseAndRedirect(cookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(cookieSetInResponse);
+		requestShouldHaveTheseCookies(cookieSetInResponse);
 		
 		// cookie in response after redirect should appear in next request
 		collectingPage = collectAllRequestCookiesOnThisPage();
-		requestOnPageShouldHaveTheseCookies(collectingPage,newCookieA);
+		requestOnPageShouldHaveTheseCookies(collectingPage,cookieSetInResponse);
 		lastResponseDoesNotHaveAnyCookies();
+		requestShouldHaveTheseCookies(cookieSetInResponse);
 		responseDoesNotHaveAnyCookies();
 		
 		// set cookie on request and remove it in response then redirect to other page
-		cookieA = newCookie("a","1",1);
-		newCookieA = newCookie("a","newValue",0);
-		tester.getRequest().addCookie(cookieA);
-		setCookieInResponseAndRedirect(newCookieA);
-		lastResponseDoesNotHaveAnyCookies();
+		Cookie nextCookieSetInRequest = newCookie("a","nextValueFromRequest",1);
+		Cookie nextCookieSetInResponse = newCookie("a","newValue",0);
+		tester.getRequest().addCookie(nextCookieSetInRequest);
+		setCookieInResponseAndRedirect(nextCookieSetInResponse);
+		lastResponseShouldHaveTheseCookies(nextCookieSetInResponse);
+		requestDoesNotHaveAnyCookies();
 		responseDoesNotHaveAnyCookies();
 		
 		// no cookies left
 		collectingPage = collectAllRequestCookiesOnThisPage();
 		requestOnPageShouldHaveTheseCookies(collectingPage);
 		lastResponseDoesNotHaveAnyCookies();
+		requestDoesNotHaveAnyCookies();
 		responseDoesNotHaveAnyCookies();
 	}
 	
@@ -1521,6 +1539,16 @@ public class WicketTesterTest extends WicketTestCase
 	}
 
 	/**
+	 * check cookies in current request
+	 * @param page page
+	 * @param cookies cookies
+	 */
+	private void requestShouldHaveTheseCookies(Cookie...cookies) {
+		Cookie[] cookieFromRequest = tester.getRequest().getCookies();
+		listShouldMatchAll(cookieFromRequest!=null ? Arrays.asList(cookieFromRequest) : new ArrayList<Cookie>(), cookies);
+	}
+	
+	/**
 	 * check if every cookie is found in the list and no cookie is left 
 	 * @param cookieList cookie list
 	 * @param cookies cookies to check
@@ -1594,6 +1622,14 @@ public class WicketTesterTest extends WicketTestCase
 	}
 	
 	/**
+	 * request should not have any cookies
+	 */
+	private void requestDoesNotHaveAnyCookies()
+	{
+		requestShouldHaveTheseCookies();
+	}
+	
+	/**
 	 * create a cookie map based on cookie name
 	 * @param cookies cookie list
 	 * @return as map


[06/11] git commit: WICKET-5147 wicket prefs changed

Posted by mg...@apache.org.
WICKET-5147 wicket prefs changed


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

Branch: refs/heads/master
Commit: 170a174edfe591a129af85f19799436d7460d7ff
Parents: 79bba93
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Fri Apr 26 01:37:53 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Fri Apr 26 01:37:53 2013 +0200

----------------------------------------------------------------------
 wicket-core/.settings/org.eclipse.jdt.ui.prefs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/170a174e/wicket-core/.settings/org.eclipse.jdt.ui.prefs
----------------------------------------------------------------------
diff --git a/wicket-core/.settings/org.eclipse.jdt.ui.prefs b/wicket-core/.settings/org.eclipse.jdt.ui.prefs
index 108d88d..93e472a 100644
--- a/wicket-core/.settings/org.eclipse.jdt.ui.prefs
+++ b/wicket-core/.settings/org.eclipse.jdt.ui.prefs
@@ -9,7 +9,7 @@ comment_line_length=80
 comment_new_line_for_parameter=true
 comment_separate_root_tags=true
 eclipse.preferences.version=1
-editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=false
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
 formatter_profile=_Wicket
 formatter_settings_version=11
 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true


[08/11] git commit: WICKET-5147 comment clean up

Posted by mg...@apache.org.
WICKET-5147 comment clean up


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

Branch: refs/heads/master
Commit: a02b2b6774576e7815b8d84ac72fa759e1accb6e
Parents: d9c2d40
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Fri Apr 26 01:41:12 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Fri Apr 26 01:41:12 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/protocol/http/mock/Cookies.java  |   57 +++++++--------
 1 files changed, 27 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/a02b2b67/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
index f785ecb..adc7be7 100644
--- a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
+++ b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/Cookies.java
@@ -17,15 +17,10 @@
 package org.apache.wicket.protocol.http.mock;
 
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
 
 import javax.servlet.http.Cookie;
 
-import org.apache.wicket.protocol.http.mock.Cookies.Key;
 import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.lang.Objects;
 
 /**
  * A helper class for dealing with cookies
@@ -36,38 +31,40 @@ public final class Cookies
 	 * Constructor.
 	 */
 	private Cookies()
-	{}
+	{
+	}
 
 	/**
 	 * Make a copy of the passed cookie.
-	 *
+	 * 
 	 * @param cookie
-	 *          The cookie to copy
+	 *            The cookie to copy
 	 * @return A copy of the passed cookie. May be {@code null} if the argument is {@code null}.
 	 */
 	public static Cookie copyOf(Cookie cookie)
 	{
-		return cookie != null ? (Cookie) cookie.clone() : null;
+		return cookie != null ? (Cookie)cookie.clone() : null;
 	}
 
 	/**
 	 * creates a key based on the property for cookie equality
-	 * @param cookie cookie
+	 * 
+	 * @param cookie
+	 *            cookie
 	 * @return key
 	 */
 	public static Key keyOf(Cookie cookie)
 	{
 		return new Key(cookie);
 	}
-	
+
 	/**
-	 * Checks whether two cookies are equal.
-	 * See http://www.ietf.org/rfc/rfc2109.txt, p.4.3.3
-	 *
+	 * Checks whether two cookies are equal. See http://www.ietf.org/rfc/rfc2109.txt, p.4.3.3
+	 * 
 	 * @param c1
-	 *      the first cookie
+	 *            the first cookie
 	 * @param c2
-	 *      the second cookie
+	 *            the second cookie
 	 * @return {@code true} only if the cookies have the same name, path and domain
 	 */
 	public static boolean isEqual(Cookie c1, Cookie c2)
@@ -75,14 +72,12 @@ public final class Cookies
 		Args.notNull(c1, "c1");
 		Args.notNull(c2, "c2");
 
-//		return c1.getName().equals(c2.getName()) &&
-//				Objects.isEqual(c1.getPath(), c2.getPath()) &&
-//				Objects.isEqual(c1.getDomain(), c2.getDomain());
 		return new Key(c1).equals(new Key(c2));
 	}
-	
+
 	/**
 	 * detect if this cookie is expired
+	 * 
 	 * @param cookie
 	 * @return
 	 */
@@ -90,17 +85,19 @@ public final class Cookies
 	{
 		return cookie.getMaxAge() == 0;
 	}
-	
-	public static class Key implements Serializable {
-		
+
+	public static class Key implements Serializable
+	{
+
 		private final String name;
 		private final String path;
 		private final String domain;
 
-		protected Key(Cookie cookie) {
-			this.name=cookie.getName();
-			this.path=cookie.getPath();
-			this.domain=cookie.getDomain();
+		protected Key(Cookie cookie)
+		{
+			name = cookie.getName();
+			path = cookie.getPath();
+			domain = cookie.getDomain();
 		}
 
 		@Override
@@ -147,13 +144,13 @@ public final class Cookies
 				return false;
 			return true;
 		}
-		
+
 		@Override
 		public String toString()
 		{
-			return name+";"+domain+"/"+path;
+			return name + ";" + domain + "/" + path;
 		}
-		
+
 	}
 
 }


[02/11] git commit: WICKET-5147 javadoc update

Posted by mg...@apache.org.
WICKET-5147 javadoc update


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

Branch: refs/heads/master
Commit: e87c847657454f1a57b23b381b3304ba4f768b11
Parents: 2dc6b4f
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Tue Apr 23 00:33:25 2013 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Tue Apr 23 00:33:25 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/util/tester/WicketTester.java    |   17 ++++++++++++++-
 .../wicket/util/tester/WicketTesterTest.java       |    9 +------
 2 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/e87c8476/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
index a10eef8..aaec246 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
@@ -39,6 +39,7 @@ import org.apache.wicket.markup.html.list.ListView;
 import org.apache.wicket.markup.html.panel.FeedbackPanel;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.wicket.util.lang.Objects;
 import org.slf4j.Logger;
@@ -134,7 +135,7 @@ import org.slf4j.LoggerFactory;
  * 	tester.assertInfoMessages(new String[] { &quot;Wicket Rocks ;-)&quot; });
  * }
  * </pre>
- *
+ * 
  * Many methods require a 'path' parameter. E.g. the page relative path can be obtained via
  * {@link Component#getPageRelativePath()}. Since each Component has an ID/name, any Component can
  * also be referenced by its ID {@link MarkupContainer#get(String)}. And since MarkupContainer's and
@@ -142,6 +143,20 @@ import org.slf4j.LoggerFactory;
  * you may not only access direct childs but also subchilds like get("myPanel:myForm:myNameField")
  * separating each ID with a ':'.
  * 
+ * Cookie handling:
+ * 
+ * There are some expectations about wicket tester cookie handling which should match as best as
+ * it can be with a real client server request response cycle: 
+ * - all valid cookies set before a request is made (tester.getRequest().addCookie()) should
+ *   appear in the page request
+ * - all cookies set in the response should appear in the last response (tester.getLastResponse()) 
+ *   after the request is made 
+ * - all cookies set in the response should appear even after a redirect response is made
+ *   until the final response (tester.getLastResponse()) is written to the client (wicket tester) 
+ * - all valid cookies (maxAge!=0) from the last response should be added or should overwrite 
+ *   the next request cookies (not visible in tester.getRequest().getCookies())
+ * 
+ * 
  * TODO General: Example usage of FormTester
  * 
  * @author Ingram Chen

http://git-wip-us.apache.org/repos/asf/wicket/blob/e87c8476/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
index 8ffcdb0..2087a3f 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
@@ -1376,13 +1376,8 @@ public class WicketTesterTest extends WicketTestCase
 	}
 	
 	/**
-	 * There are some expectations about wicket tester cookie handling which should match as 
-	 * best as it can be with a real client server request response cycle:
-	 * - all valid cookies set before a request is made should appear in the wicket request
-	 * - all cookies set in the response should appear in the tester response after the request is made
-	 * - all cookies set in the response should appear even after a redirect response is made until the final response is written to the client
-	 * - all valid cookies from the last response should be added or should overwrite the next request cookies
-	 *
+	 * @see WicketTester
+	 * 
 	 * https://issues.apache.org/jira/browse/WICKET-5147
 	 */
 	@Test