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/01/11 11:51:32 UTC

svn commit: r733445 - in /wicket/trunk/wicket/src: main/java/org/apache/wicket/util/tester/ test/java/org/apache/wicket/util/tester/apps_7/

Author: jdonnerstag
Date: Sun Jan 11 02:51:32 2009
New Revision: 733445

URL: http://svn.apache.org/viewvc?rev=733445&view=rev
Log:
fixed wicket-2016: FormTester (BaseWicketTester.executeAjaxEvent[component,event]) submits also buttons that are hidden (isVisible=false) resulting in exception

Added:
    wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/
    wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.html
    wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java
    wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java
Modified:
    wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.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=733445&r1=733444&r2=733445&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 Sun Jan 11 02:51:32 2009
@@ -1261,20 +1261,23 @@
 			@Override
 			public void onFormComponent(FormComponent<?> formComponent)
 			{
-				// !(formComponent instanceof Button) &&
-				if (!(formComponent instanceof RadioGroup) &&
-					!(formComponent instanceof CheckGroup))
+				if (formComponent.isVisible())
 				{
-					String name = formComponent.getInputName();
-					String value = formComponent.getValue();
-
-					// Set request parameter with the field value, but do not
-					// modify an existing
-					// request parameter explicitly set using
-					// FormTester.setValue()
-					if (getServletRequest().getParameterMap().get(name) == null)
+					// !(formComponent instanceof Button) &&
+					if (!(formComponent instanceof RadioGroup) &&
+						!(formComponent instanceof CheckGroup))
 					{
-						getServletRequest().setParameter(name, value);
+						String name = formComponent.getInputName();
+						String value = formComponent.getValue();
+
+						// Set request parameter with the field value, but do not
+						// modify an existing
+						// request parameter explicitly set using
+						// FormTester.setValue()
+						if (getServletRequest().getParameterMap().get(name) == null)
+						{
+							getServletRequest().setParameter(name, value);
+						}
 					}
 				}
 			}

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.html?rev=733445&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.html Sun Jan 11 02:51:32 2009
@@ -0,0 +1,17 @@
+<html>
+    <head>
+        <title>Wicket Quickstart Archetype Homepage</title>
+    </head>
+    <body>
+        <strong>Wicket Quickstart Archetype Homepage</strong>
+        <br/><br/>
+        <span wicket:id="message">message will be here</span>
+        
+        <form wicket:id="form">
+        Input field: <input type="text" wicket:id="inputField" />
+        <input type="submit" wicket:id="hiddenButton" value="Submit"/>
+        <input type="submit" wicket:id="ajaxButton" value="Submit"/>
+        </form>
+    </body>
+</html>
+

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.java?rev=733445&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/HomePage.java Sun Jan 11 02:51:32 2009
@@ -0,0 +1,65 @@
+/*
+ * 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.util.tester.apps_7;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Button;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.Model;
+
+/**
+ * Homepage
+ */
+public class HomePage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 */
+	public HomePage()
+	{
+		this(true, 0);
+	}
+
+	/**
+	 * @param enableInputField
+	 * @param newPageId
+	 */
+	public HomePage(boolean enableInputField, int newPageId)
+	{
+		// Add the simplest type of label
+		add(new Label("message",
+			"If you see this message wicket is properly configured and running"));
+
+		Form<?> form;
+		add(form = new Form<Void>("form"));
+		form.add(new TextField<String>("inputField", new Model<String>()));
+		form.add(new Button("hiddenButton").setVisible(false));
+		form.add(new AjaxButton("ajaxButton")
+		{
+			@Override
+			protected void onSubmit(AjaxRequestTarget target, Form<?> form)
+			{
+
+			}
+		});
+	}
+}

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java?rev=733445&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java Sun Jan 11 02:51:32 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.util.tester.apps_7;
+
+import junit.framework.TestCase;
+
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * Simple test using the WicketTester
+ */
+public class TestHomePage extends TestCase
+{
+	private WicketTester tester;
+
+	@Override
+	public void setUp()
+	{
+		tester = new WicketTester(new WicketApplication());
+	}
+
+	/**
+	 * 
+	 */
+	public void testAjaxSubmitWhileAnotherButtonIsNotVisible()
+	{
+		// start and render the test page
+		tester.startPage(HomePage.class);
+		// assert rendered page class
+		tester.assertRenderedPage(HomePage.class);
+		// assert rendered label component
+		tester.assertLabel("message",
+			"If you see this message wicket is properly configured and running");
+
+		// execute ajax
+		tester.executeAjaxEvent("form:ajaxButton", "onclick");
+	}
+}

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java?rev=733445&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java Sun Jan 11 02:51:32 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.util.tester.apps_7;
+
+import org.apache.wicket.protocol.http.WebApplication;
+
+/**
+ * Application object for your web application. If you want to run this application without
+ * deploying, run the Start class.
+ * 
+ * @see com.mycompany.Start#main(String[])
+ */
+public class WicketApplication extends WebApplication
+{
+	/**
+	 * Constructor
+	 */
+	public WicketApplication()
+	{
+	}
+
+	/**
+	 * @see org.apache.wicket.Application#getHomePage()
+	 */
+	@Override
+	public Class<HomePage> getHomePage()
+	{
+		return HomePage.class;
+	}
+
+	@Override
+	protected void init()
+	{
+		getSessionSettings().setPageIdUniquePerSession(true);
+	}
+}