You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/04/04 23:10:58 UTC
svn commit: r762012 - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/util/tester/
test/java/org/apache/wicket/markup/html/link/submitLink/
Author: jdonnerstag
Date: Sat Apr 4 21:10:57 2009
New Revision: 762012
URL: http://svn.apache.org/viewvc?rev=762012&view=rev
Log:
fixed WICKET-2203 WicketTester clickLink on submitLink fails with conversion error
Issue: WICKET-2203
Added:
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2Test.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPageTest.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=762012&r1=762011&r2=762012&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java Sat Apr 4 21:10:57 2009
@@ -30,6 +30,7 @@
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Session;
import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.Component.IVisitor;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
@@ -46,6 +47,7 @@
import org.apache.wicket.markup.html.form.CheckGroup;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
+import org.apache.wicket.markup.html.form.IFormVisitorParticipant;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.link.AbstractLink;
@@ -249,9 +251,9 @@
*/
public void executeListener(Component component)
{
- setupRequestAndResponse();
+ WebRequestCycle cycle = setupRequestAndResponse();
getServletRequest().setRequestToComponent(component);
- processRequestCycle();
+ processRequestCycle(cycle);
}
/**
@@ -758,6 +760,23 @@
String pageRelativePath = submitLink.getInputName();
getParametersForNextRequest().put(pageRelativePath, new String[] { "x" });
+
+ Form<?> form = submitLink.getForm();
+ form.visitFormComponents(new FormComponent.IVisitor()
+ {
+ public Object formComponent(IFormVisitorParticipant formComponent)
+ {
+ FormComponent<?> component = (FormComponent<?>)formComponent;
+ if (getParametersForNextRequest().containsKey(component.getInputName()) == false)
+ {
+ getParametersForNextRequest().put(component.getInputName(),
+ new String[] { component.getDefaultModelObjectAsString() });
+ }
+
+ return IVisitor.CONTINUE_TRAVERSAL;
+ }
+ });
+
submitForm(submitLink.getForm().getPageRelativePath());
}
// if the link is a normal link (or ResourceLink)
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java?rev=762012&r1=762011&r2=762012&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java Sat Apr 4 21:10:57 2009
@@ -678,6 +678,30 @@
}
/**
+ * A convenience method to submit the Form via a SubmitLink which may inside or outside of the
+ * Form.
+ *
+ * @param path
+ * The path to the SubmitLink
+ * @param pageRelative
+ * if true, than the 'path' to the SubmitLink is relative to the page. Thus the link
+ * can be outside the form. If false, the path is relative to the form and thus the
+ * link is inside the form.
+ */
+ public void submitLink(String path, final boolean pageRelative)
+ {
+ if (pageRelative)
+ {
+ baseWicketTester.clickLink(path, false);
+ }
+ else
+ {
+ path = this.path + ":" + path;
+ baseWicketTester.clickLink(path, false);
+ }
+ }
+
+ /**
* Adds an additional <code>FormComponent</code>'s value into request parameter -- this method
* retains existing parameters but removes any duplicate parameters.
*
Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.html?rev=762012&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.html Sat Apr 4 21:10:57 2009
@@ -0,0 +1,8 @@
+<html>
+ <body>
+ <form wicket:id="form">
+ <input type="text" wicket:id="field" />
+ </form>
+ <a href="#" wicket:id="link">click</a>
+ </body>
+</html>
Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java?rev=762012&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage.java Sat Apr 4 21:10:57 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.markup.html.link.submitLink;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.SubmitLink;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.PropertyModel;
+
+/**
+ *
+ */
+public class FormPage extends WebPage
+{
+ private final int somevalue = 1;
+
+ private boolean formSubmitted;
+
+ private boolean submitLinkSubmitted;
+
+ private final Form form;
+
+ public FormPage()
+ {
+ form = new Form("form")
+ {
+ @Override
+ protected void onSubmit()
+ {
+ formSubmitted = true;
+ }
+ };
+ add(form);
+
+ form.add(new TextField("field", new PropertyModel(this, "somevalue")));
+
+ add(new SubmitLink("link", form)
+ {
+ @Override
+ public void onSubmit()
+ {
+ submitLinkSubmitted = true;
+ }
+ });
+ }
+
+ public boolean isFormSubmitted()
+ {
+ return formSubmitted;
+ }
+
+ public boolean isSubmitLinkSubmitted()
+ {
+ return submitLinkSubmitted;
+ }
+}
Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.html?rev=762012&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.html Sat Apr 4 21:10:57 2009
@@ -0,0 +1,8 @@
+<html>
+ <body>
+ <form wicket:id="form">
+ <input type="text" wicket:id="field" />
+ <a href="#" wicket:id="link">click</a>
+ </form>
+ </body>
+</html>
Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.java?rev=762012&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2.java Sat Apr 4 21:10:57 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.markup.html.link.submitLink;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.SubmitLink;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.PropertyModel;
+
+/**
+ *
+ */
+public class FormPage2 extends WebPage
+{
+ private final int somevalue = 1;
+
+ private boolean formSubmitted;
+
+ private boolean submitLinkSubmitted;
+
+ private final Form form;
+
+ public FormPage2()
+ {
+ form = new Form("form")
+ {
+ @Override
+ protected void onSubmit()
+ {
+ formSubmitted = true;
+ }
+ };
+ add(form);
+
+ form.add(new TextField("field", new PropertyModel(this, "somevalue")));
+
+ form.add(new SubmitLink("link", form)
+ {
+ @Override
+ public void onSubmit()
+ {
+ submitLinkSubmitted = true;
+ }
+ });
+ }
+
+ public boolean isFormSubmitted()
+ {
+ return formSubmitted;
+ }
+
+ public boolean isSubmitLinkSubmitted()
+ {
+ return submitLinkSubmitted;
+ }
+}
Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2Test.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2Test.java?rev=762012&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2Test.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPage2Test.java Sat Apr 4 21:10:57 2009
@@ -0,0 +1,93 @@
+/*
+ * 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.markup.html.link.submitLink;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.wicket.util.tester.FormTester;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ *
+ */
+public class FormPage2Test extends TestCase
+{
+ /**
+ *
+ */
+ public void testSubmitlinkIsSubmitted()
+ {
+ WicketTester tester = new WicketTester();
+ tester.startPage(FormPage2.class);
+
+ FormPage2 page = (FormPage2)tester.getLastRenderedPage();
+
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ Assert.assertFalse(page.isFormSubmitted());
+
+ tester.clickLink("form:link", false);
+ page = (FormPage2)tester.getLastRenderedPage();
+
+ Assert.assertTrue(page.isSubmitLinkSubmitted());
+ Assert.assertTrue(page.isFormSubmitted());
+ }
+
+ /**
+ *
+ */
+ public void testFormIsSubmitted()
+ {
+ WicketTester tester = new WicketTester();
+ tester.startPage(FormPage2.class);
+
+ FormPage2 page = (FormPage2)tester.getLastRenderedPage();
+
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ Assert.assertFalse(page.isFormSubmitted());
+
+ FormTester formTester = tester.newFormTester("form");
+ formTester.submit();
+
+ page = (FormPage2)tester.getLastRenderedPage();
+
+ Assert.assertTrue(page.isFormSubmitted());
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ }
+
+ /**
+ *
+ */
+ public void testFormAndLinkAreSubmitted()
+ {
+ WicketTester tester = new WicketTester();
+ tester.startPage(FormPage2.class);
+
+ FormPage2 page = (FormPage2)tester.getLastRenderedPage();
+
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ Assert.assertFalse(page.isFormSubmitted());
+
+ FormTester formTester = tester.newFormTester("form");
+ formTester.submitLink("link", false);
+
+ page = (FormPage2)tester.getLastRenderedPage();
+
+ Assert.assertTrue(page.isFormSubmitted());
+ Assert.assertTrue(page.isSubmitLinkSubmitted());
+ }
+}
Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPageTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPageTest.java?rev=762012&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPageTest.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/link/submitLink/FormPageTest.java Sat Apr 4 21:10:57 2009
@@ -0,0 +1,93 @@
+/*
+ * 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.markup.html.link.submitLink;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.wicket.util.tester.FormTester;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ *
+ */
+public class FormPageTest extends TestCase
+{
+ /**
+ *
+ */
+ public void testSubmitlinkIsSubmitted()
+ {
+ WicketTester tester = new WicketTester();
+ tester.startPage(FormPage.class);
+
+ FormPage page = (FormPage)tester.getLastRenderedPage();
+
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ Assert.assertFalse(page.isFormSubmitted());
+
+ tester.clickLink("link", false);
+ page = (FormPage)tester.getLastRenderedPage();
+
+ Assert.assertTrue(page.isSubmitLinkSubmitted());
+ Assert.assertTrue(page.isFormSubmitted());
+ }
+
+ /**
+ *
+ */
+ public void testFormIsSubmitted()
+ {
+ WicketTester tester = new WicketTester();
+ tester.startPage(FormPage.class);
+
+ FormPage page = (FormPage)tester.getLastRenderedPage();
+
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ Assert.assertFalse(page.isFormSubmitted());
+
+ FormTester formTester = tester.newFormTester("form");
+ formTester.submit();
+
+ page = (FormPage)tester.getLastRenderedPage();
+
+ Assert.assertTrue(page.isFormSubmitted());
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ }
+
+ /**
+ *
+ */
+ public void testFormAndLinkAreSubmitted()
+ {
+ WicketTester tester = new WicketTester();
+ tester.startPage(FormPage.class);
+
+ FormPage page = (FormPage)tester.getLastRenderedPage();
+
+ Assert.assertFalse(page.isSubmitLinkSubmitted());
+ Assert.assertFalse(page.isFormSubmitted());
+
+ FormTester formTester = tester.newFormTester("form");
+ formTester.submitLink("link", true);
+
+ page = (FormPage)tester.getLastRenderedPage();
+
+ Assert.assertTrue(page.isFormSubmitted());
+ Assert.assertTrue(page.isSubmitLinkSubmitted());
+ }
+}