You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by fr...@apache.org on 2006/11/04 23:12:34 UTC
svn commit: r471276 - in /incubator/wicket/trunk/wicket/src:
main/java/wicket/util/tester/ test/java/wicket/util/tester/
Author: frankbille
Date: Sat Nov 4 14:12:34 2006
New Revision: 471276
URL: http://svn.apache.org/viewvc?view=rev&rev=471276
Log:
WICKET-35 WicketTester can now test BookmarkablePageLinks with PageParameters.
Added:
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html (with props)
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java (with props)
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java?view=diff&rev=471276&r1=471275&r2=471276
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/WicketTester.java Sat Nov 4 14:12:34 2006
@@ -35,6 +35,7 @@
import wicket.Component;
import wicket.MarkupContainer;
import wicket.Page;
+import wicket.PageParameters;
import wicket.RequestCycle;
import wicket.WicketRuntimeException;
import wicket.ajax.AjaxEventBehavior;
@@ -53,6 +54,7 @@
import wicket.markup.html.form.Form;
import wicket.markup.html.form.FormComponent;
import wicket.markup.html.form.RadioGroup;
+import wicket.markup.html.link.BookmarkablePageLink;
import wicket.markup.html.link.IPageLink;
import wicket.markup.html.link.Link;
import wicket.markup.html.link.PageLink;
@@ -728,6 +730,31 @@
else if (linkComponent instanceof Link)
{
Link link = (Link)linkComponent;
+
+ /*
+ * If the link is a bookmarkable link, then we need to transfer the
+ * parameters to the next request.
+ */
+ if (link instanceof BookmarkablePageLink)
+ {
+ BookmarkablePageLink bookmarkablePageLink = (BookmarkablePageLink)link;
+ try
+ {
+ Field parametersField = BookmarkablePageLink.class
+ .getDeclaredField("parameters");
+ parametersField.setAccessible(true);
+ PageParameters parameters = (PageParameters)parametersField
+ .get(bookmarkablePageLink);
+ setParametersForNextRequest(parameters);
+ }
+ catch (Exception e)
+ {
+ Assert.fail("Internal error in WicketTester. "
+ + "Please report this in Wickets Issue Tracker.");
+ }
+
+ }
+
newRequestToComponent(link);
}
else
@@ -997,24 +1024,24 @@
* component by using:
*
* <pre>
- * ...
- * component.add(new AjaxEventBehavior(ClientEvent.DBLCLICK) {
- * public void onEvent(AjaxRequestTarget) {
- * // Do something.
- * }
- * });
- * ...
+ * ...
+ * component.add(new AjaxEventBehavior(ClientEvent.DBLCLICK) {
+ * public void onEvent(AjaxRequestTarget) {
+ * // Do something.
+ * }
+ * });
+ * ...
* </pre>
*
* You can then test that the code inside onEvent actually does what it's
* supposed to, using the WicketTester:
*
* <pre>
- * ...
- * tester.executeAjaxEvent(component, ClientEvent.DBLCLICK);
- *
- * // Test that the code inside onEvent is correct.
- * ...
+ * ...
+ * tester.executeAjaxEvent(component, ClientEvent.DBLCLICK);
+ *
+ * // Test that the code inside onEvent is correct.
+ * ...
* </pre>
*
* PLEASE NOTE! This method doesn't actually insert the component in the
Added: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html?view=auto&rev=471276
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html (added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html Sat Nov 4 14:12:34 2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://www.wicketframework.org/">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Insert title here</title>
+</head>
+<body>
+<a wicket:id="link">Bookmarkable link</a>
+<span wicket:id="label"></span>
+</body>
+</html>
\ No newline at end of file
Propchange: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java?view=auto&rev=471276
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java (added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java Sat Nov 4 14:12:34 2006
@@ -0,0 +1,44 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ==============================================================================
+ * Licensed 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 wicket.util.tester;
+
+import wicket.PageParameters;
+import wicket.markup.html.WebPage;
+import wicket.markup.html.basic.Label;
+import wicket.markup.html.link.BookmarkablePageLink;
+
+/**
+ * Mock page for testing PageParameters handling in WicketTester.
+ *
+ * @author Frank Bille Jensen (frankbille)
+ */
+public class MockPageParameterPage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct.
+ * @param pageParameters
+ */
+ public MockPageParameterPage(PageParameters pageParameters)
+ {
+ new BookmarkablePageLink(this, "link", MockPageParameterPage.class, new PageParameters("id=1"));
+ new Label(this, "label", pageParameters.getString("id"));
+ }
+}
Propchange: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java?view=diff&rev=471276&r1=471275&r2=471276
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java (original)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java Sat Nov 4 14:12:34 2006
@@ -267,4 +267,24 @@
assertTrue(eventExecuted);
}
+
+ /**
+ *
+ */
+ public void testRedirectWithPageParameters()
+ {
+ WicketTester tester = new WicketTester();
+
+ tester.startPage(MockPageParameterPage.class);
+
+ tester.assertLabel("label", "");
+
+ // Click the bookmarkable link
+ tester.clickLink("link");
+
+ // It should still be the MockPageParameterPage, but the
+ // label should now have "1" in it because that's what comes
+ // from the page parameter.
+ tester.assertLabel("label", "1");
+ }
}