Author: jdonnerstag
Date: Thu May 27 17:32:28 2010
New Revision: 948918
URL: http://svn.apache.org/viewvc?rev=948918&view=rev
Log:
fixed WICKET-2863 MockHttpServletResponse does not save Session cookies (maxAge
= -1)
Issue: WICKET-2863
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java?rev=948918&r1=948917&r2=948918&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
Thu May 27 17:32:28 2010
@@ -1272,6 +1272,7 @@ public class Form<T> extends WebMarkupCo
{
public Object component(final Component component)
{
+ log.error("1: " +
component.getPageRelativePath());
return visitor.component(component);
}
});
@@ -1280,15 +1281,19 @@ public class Form<T> extends WebMarkupCo
if (!error[0] && (getParent() instanceof Border))
{
MarkupContainer border = getParent();
- Iterator<? extends Component> iter = border.iterator();
- while (!error[0] && iter.hasNext())
+ border.visitChildren(Component.class, new
IVisitor<Component>()
{
- Component child = iter.next();
- if ((child != this) && (child instanceof
FormComponent))
+ public Object component(final Component
component)
{
- visitor.component(child);
+ if ((component == Form.this) ||
!(component instanceof FormComponent))
+ {
+ return
Component.IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
+ }
+
+ log.error("2: " +
component.getPageRelativePath());
+ return visitor.component(component);
}
- }
+ });
}
return error[0];
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java?rev=948918&r1=948917&r2=948918&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/MockWebApplication.java
Thu May 27 17:32:28 2010
@@ -214,25 +214,28 @@ public class MockWebApplication
super.addCookie(cookie);
// remove any potential duplicates
- cookiesOfThisSession.remove(cookie);
-
- // if maxAge <= 0, than remove cookie from
browser session
- if (cookie.getMaxAge() > 0)
- {
- cookiesOfThisSession.add(cookie);
- }
- else
+ Iterator<Cookie> iter =
cookiesOfThisSession.iterator();
+ while (iter.hasNext())
{
- Iterator<Cookie> iter =
cookiesOfThisSession.iterator();
- while (iter.hasNext())
+ Cookie entry = iter.next();
+ if
(cookie.getName().equals(entry.getName()))
{
- Cookie entry = iter.next();
- if
(cookie.getName().equals(entry.getName()))
- {
- iter.remove();
- }
+ iter.remove();
}
}
+
+ // From Cookie javadoc:
+ // A positive value indicates that the cookie
will expire after that many seconds
+ // have passed. Note that the value is the
maximum age when the cookie will expire,
+ // not the cookie's current age.
+ // A negative value means that the cookie is
not stored persistently and will be
+ // deleted when the Web browser exits. A zero
value causes the cookie to be deleted.
+ if (cookie.getMaxAge() != 0)
+ {
+ cookiesOfThisSession.add(cookie);
+ }
+
+ // Note that Cookie expiration is not yet
implemented in WicketTester
}
};
Modified:
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java?rev=948918&r1=948917&r2=948918&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java
Thu May 27 17:32:28 2010
@@ -641,7 +641,13 @@ public class WicketTesterTest extends Te
public void testCookieIsFoundOnNextRequestWhenAddedToWicketResponse()
{
+ // Test that maxAge == -1 (Default) works properly
Cookie cookie = new Cookie("name", "value");
+ tester.getWicketResponse().addCookie(cookie);
+ tester.setupRequestAndResponse();
+ assertEquals("value",
tester.getWicketRequest().getCookie("name").getValue());
+
+ cookie = new Cookie("name", "value");
cookie.setMaxAge(60);
tester.getWicketResponse().addCookie(cookie);
tester.setupRequestAndResponse();