// component properly set up (getRelativePath() etc.). See setUp().
final Page page = application.getLastRenderedPage();
// Get the form and form component created
final TestForm form = (TestForm)page.get("form");
final TextField textField = (TextField)form.get("input");
// Make sure a valid cycle is available through RequestCycle.get().
// The RequestCycle's constructor will attach the new cycle to
// the threadLocal retrieved by RequestCycle.get().
// Attached to this cycle must be a valid request and response
final WebRequestCycle cycle = application.createRequestCycle();
// Just after init, the requests and responses cookie lists must be
// empty
assertNull(getRequestCookies(cycle));
assertEquals(0, getResponseCookies(cycle).size());
// The persister to be used for the tests
final CookieValuePersister persister = new CookieValuePersister();
// See comment on CookieValuePersister on how clearing a value with
// Cookies works. As no cookies in the request, no "delete" cookie
// will be added to the response.
persister.clear(textField);
assertNull(getRequestCookies(cycle));
assertEquals(0, getResponseCookies(cycle).size());
// Save the input field's value (add it to the response's cookie list)
persister.save(textField);
assertNull(getRequestCookies(cycle));
assertEquals(1, getResponseCookies(cycle).size());
assertEquals("test", ((Cookie)getResponseCookies(cycle).get(0)).getValue());
assertEquals("form.input", ((Cookie)getResponseCookies(cycle).get(0)).getName());
assertEquals("/WicketTester$DummyWebApplication",
((Cookie)getResponseCookies(cycle).get(0)).getPath());
// To clear in the context of cookies means to add a special cookie
// (maxAge=0) to the response, provided a cookie with
// the same name has been provided in the request. Thus, no changes in
// our test case
persister.clear(textField);
assertNull(getRequestCookies(cycle));
assertEquals(1, getResponseCookies(cycle).size());
assertEquals("test", ((Cookie)getResponseCookies(cycle).get(0)).getValue());
assertEquals("form.input", ((Cookie)getResponseCookies(cycle).get(0)).getName());
assertEquals("/WicketTester$DummyWebApplication",
((Cookie)getResponseCookies(cycle).get(0)).getPath());
// Try to load it. Because there is no Cookie matching the textfield's name
// it remains unchanged
persister.load(textField);
assertEquals("test", textField.getModelObjectAsString());
// Simulate loading a textfield. Initialize textfield with a new
// (default) value, copy the cookie from respone to request (simulating
// a browser), than load the textfield from cookie and voala the
// textfields value should change.
// save means: add it to the respone
// load means: take it from request
assertEquals("test", textField.getModelObjectAsString());
textField.setModelObject("new text");
assertEquals("new text", textField.getModelObjectAsString());
copyCookieFromResponseToRequest(cycle);
assertEquals(1, getRequestCookies(cycle).length);
assertEquals(1, getResponseCookies(cycle).size());
persister.load(textField);
assertEquals("test", textField.getModelObjectAsString());
assertEquals(1, getRequestCookies(cycle).length);
assertEquals(1, getResponseCookies(cycle).size());
// remove all cookies from mock response
// Because I'll find the cookie to be removed in the request, the