Author: frankbille
Date: Sat Nov  4 14:11:25 2006
New Revision: 471275

URL: http://svn.apache.org/viewvc?view=rev&rev=471275
Log:
WICKET-35 WicketTester can now test BookmarkablePageLinks with PageParameters.

Added:
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
   (with props)
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
   (with props)
Modified:
    incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml
    
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/WicketTester.java
    
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java

Modified: incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml?view=diff&rev=471275&r1=471274&r2=471275
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml 
(original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/changes/changes.xml Sat Nov 
 4 14:11:25 2006
@@ -14,6 +14,9 @@
   <body>
     <release version="1.3" date="tbd" description="Wicket 1.3">
        </release>
+       <release version="1.2.4" description="Wicket 1.2.4">
+               <action type="fix" dev="Frank Bille Jensen" 
issue="WICKET-35">WicketTester can now test BookmarkablePageLinks with 
PageParameters.</action>
+       </release>
        <release version="1.2.3" description="Wicket 1.2.3">
                <action type="fix" dev="Frank Bille Jensen" 
issue="WICKET-16">Make sure that bookmarkable urls for classes containing 
non-ascii characters is encoded properly.</action>
                <action type="add" dev="Eelco Hillenius">Added method protected 
void onDisabled(final ComponentTag tag) to FormComponent, which is called 
during rendering when the component is disabled. By default, an 
disabled="disabled" attribute is added, but clients may override this 
method.</action>

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/WicketTester.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/WicketTester.java?view=diff&rev=471275&r1=471274&r2=471275
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/WicketTester.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/WicketTester.java
 Sat Nov  4 14:11:25 2006
@@ -33,6 +33,7 @@
 
 import wicket.Component;
 import wicket.Page;
+import wicket.PageParameters;
 import wicket.RequestCycle;
 import wicket.WicketRuntimeException;
 import wicket.ajax.AjaxEventBehavior;
@@ -51,6 +52,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;
@@ -691,6 +693,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
@@ -955,24 +982,24 @@
         * component by using:
         * 
         * <pre>
-        *  ...
-        *  component.add(new AjaxEventBehavior(&quot;ondblclick&quot;) {
-        *      public void onEvent(AjaxRequestTarget) {
-        *          // Do something.
-        *      }
-        *  });
-        *  ...
+        *    ...
+        *    component.add(new AjaxEventBehavior(&quot;ondblclick&quot;) {
+        *        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, &quot;ondblclick&quot;);
-        *            
-        *  // Test that the code inside onEvent is correct.
-        *  ...
+        *    ...
+        *    tester.executeAjaxEvent(component, &quot;ondblclick&quot;);
+        *              
+        *    // Test that the code inside onEvent is correct.
+        *    ...
         * </pre>
         * 
         * This also works with AjaxFormSubmitBehavior, where it will "submit" 
the

Added: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html?view=auto&rev=471275
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
 (added)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
 Sat Nov  4 14:11:25 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/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.html
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java?view=auto&rev=471275
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
 (added)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
 Sat Nov  4 14:11:25 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)
+       {
+               add(new BookmarkablePageLink("link", 
MockPageParameterPage.class, new PageParameters("id=1")));
+               add(new Label("label", pageParameters.getString("id")));
+       }
+}

Propchange: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageParameterPage.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java?view=diff&rev=471275&r1=471274&r2=471275
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
 (original)
+++ 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
 Sat Nov  4 14:11:25 2006
@@ -314,4 +314,25 @@
 
                assertTrue(page.isExecuted());
        }
+
+
+       /**
+        * 
+        */
+       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");
+       }
 }


Reply via email to