You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ja...@apache.org on 2007/06/19 09:51:21 UTC
svn commit: r548635 - in
/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester:
BaseWicketTester.java FormTester.java WicketTester.java
Author: janne
Date: Tue Jun 19 00:51:20 2007
New Revision: 548635
URL: http://svn.apache.org/viewvc?view=rev&rev=548635
Log:
moved newFormTester from WicketTester to BaseWicketTester
Modified:
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java
incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?view=diff&rev=548635&r1=548634&r2=548635
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java Tue Jun 19 00:51:20 2007
@@ -68,9 +68,9 @@
* A helper to ease unit testing of Wicket applications without the need for a
* servlet container. See javadoc of WicketTester for example usage. This class
* can be used as is, but JUnit users should use derived class WicketTester.
- *
+ *
* @see WicketTester
- *
+ *
* @author Ingram Chen
* @author Juergen Donnerstag
* @author Frank Bille
@@ -90,7 +90,7 @@
/**
* Construct.
- *
+ *
* @param page
*/
private TestPageSource(Page page)
@@ -131,7 +131,7 @@
/**
* Create WicketTester and automatically create a WebApplication.
- *
+ *
* @param homePage
*/
public BaseWicketTester(final Class homePage)
@@ -145,7 +145,7 @@
{
return homePage;
}
-
+
protected void outputDevelopmentModeWarning()
{
// Do nothing.
@@ -155,7 +155,7 @@
/**
* Create WicketTester
- *
+ *
* @param application
* The wicket tester object
*/
@@ -166,13 +166,13 @@
/**
* Create WicketTester to help unit testing
- *
+ *
* @param application
* The wicket tester object
* @param path
* The absolute path on disk to the web application contents
* (e.g. war root) - may be null
- *
+ *
* @see org.apache.wicket.protocol.http.MockWebApplication#MockWebApplication(String)
*/
public BaseWicketTester(final WebApplication application, final String path)
@@ -184,7 +184,7 @@
* Render a page defined in <code>TestPageSource</code>. This is usually
* used when a page does not have default constructor. For example, a
* <code>ViewBook</code> page requires a <code>Book</code> instance:
- *
+ *
* <pre>
* tester.startPage(new TestPageSource()
* {
@@ -195,7 +195,7 @@
* }
* });
* </pre>
- *
+ *
* @param testPageSource
* a page factory that creating test page instance
* @return Page rendered page
@@ -213,7 +213,7 @@
/**
* Builds and processes a request suitable for invoking a listener. The
* component must implement any of the known *Listener interfaces.
- *
+ *
* @param component
* the listener to invoke
*/
@@ -226,7 +226,7 @@
/**
* Builds and processes a request suitable for executing an ajax behavior.
- *
+ *
* @param behavior
* the ajax behavior to execute
*/
@@ -243,7 +243,7 @@
/**
* Render the page
- *
+ *
* @param page
* @return The page rendered
*/
@@ -254,7 +254,7 @@
/**
* Render a page from its default constructor.
- *
+ *
* @param pageClass
* a test page class with default constructor
* @return Page Rendered Page
@@ -266,6 +266,39 @@
}
/**
+ * create a {@link FormTester} for the form at path, and fill all child
+ * {@link org.apache.wicket.markup.html.form.FormComponent}s with blank
+ * String initially.
+ *
+ * @param path
+ * path to {@link Form} component
+ * @return FormTester A FormTester instance for testing form
+ * @see #newFormTester(String, boolean)
+ */
+ public FormTester newFormTester(String path)
+ {
+ return newFormTester(path, true);
+ }
+
+ /**
+ * create a {@link FormTester} for the form at path.
+ *
+ * @param path
+ * path to {@link Form} component
+ * @param fillBlankString
+ * specify whether fill all child
+ * {@link org.apache.wicket.markup.html.form.FormComponent}s
+ * with blankString initially.
+ * @return FormTester A FormTester instance for testing form
+ * @see FormTester
+ */
+ public FormTester newFormTester(String path, boolean fillBlankString)
+ {
+ return new FormTester(path, (Form)getComponentFromLastRenderedPage(path), this,
+ fillBlankString);
+ }
+
+ /**
* Render a panel defined in <code>TestPanelSource</code>. The usage is
* similar with {@link #startPage(ITestPageSource)}. Please note that
* testing panel must use supplied <code>panelId<code> as component id.
@@ -300,7 +333,7 @@
/**
* Render a panel from <code>Panel(String id)</code> constructor.
- *
+ *
* @param panelClass
* a test panel class with <code>Panel(String id)</code>
* constructor
@@ -353,7 +386,7 @@
/**
* Throw "standard" WicketRuntimeException
- *
+ *
* @param e
* @return RuntimeException
*/
@@ -366,7 +399,7 @@
* Gets the component with the given path from last rendered page. This
* method fails in case the component couldn't be found, and it will return
* null if the component was found, but is not visible.
- *
+ *
* @param path
* Path to component
* @return The component at the path
@@ -390,7 +423,7 @@
/**
* assert the text of <code>Label</code> component.
- *
+ *
* @param path
* path to <code>Label</code> component
* @param expectedLabelText
@@ -405,7 +438,7 @@
/**
* assert <code>PageLink</code> link to page class.
- *
+ *
* @param path
* path to <code>PageLink</code> component
* @param expectedPageClass
@@ -438,7 +471,7 @@
/**
* assert component class
- *
+ *
* @param path
* path to component
* @param expectedComponentClass
@@ -455,7 +488,7 @@
/**
* assert component visible.
- *
+ *
* @param path
* path to component
* @return
@@ -474,7 +507,7 @@
/**
* assert component invisible.
- *
+ *
* @param path
* path to component
* @return
@@ -486,7 +519,7 @@
/**
* assert the content of last rendered page contains(matches) regex pattern.
- *
+ *
* @param pattern
* reqex pattern to match
* @return
@@ -499,7 +532,7 @@
/**
* assert the model of {@link ListView} use expectedList
- *
+ *
* @param path
* path to {@link ListView} component
* @param expectedList
@@ -515,7 +548,7 @@
* Click the {@link Link} in the last rendered Page.
* <p>
* Simulate that AJAX is enabled.
- *
+ *
* @see WicketTester#clickLink(String, boolean)
* @param path
* Click the <code>Link</code> in the last rendered Page.
@@ -547,7 +580,7 @@
* on the client. This is done by setting the isAjax parameter to false. If
* you have an AjaxFallbackLink you can then check that it doesn't fail when
* invoked as a normal link.
- *
+ *
* @param path
* path to <code>Link</code> component
* @param isAjax
@@ -680,7 +713,7 @@
/**
* submit the <code>Form</code> in the last rendered Page.
- *
+ *
* @param path
* path to <code>Form</code> component
*/
@@ -694,7 +727,7 @@
* Sets a parameter for the component with the given path to be used with
* the next request. NOTE: this method only works when a page was rendered
* first.
- *
+ *
* @param componentPath
* path of the component
* @param value
@@ -727,10 +760,10 @@
/**
* assert last rendered Page class
- *
+ *
* FIXME explain why the code is so complicated to compare two classes, or
* simplify
- *
+ *
* @param expectedRenderedPageClass
* expected class of last renered page
* @return
@@ -756,7 +789,7 @@
* Use <code>-Dwicket.replace.expected.results=true</code> to
* automatically replace the expected output file.
* </p>
- *
+ *
* @param pageClass
* Used to load the file (relative to clazz package)
* @param filename
@@ -772,7 +805,7 @@
/**
* assert last rendered Page against an expected HTML document as a String
- *
+ *
* @param expectedDocument
* Expected output
* @return
@@ -787,7 +820,7 @@
/**
* assert no error feedback messages
- *
+ *
* @return
*/
public Result hasNoErrorMessage()
@@ -799,7 +832,7 @@
/**
* assert no info feedback messages
- *
+ *
* @return
*/
public Result hasNoInfoMessage()
@@ -811,7 +844,7 @@
/**
* get feedback messages
- *
+ *
* @param level
* level of feedback message, ex.
* <code>FeedbackMessage.DEBUG or FeedbackMessage.INFO.. etc</code>
@@ -857,7 +890,7 @@
/**
* Dump the component trees to log.
- *
+ *
* @param filter
* Show only the components, which path contains the
* filterstring.
@@ -884,7 +917,7 @@
* PLEASE NOTE! This method doesn't actually insert the component in the
* client DOM tree, using javascript. But it shouldn't be needed because you
* have to trust that the Wicket Ajax Javascript just works.
- *
+ *
* @param component
* The component to test whether it's on the response.
* @return
@@ -924,9 +957,9 @@
/**
* Simulate that an AJAX event has been fired.
- *
+ *
* @see #executeAjaxEvent(Component, String)
- *
+ *
* @since 1.2.3
* @param componentPath
* The component path.
@@ -943,7 +976,7 @@
/**
* Simulate that an AJAX event has been fired. You add an AJAX event to a
* component by using:
- *
+ *
* <pre>
* ...
* component.add(new AjaxEventBehavior("ondblclick") {
@@ -951,24 +984,24 @@
* });
* ...
* </pre>
- *
+ *
* You can then test that the code inside onEvent actually does what it's
* supposed to, using the WicketTester:
- *
+ *
* <pre>
* ...
* tester.executeAjaxEvent(component, "ondblclick");
* // Test that the code inside onEvent is correct.
* ...
* </pre>
- *
+ *
* This also works with AjaxFormSubmitBehavior, where it will "submit" the
* form before executing the command.
* <p>
* PLEASE NOTE! This method doesn't actually insert the component in the
* client DOM tree, using javascript.
- *
- *
+ *
+ *
* @param component
* The component which has the AjaxEventBehavior we wan't to
* test. If the component is null, the test will fail.
@@ -1029,7 +1062,7 @@
/**
* Get a TagTester based on a wicket:id. If more components exists with the
* same wicket:id in the markup only the first one is returned.
- *
+ *
* @param wicketId
* The wicket:id to search for.
* @return The TagTester for the tag which has the given wicket:id.
@@ -1043,7 +1076,7 @@
/**
* Get a TagTester based on an dom id. If more components exists with the
* same id in the markup only the first one is returned.
- *
+ *
* @param id
* The dom id to search for.
* @return The TagTester for the tag which has the given dom id.
@@ -1056,7 +1089,7 @@
/**
* Helper method for all the places where an AjaxCall should submit an
* associated form.
- *
+ *
* @param behavior
* The AjaxFormSubmitBehavior with the form to "submit"
*/
@@ -1096,7 +1129,7 @@
}
/**
- *
+ *
* @return
*/
public String getContentTypeFromResponseHeader()
@@ -1111,7 +1144,7 @@
}
/**
- *
+ *
* @return
*/
public int getContentLengthFromResponseHeader()
@@ -1126,7 +1159,7 @@
}
/**
- *
+ *
* @return
*/
public String getLastModifiedFromResponseHeader()
@@ -1136,7 +1169,7 @@
}
/**
- *
+ *
* @return
*/
public String getContentDispositionFromResponseHeader()
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java?view=diff&rev=548635&r1=548634&r2=548635
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/FormTester.java Tue Jun 19 00:51:20 2007
@@ -324,8 +324,8 @@
/** path to form component */
private final String path;
- /** wicketTester that create FormTester */
- private final WicketTester wicketTester;
+ /** baseWicketTester that create FormTester */
+ private final BaseWicketTester baseWicketTester;
/** form component to be test */
private Form workingForm;
@@ -344,12 +344,12 @@
* String
*/
protected FormTester(final String path, final Form workingForm,
- final WicketTester wicketTester, final boolean fillBlankString)
+ final BaseWicketTester wicketTester, final boolean fillBlankString)
{
this.path = path;
this.workingForm = workingForm;
- this.wicketTester = wicketTester;
- this.wicketTester.setupRequestAndResponse();
+ this.baseWicketTester = wicketTester;
+ this.baseWicketTester.setupRequestAndResponse();
// fill blank String for Text Component.
workingForm.visitFormComponents(new FormComponent.AbstractVisitor()
@@ -538,7 +538,7 @@
+ "component of this type.");
}
- MockHttpServletRequest servletRequest = wicketTester.getServletRequest();
+ MockHttpServletRequest servletRequest = baseWicketTester.getServletRequest();
servletRequest.addFile(formComponent.getInputName(), file, contentType);
}
@@ -550,8 +550,8 @@
checkClosed();
try
{
- MockHttpServletRequest servletRequest = wicketTester.getServletRequest();
- WebRequestCycle requestCycle = wicketTester.createRequestCycle();
+ MockHttpServletRequest servletRequest = baseWicketTester.getServletRequest();
+ WebRequestCycle requestCycle = baseWicketTester.createRequestCycle();
servletRequest.setRequestToComponent(workingForm);
if (servletRequest.hasUploadedFiles())
@@ -560,7 +560,7 @@
.getMaxSize()));
}
- wicketTester.processRequestCycle(requestCycle);
+ baseWicketTester.processRequestCycle(requestCycle);
}
catch (FileUploadException e)
{
@@ -603,14 +603,14 @@
{
if (parameterExist(formComponent))
{
- String[] values = wicketTester.getServletRequest().getParameterValues(
+ String[] values = baseWicketTester.getServletRequest().getParameterValues(
formComponent.getInputName());
// remove duplicated
HashSet all = new HashSet(Arrays.asList(values));
all.add(value);
Map newParameters = new HashMap();
newParameters.put(formComponent.getInputName(), all.toArray(new String[all.size()]));
- wicketTester.getServletRequest().setParameters(newParameters);
+ baseWicketTester.getServletRequest().setParameters(newParameters);
}
else
{
@@ -639,7 +639,7 @@
*/
private boolean parameterExist(FormComponent formComponent)
{
- String parameter = wicketTester.getServletRequest().getParameter(
+ String parameter = baseWicketTester.getServletRequest().getParameter(
formComponent.getInputName());
return parameter != null && parameter.trim().length() > 0;
}
@@ -653,7 +653,7 @@
*/
private void setFormComponentValue(FormComponent formComponent, String value)
{
- wicketTester.getServletRequest().setParameter(formComponent.getInputName(), value);
+ baseWicketTester.getServletRequest().setParameter(formComponent.getInputName(), value);
}
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java?view=diff&rev=548635&r1=548634&r2=548635
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java Tue Jun 19 00:51:20 2007
@@ -30,7 +30,6 @@
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.protocol.http.MockHttpServletResponse;
import org.apache.wicket.protocol.http.UnitTestSettings;
@@ -44,7 +43,7 @@
/**
* A helper to ease unit testing of Wicket applications without the need for a
* servlet container. To start a test, either use startPage() or startPanel():
- *
+ *
* <pre>
* // production page
* public class MyPage extends WebPage
@@ -62,16 +61,16 @@
* }
* }
* </pre>
- *
+ *
* <pre>
* // test code
* private WicketTester tester;
- *
+ *
* public void setUp()
* {
* tester = new WicketTester();
* }
- *
+ *
* public void testRenderMyPage()
* {
* //start and render the test page
@@ -82,10 +81,10 @@
* tester.assertLabel("myMessage", "Hello!");
* }
* </pre>
- *
+ *
* Above example is straight forward: start MyPage.class and assert Label it
* rendered. Next, we try to navigate through link:
- *
+ *
* <pre>
* // production page
* public class YourPage extends WebPage
@@ -96,7 +95,7 @@
* info("Wicket Rocks ;-)");
* }
* }
- *
+ *
* //test code
* public void testLinkToYourPage()
* {
@@ -107,12 +106,12 @@
* tester.assertLabel("yourMessage", "Hi!");
* }
* </pre>
- *
+ *
* <code>tester.clickLink(path);</code> will simulate user click on the
* component (in this case, it's a <code>Link</code>) and render the response
* page <code>YourPage</code>. Ok, unit test of <code>MyPage</code> is
* completed. Now we test <code>YourPage</code> standalone:
- *
+ *
* <pre>
* //test code
* public void testRenderYourPage()
@@ -131,7 +130,7 @@
* tester.assertInfoMessages(new String[] { "Wicket Rocks ;-)" });
* }
* </pre>
- *
+ *
* Instead of <code>tester.startPage(pageClass)</code>, we define a
* {@link org.apache.wicket.util.tester.ITestPageSource} to provide testing page
* instance for WicketTester. This is necessary because <code>YourPage</code>
@@ -139,9 +138,9 @@
* but can not be instantiated by reflection. Finally, we use
* <code>assertInfoMessages</code> to assert there is a feedback message
* "Wicket Rocks ;-)" in INFO level.
- *
+ *
* TODO General: Example usage of FormTester
- *
+ *
* @author Ingram Chen
* @author Juergen Donnerstag
* @author Frank Bille
@@ -170,7 +169,7 @@
{
return new WebResponse(servletResponse);
}
-
+
protected void outputDevelopmentModeWarning()
{
// do nothing
@@ -188,7 +187,7 @@
/**
* Create WicketTester and automatically create a WebApplication.
- *
+ *
* @param homePage
*/
public WicketTester(final Class homePage)
@@ -207,7 +206,7 @@
{
return new WebResponse(servletResponse);
}
-
+
protected void outputDevelopmentModeWarning()
{
// Do nothing.
@@ -217,7 +216,7 @@
/**
* Create WicketTester
- *
+ *
* @param application
* The wicket tester object
*/
@@ -228,13 +227,13 @@
/**
* Create WicketTester to help unit testing
- *
+ *
* @param application
* The wicket tester object
* @param path
* The absolute path on disk to the web application contents
* (e.g. war root) - may be null
- *
+ *
* @see org.apache.wicket.protocol.http.MockWebApplication#MockWebApplication(String)
*/
public WicketTester(final WebApplication application, final String path)
@@ -249,7 +248,7 @@
/**
* assert the text of <code>Label</code> component.
- *
+ *
* @param path
* path to <code>Label</code> component
* @param expectedLabelText
@@ -263,7 +262,7 @@
/**
* assert <code>PageLink</code> link to page class.
- *
+ *
* @param path
* path to <code>PageLink</code> component
* @param expectedPageClass
@@ -276,7 +275,7 @@
/**
* assert component class
- *
+ *
* @param path
* path to component
* @param expectedComponentClass
@@ -289,7 +288,7 @@
/**
* assert component visible.
- *
+ *
* @param path
* path to component
*/
@@ -300,7 +299,7 @@
/**
* assert component invisible.
- *
+ *
* @param path
* path to component
*/
@@ -311,7 +310,7 @@
/**
* assert the content of last rendered page contains(matches) regex pattern.
- *
+ *
* @param pattern
* reqex pattern to match
*/
@@ -322,7 +321,7 @@
/**
* assert the model of {@link ListView} use expectedList
- *
+ *
* @param path
* path to {@link ListView} component
* @param expectedList
@@ -335,41 +334,8 @@
}
/**
- * create a {@link FormTester} for the form at path, and fill all child
- * {@link org.apache.wicket.markup.html.form.FormComponent}s with blank
- * String initially.
- *
- * @param path
- * path to {@link Form} component
- * @return FormTester A FormTester instance for testing form
- * @see #newFormTester(String, boolean)
- */
- public FormTester newFormTester(String path)
- {
- return newFormTester(path, true);
- }
-
- /**
- * create a {@link FormTester} for the form at path.
- *
- * @param path
- * path to {@link Form} component
- * @param fillBlankString
- * specify whether fill all child
- * {@link org.apache.wicket.markup.html.form.FormComponent}s
- * with blankString initially.
- * @return FormTester A FormTester instance for testing form
- * @see FormTester
- */
- public FormTester newFormTester(String path, boolean fillBlankString)
- {
- return new FormTester(path, (Form)getComponentFromLastRenderedPage(path), this,
- fillBlankString);
- }
-
- /**
* assert last rendered Page class
- *
+ *
* @param expectedRenderedPageClass
* expected class of last renered page
*/
@@ -384,7 +350,7 @@
* Use <code>-Dwicket.replace.expected.results=true</code> to
* automatically replace the expected output file.
* </p>
- *
+ *
* @param clazz
* Used to load the file (relative to clazz package)
* @param filename
@@ -400,7 +366,7 @@
/**
* assert last rendered Page against an expected HTML document as a String
- *
+ *
* @param expectedDocument
* Expected output
* @throws Exception
@@ -434,7 +400,7 @@
/**
* assert error feedback messages
- *
+ *
* @param expectedErrorMessages
* expected error messages
*/
@@ -451,7 +417,7 @@
/**
* assert info feedback message
- *
+ *
* @param expectedInfoMessages
* expected info messages
*/
@@ -460,7 +426,7 @@
List actualMessages = getMessages(FeedbackMessage.INFO);
WicketTesterHelper.assertEquals(Arrays.asList(expectedInfoMessages), actualMessages);
}
-
+
/**
* Test that a component has been added to a AjaxRequestTarget, using
* {@link AjaxRequestTarget#addComponent(Component)}. This method actually
@@ -469,7 +435,7 @@
* PLEASE NOTE! This method doesn't actually insert the component in the
* client DOM tree, using javascript. But it shouldn't be needed because you
* have to trust that the Wicket Ajax Javascript just works.
- *
+ *
* @param componentPath
* The component path to the component to test whether it's on
* the response.
@@ -487,7 +453,7 @@
* PLEASE NOTE! This method doesn't actually insert the component in the
* client DOM tree, using javascript. But it shouldn't be needed because you
* have to trust that the Wicket Ajax Javascript just works.
- *
+ *
* @param component
* The component to test whether it's on the response.
*/
@@ -515,14 +481,14 @@
{
throw new AssertionFailedError("Location header should *not* be present when using Ajax");
}
-
+
String ajaxLocation = ((MockHttpServletResponse)getWicketResponse()
.getHttpServletResponse()).getHeader("Ajax-Location");
if (null == ajaxLocation)
{
throw new AssertionFailedError("Ajax-Location header should be present when using Ajax");
}
-
+
int statusCode = ((MockHttpServletResponse)getWicketResponse()
.getHttpServletResponse()).getStatus();
if (statusCode != 200)