Author: jbq
Date: Thu Feb 22 05:57:04 2007
New Revision: 510519
URL: http://svn.apache.org/viewvc?view=rev&rev=510519
Log:
Keep in sync with 1.x
Added:
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.html
- copied unchanged from r509219,
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.html
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java
- copied, changed from r509219,
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.html
- copied unchanged from r509219,
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.html
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java
- copied, changed from r509219,
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java
Modified:
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/WicketTesterTest.java
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/apps_1/MyMockApplication.java
Copied:
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java
(from r509219,
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java)
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java?view=diff&rev=510519&p1=incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java&r1=509219&p2=incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java&r2=510519
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java
(original)
+++
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndAjaxFormSubmitBehavior.java
Thu Feb 22 05:57:04 2007
@@ -19,6 +19,7 @@
import java.io.Serializable;
import wicket.ajax.AjaxRequestTarget;
+import wicket.ajax.ClientEvent;
import wicket.ajax.form.AjaxFormSubmitBehavior;
import wicket.markup.html.WebComponent;
import wicket.markup.html.WebPage;
@@ -33,6 +34,8 @@
*/
public class MockPageWithFormAndAjaxFormSubmitBehavior extends WebPage
{
+ public static final String EVENT_COMPONENT = "eventComponent";
+
private static final long serialVersionUID = 1L;
private boolean executed = false;
@@ -46,15 +49,13 @@
{
pojo = new Pojo("Mock name");
- Form form = new Form("form", new CompoundPropertyModel(pojo));
- add(form);
+ Form form = new Form(this, "form", new
CompoundPropertyModel(pojo));
- form.add(new TextField("name"));
+ new TextField(form, "name");
// The Event behavior
- WebComponent eventComponent = new
WebComponent("eventComponent");
- add(eventComponent);
- eventComponent.add(new AjaxFormSubmitBehavior(form, "onclick")
+ WebComponent eventComponent = new WebComponent(this,
EVENT_COMPONENT);
+ eventComponent.add(new AjaxFormSubmitBehavior(form,
ClientEvent.CLICK)
{
private static final long serialVersionUID = 1L;
Copied:
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java
(from r509219,
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java)
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java?view=diff&rev=510519&p1=incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java&r1=509219&p2=incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java&r2=510519
==============================================================================
---
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java
(original)
+++
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/MockPageWithFormAndCheckGroup.java
Thu Feb 22 05:57:04 2007
@@ -44,24 +44,21 @@
*/
public MockPageWithFormAndCheckGroup()
{
- Form form = new Form("form");
- add(form);
+ Form form = new Form(this, "form");
+ CheckGroup checkGroup = new CheckGroup(form, "checkGroup", new
PropertyModel(this, "selected"));
- CheckGroup checkGroup = new CheckGroup("checkGroup", new
PropertyModel(this, "selected"));
- form.add(checkGroup);
+ new Check(checkGroup, "check1", new Model(new Integer(1)));
+ new Check(checkGroup, "check2", new Model(new Integer(2)));
- checkGroup.add(new Check("check1", new Model(new Integer(1))));
- checkGroup.add(new Check("check2", new Model(new Integer(2))));
-
- add(new AjaxSubmitLink("submitLink", form)
+ new AjaxSubmitLink(this, "submitLink", form)
{
private static final long serialVersionUID = 1L;
protected void onSubmit(AjaxRequestTarget target, Form
form)
{
}
- });
+ };
}
/**
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=510519&r1=510518&r2=510519
==============================================================================
---
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
Thu Feb 22 05:57:04 2007
@@ -29,7 +29,9 @@
import wicket.ajax.ClientEvent;
import wicket.ajax.markup.html.AjaxLink;
import wicket.markup.html.basic.Label;
+import wicket.markup.html.form.TextField;
import wicket.markup.html.link.Link;
+import wicket.util.tester.MockPageWithFormAndAjaxFormSubmitBehavior.Pojo;
import wicket.util.tester.apps_1.Book;
import wicket.util.tester.apps_1.CreateBook;
import wicket.util.tester.apps_1.MyMockApplication;
@@ -44,11 +46,19 @@
public class WicketTesterTest extends TestCase
{
private boolean eventExecuted;
+ private WicketTester tester;
@Override
protected void setUp() throws Exception
{
eventExecuted = false;
+ tester = new WicketTester(new MyMockApplication());
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ tester.destroy();
}
/**
@@ -57,8 +67,6 @@
*/
public void testViewBook() throws Exception
{
- MyMockApplication tester = new MyMockApplication();
-
// for WebPage without default constructor, I define a
TestPageSource to
// let the page be instatiated lately.
tester.startPage(new ITestPageSource()
@@ -76,8 +84,6 @@
tester.assertRenderedPage(ViewBook.class);
tester.assertLabel("id", "xxId");
tester.assertLabel("name", "xxName");
-
- tester.destroy();
}
/**
@@ -86,7 +92,6 @@
*/
public void testCreateBook_validateFail() throws Exception
{
- MyMockApplication tester = new MyMockApplication();
Session.get().setLocale(Locale.US); // fix locale
tester.startPage(CreateBook.class);
@@ -100,8 +105,6 @@
// assert error message from validation
tester.assertErrorMessages(new String[] { "id is required",
"name is required" });
-
- tester.destroy();
}
/**
@@ -110,7 +113,6 @@
*/
public void testCreateBook_validatePass() throws Exception
{
- MyMockApplication tester = new MyMockApplication();
tester.startPage(CreateBook.class);
FormTester formTester = tester.newFormTester("createForm");
@@ -127,7 +129,6 @@
// assert previous page expired.
// TODO Post 1.2: General: No longer a valid test
// tester.assertExpirePreviousPage();
- tester.destroy();
}
/**
@@ -136,8 +137,6 @@
*/
public void testBookmarkableLink() throws Exception
{
- MyMockApplication tester = new MyMockApplication();
-
// for WebPage without default constructor, I define a
TestPageSource to
// let the page be instatiated lately.
tester.startPage(new ITestPageSource()
@@ -155,8 +154,6 @@
tester.assertRenderedPage(ViewBook.class);
tester.clickLink("link");
tester.assertRenderedPage(CreateBook.class);
-
- tester.destroy();
}
/**
@@ -165,7 +162,6 @@
*/
public void testPageConstructor() throws Exception
{
- MyMockApplication tester = new MyMockApplication();
Book mockBook = new Book("xxId", "xxName");
Page page = new ViewBook(mockBook);
tester.startPage(page);
@@ -174,8 +170,6 @@
tester.assertRenderedPage(ViewBook.class);
tester.clickLink("link");
tester.assertRenderedPage(CreateBook.class);
-
- tester.destroy();
}
/**
@@ -183,9 +177,6 @@
*/
public void testAssertComponentOnAjaxResponse()
{
- // Start the tester
- WicketTester tester = new WicketTester();
-
final Page page = new MockPageWithLink();
AjaxLink ajaxLink = new AjaxLink(page, MockPageWithLink.LINK_ID)
{
@@ -234,8 +225,6 @@
// This must not fail
tester.assertComponentOnAjaxResponse(component);
-
- tester.destroy();
}
/**
@@ -243,9 +232,6 @@
*/
public void testExecuteAjaxEvent()
{
- // Start the tester
- WicketTester tester = new WicketTester();
-
// Setup mocks
final MockPageWithOneComponent page = new
MockPageWithOneComponent();
@@ -276,8 +262,55 @@
tester.executeAjaxEvent(label, ClientEvent.DBLCLICK);
assertTrue(eventExecuted);
+ }
+
+ /**
+ * Test that the clickLink works when submitting a form with a
checkgroup
+ * inside.
+ */
+ public void testClickLink_ajaxSubmitLink_checkGroup()
+ {
+ tester.startPage(MockPageWithFormAndCheckGroup.class);
+
+ // Click the submit
+ tester.clickLink("submitLink");
+ }
+
+ /**
+ * Test that the executeAjaxEvent "submits" the form if the event is a
+ * AjaxFormSubmitBehavior.
+ */
+ public void testExecuteAjaxEvent_ajaxFormSubmitLink()
+ {
+
tester.startPage(MockPageWithFormAndAjaxFormSubmitBehavior.class);
+
+ // Get the page
+ MockPageWithFormAndAjaxFormSubmitBehavior page =
(MockPageWithFormAndAjaxFormSubmitBehavior)tester
+ .getLastRenderedPage();
+
+ Pojo pojo = page.getPojo();
+
+ assertEquals("Mock name", pojo.getName());
+ assertEquals("Mock name",
((TextField)tester.getComponentFromLastRenderedPage("form"
+ + Component.PATH_SEPARATOR +
"name")).getValue());
+
+ assertFalse(page.isExecuted());
+
+ // Execute the ajax event
+
tester.executeAjaxEvent(MockPageWithFormAndAjaxFormSubmitBehavior.EVENT_COMPONENT,
+ ClientEvent.CLICK);
+
+ assertTrue("AjaxFormSubmitBehavior.onSubmit() has not been
executed in "
+ +
MockPageWithFormAndAjaxFormSubmitBehavior.class, page.isExecuted());
+
+ assertEquals("Mock name",
((TextField)tester.getComponentFromLastRenderedPage("form" +
Component.PATH_SEPARATOR + "name")).getValue());
- tester.destroy();
+ // The name of the pojo should still be the same. If the
+ // executeAjaxEvent weren't submitting the form the name would
have been
+ // reset to null, because the form would have been updated but
there
+ // wouldn't be any data to update it with.
+ assertNotNull("executeAjaxEvent() did not properly submit the
form", pojo.getName());
+ assertEquals("Mock name", pojo.getName());
}
/**
@@ -285,8 +318,6 @@
*/
public void testRedirectWithPageParameters()
{
- WicketTester tester = new WicketTester();
-
tester.startPage(MockPageParameterPage.class);
tester.assertLabel("label", "");
@@ -298,8 +329,6 @@
// label should now have "1" in it because that's what comes
// from the page parameter.
tester.assertLabel("label", "1");
-
- tester.destroy();
}
/**
Modified:
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/apps_1/MyMockApplication.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/apps_1/MyMockApplication.java?view=diff&rev=510519&r1=510518&r2=510519
==============================================================================
---
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/apps_1/MyMockApplication.java
(original)
+++
incubator/wicket/trunk/wicket/src/test/java/wicket/util/tester/apps_1/MyMockApplication.java
Thu Feb 22 05:57:04 2007
@@ -21,12 +21,6 @@
/**
* @author Juergen Donnerstag
*/
-public class MyMockApplication extends WicketTester
+public class MyMockApplication extends WicketTester.DummyWebApplication
{
- /**
- * Constructor.
- */
- public MyMockApplication()
- {
- }
-}
\ No newline at end of file
+}