Author: jbq
Date: Tue Mar 6 10:08:19 2007
New Revision: 515233
URL: http://svn.apache.org/viewvc?view=rev&rev=515233
Log:
WICKET-165 While testing with FormTester: onSelectionChanged is not being
invoked if DropDownChoice is enabled for notifications
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.html
(with props)
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.java
(with props)
incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.html
(with props)
incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.java
(with props)
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/FormTester.java
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/FormDispatchEventTest.java
incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/FormTester.java
incubator/wicket/trunk/wicket/src/test/java/wicket/FormDispatchEventTest.java
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/FormTester.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/FormTester.java?view=diff&rev=515233&r1=515232&r2=515233
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/FormTester.java
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/util/tester/FormTester.java
Tue Mar 6 10:08:19 2007
@@ -48,7 +48,7 @@
import wicket.util.upload.FileUploadException;
/**
- * A helper for testing validaiton and submission of Form component.
+ * A helper for testing validation and submission of Form component.
*
* @author Ingram Chen
* @author Frank Bille (frankbille)
@@ -367,7 +367,9 @@
if
(Strings.isEmpty(formComponent.getValue()))
{
if (fillBlankString)
+ {
setFormComponentValue(formComponent, "");
+ }
}
else
{
@@ -398,7 +400,9 @@
{
Component c = getForm().get(id);
if (c instanceof AbstractTextComponent)
+ {
return ((AbstractTextComponent)c).getValue();
+ }
return null;
}
@@ -417,9 +421,27 @@
public void select(String formComponentId, int index)
{
checkClosed();
- ChoiceSelector choiceSelector =
choiceSelectorFactory.create((FormComponent)workingForm
- .get(formComponentId));
+ FormComponent component = (FormComponent)workingForm
+ .get(formComponentId);
+
+ ChoiceSelector choiceSelector =
choiceSelectorFactory.create(component);
choiceSelector.doSelect(index);
+ if (component instanceof DropDownChoice) {
+ Method wantOnSelectionChangedNotificationsMethod;
+ try
+ {
+ wantOnSelectionChangedNotificationsMethod =
component.getClass().getDeclaredMethod("wantOnSelectionChangedNotifications",
new Class[0]);
+
wantOnSelectionChangedNotificationsMethod.setAccessible(true);
+ boolean wantOnSelectionChangedNotifications =
((Boolean)wantOnSelectionChangedNotificationsMethod.invoke(component, new
Object[0])).booleanValue();
+ if (wantOnSelectionChangedNotifications) {
+
((DropDownChoice)component).onSelectionChanged();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
/**
Modified:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/FormDispatchEventTest.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/FormDispatchEventTest.java?view=diff&rev=515233&r1=515232&r2=515233
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/FormDispatchEventTest.java
(original)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/FormDispatchEventTest.java
Tue Mar 6 10:08:19 2007
@@ -16,45 +16,13 @@
*/
package wicket;
-import java.util.ArrayList;
-
-import wicket.markup.html.form.DropDownChoice;
-import wicket.markup.html.form.Form;
-import wicket.markup.html.form.IOnChangeListener;
-import wicket.model.Model;
-import wicket.protocol.http.MockPage;
+import wicket.util.tester.FormTester;
/**
* @author jcompagner
*/
public class FormDispatchEventTest extends WicketTestCase
{
- private final class MyForm extends Form
- {
- private static final long serialVersionUID = 1L;
-
- private MyForm(String id)
- {
- super(id);
- }
-
- protected void onSubmit()
- {
- submit = true;
- }
-
- /**
- * @return The hidden field id of the form
- */
- public String getHiddenField()
- {
- return getHiddenFieldId();
- }
- }
-
- private boolean selection;
- private boolean submit;
-
/**
* Construct.
*
@@ -70,46 +38,18 @@
*/
public void testDropDownEvent() throws Exception
{
- MyForm form = new MyForm("form");
-
- DropDownChoice dropDown = new DropDownChoice("dropdown",new
Model(), new ArrayList())
- {
- private static final long serialVersionUID = 1L;
-
- protected void onSelectionChanged(Object newSelection)
- {
- selection = true;
- }
-
- /**
- * @see
wicket.markup.html.form.DropDownChoice#wantOnSelectionChangedNotifications()
- */
- protected boolean wantOnSelectionChangedNotifications()
- {
- return true;
- }
- };
-
-
- form.add(dropDown);
-
- MockPage page = new MockPage();
- page.add(form);
-
- tester.setupRequestAndResponse();
- RequestCycle cycle = tester.createRequestCycle();
+ tester.startPage(MockPageWithForm.class);
- page.urlFor(IRedirectListener.INTERFACE);
- cycle.getSession().touch(page);
- cycle.getSession().update();
+ // FIXME should not be needed
+ tester.createRequestCycle();
- form.onFormSubmitted();
- assertTrue("form should should set value ", submit);
+ FormTester formTester = tester.newFormTester("form");
+ formTester.select("dropdown", 0);
+ formTester.submit();
- tester.getServletRequest().setParameter(form.getHiddenField(),
-
dropDown.urlFor(IOnChangeListener.INTERFACE).toString());
+ MockPageWithForm page =
(MockPageWithForm)tester.getLastRenderedPage();
- form.onFormSubmitted();
- assertTrue("Selection should be called", selection);
+ assertTrue("Form.onSubmit() should have been called",
page.isSubmitted());
+ assertTrue("DropDownChoice.onSelectionChanged() should have
been called", page.isSelected());
}
}
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.html?view=auto&rev=515233
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.html
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.html
Tue Mar 6 10:08:19 2007
@@ -0,0 +1,3 @@
+<form wicket:id="form">
+ <select wicket:id="dropdown"></select>
+</form>
Propchange:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.html
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.java?view=auto&rev=515233
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.java
(added)
+++
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.java
Tue Mar 6 10:08:19 2007
@@ -0,0 +1,86 @@
+/*
+ * 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 wicket;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import wicket.markup.html.WebPage;
+import wicket.markup.html.form.DropDownChoice;
+import wicket.markup.html.form.Form;
+import wicket.model.Model;
+
+public class MockPageWithForm extends WebPage
+{
+ private boolean selected;
+ private boolean submitted;
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public MockPageWithForm()
+ {
+ List list = new ArrayList();
+ list.add("Select me");
+ MyForm form = new MyForm("form");
+ DropDownChoice dropDown = new DropDownChoice("dropdown",new
Model(), list)
+ {
+ private static final long serialVersionUID = 1L;
+
+ protected void onSelectionChanged(Object newSelection)
+ {
+ selected = true;
+ }
+
+ /**
+ * @see
wicket.markup.html.form.DropDownChoice#wantOnSelectionChangedNotifications()
+ */
+ protected boolean wantOnSelectionChangedNotifications()
+ {
+ return true;
+ }
+ };
+
+
+ form.add(dropDown);
+ add(form);
+ }
+ private final class MyForm extends Form
+ {
+ private static final long serialVersionUID = 1L;
+
+ private MyForm(String id)
+ {
+ super(id);
+ }
+
+ protected void onSubmit()
+ {
+ submitted = true;
+ }
+ }
+ public boolean isSelected()
+ {
+ return selected;
+ }
+ public boolean isSubmitted()
+ {
+ return submitted;
+ }
+}
Propchange:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/MockPageWithForm.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified:
incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/FormTester.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/FormTester.java?view=diff&rev=515233&r1=515232&r2=515233
==============================================================================
---
incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/FormTester.java
(original)
+++
incubator/wicket/trunk/wicket/src/main/java/wicket/util/tester/FormTester.java
Tue Mar 6 10:08:19 2007
@@ -48,7 +48,7 @@
import wicket.util.upload.FileUploadException;
/**
- * A helper for testing validaiton and submission of Form component.
+ * A helper for testing validation and submission of Form component.
*
* @author Ingram Chen
* @author Frank Bille (frankbille)
@@ -425,9 +425,27 @@
public void select(String formComponentId, int index)
{
checkClosed();
- ChoiceSelector choiceSelector =
choiceSelectorFactory.create((FormComponent)workingForm
- .get(formComponentId));
+ FormComponent component = (FormComponent)workingForm
+ .get(formComponentId);
+
+ ChoiceSelector choiceSelector =
choiceSelectorFactory.create(component);
choiceSelector.doSelect(index);
+ if (component instanceof DropDownChoice) {
+ Method wantOnSelectionChangedNotificationsMethod;
+ try
+ {
+ wantOnSelectionChangedNotificationsMethod =
component.getClass().getDeclaredMethod("wantOnSelectionChangedNotifications",
new Class[0]);
+
wantOnSelectionChangedNotificationsMethod.setAccessible(true);
+ boolean wantOnSelectionChangedNotifications =
((Boolean)wantOnSelectionChangedNotificationsMethod.invoke(component, new
Object[0])).booleanValue();
+ if (wantOnSelectionChangedNotifications) {
+
((DropDownChoice)component).onSelectionChanged();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
/**
Modified:
incubator/wicket/trunk/wicket/src/test/java/wicket/FormDispatchEventTest.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/FormDispatchEventTest.java?view=diff&rev=515233&r1=515232&r2=515233
==============================================================================
---
incubator/wicket/trunk/wicket/src/test/java/wicket/FormDispatchEventTest.java
(original)
+++
incubator/wicket/trunk/wicket/src/test/java/wicket/FormDispatchEventTest.java
Tue Mar 6 10:08:19 2007
@@ -16,46 +16,13 @@
*/
package wicket;
-import java.util.ArrayList;
-
-import wicket.markup.html.form.DropDownChoice;
-import wicket.markup.html.form.Form;
-import wicket.markup.html.form.IOnChangeListener;
-import wicket.model.Model;
+import wicket.util.tester.FormTester;
/**
* @author jcompagner
*/
public class FormDispatchEventTest extends WicketTestCase
{
- private final class MyForm extends Form
- {
- private static final long serialVersionUID = 1L;
-
- private MyForm(MarkupContainer parent, String id)
- {
- super(parent, id);
- }
-
- @Override
- protected void onSubmit()
- {
- submit = true;
- }
-
- /**
- * @param name
- * @return The hidden field id of the form
- */
- public String getHiddenField(String name)
- {
- return getHiddenFieldId(name);
- }
- }
-
- private boolean selection;
- private boolean submit;
-
/**
* Construct.
*
@@ -71,45 +38,18 @@
*/
public void testDropDownEvent() throws Exception
{
- MockPageWithFormAndDropdown page = new
MockPageWithFormAndDropdown();
- MyForm form = new MyForm(page, "form");
+ tester.startPage(MockPageWithForm.class);
+
+ // FIXME should not be needed
+ tester.createRequestCycle();
+
+ FormTester formTester = tester.newFormTester("form");
+ formTester.select("dropdown", 0);
+ formTester.submit();
- DropDownChoice<String> dropDown = new
DropDownChoice<String>(form, "dropdown", new Model<String>(), new
ArrayList<String>())
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void onSelectionChanged(String newSelection)
- {
- selection = true;
- }
-
- /**
- * @see
wicket.markup.html.form.DropDownChoice#wantOnSelectionChangedNotifications()
- */
- @Override
- protected boolean wantOnSelectionChangedNotifications()
- {
- return true;
- }
- };
-
-
- tester.setupRequestAndResponse();
- RequestCycle cycle = tester.createRequestCycle();
-
- page.urlFor(IRedirectListener.INTERFACE);
- cycle.getSession().touch(page);
- cycle.getSession().update();
-
- form.onFormSubmitted();
- assertTrue("form should should set value ", submit);
-
- tester.getServletRequest().setParameter(
-
form.getHiddenField(Form.HIDDEN_FIELD_FAKE_SUBMIT),
-
dropDown.urlFor(IOnChangeListener.INTERFACE).toString());
+ MockPageWithForm page =
(MockPageWithForm)tester.getLastRenderedPage();
- form.onFormSubmitted();
- assertTrue("Selection should be called", selection);
+ assertTrue("Form.onSubmit() should have been called",
page.isSubmitted());
+ assertTrue("DropDownChoice.onSelectionChanged() should have
been called", page.isSelected());
}
}
Added: incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.html
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.html?view=auto&rev=515233
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.html
(added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.html
Tue Mar 6 10:08:19 2007
@@ -0,0 +1,3 @@
+<form wicket:id="form">
+ <select wicket:id="dropdown"></select>
+</form>
Propchange:
incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.java?view=auto&rev=515233
==============================================================================
--- incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.java
(added)
+++ incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.java
Tue Mar 6 10:08:19 2007
@@ -0,0 +1,82 @@
+/*
+ * 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 wicket;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import wicket.markup.html.WebPage;
+import wicket.markup.html.form.DropDownChoice;
+import wicket.markup.html.form.Form;
+import wicket.model.Model;
+
+public class MockPageWithForm extends WebPage
+{
+ private boolean selected;
+ private boolean submitted;
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public MockPageWithForm()
+ {
+ List list = new ArrayList();
+ list.add("Select me");
+ MyForm form = new MyForm(this, "form");
+ new DropDownChoice(form, "dropdown", new Model(), list)
+ {
+ private static final long serialVersionUID = 1L;
+
+ protected void onSelectionChanged(Object newSelection)
+ {
+ selected = true;
+ }
+
+ /**
+ * @see
wicket.markup.html.form.DropDownChoice#wantOnSelectionChangedNotifications()
+ */
+ protected boolean wantOnSelectionChangedNotifications()
+ {
+ return true;
+ }
+ };
+ }
+ private final class MyForm extends Form
+ {
+ private static final long serialVersionUID = 1L;
+
+ private MyForm(MarkupContainer parent, String id)
+ {
+ super(parent, id);
+ }
+
+ protected void onSubmit()
+ {
+ submitted = true;
+ }
+ }
+ public boolean isSelected()
+ {
+ return selected;
+ }
+ public boolean isSubmitted()
+ {
+ return submitted;
+ }
+}
Propchange:
incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/wicket/trunk/wicket/src/test/java/wicket/MockPageWithForm.java
------------------------------------------------------------------------------
svn:keywords = Id