You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/10/14 23:31:35 UTC

svn commit: r584613 [2/2] - /wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java?rev=584613&r1=584612&r2=584613&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTester.java Sun Oct 14 14:31:34 2007
@@ -46,20 +46,17 @@
 
 
 /**
- * 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():
+ * A helper class to ease unit testing of Wicket applications without the need
+ * for a servlet container. To start a test, either use <code>startPage</code>
+ * or <code>startPanel</code>:
  * 
  * <pre>
  * // production page
- * public class MyPage extends WebPage
- * {
- * 	public MyPage()
- * 	{
+ * public class MyPage extends WebPage {
+ * 	public MyPage() {
  * 		add(new Label(&quot;myMessage&quot;, &quot;Hello!&quot;));
- * 		add(new Link(&quot;toYourPage&quot;)
- * 		{
- * 			public void onClick()
- * 			{
+ * 		add(new Link(&quot;toYourPage&quot;) {
+ * 			public void onClick() {
  * 				setResponsePage(new YourPage(&quot;Hi!&quot;));
  * 			}
  * 		});
@@ -71,13 +68,11 @@
  * // test code
  * private WicketTester tester;
  * 
- * public void setUp()
- * {
+ * public void setUp() {
  * 	tester = new WicketTester();
  * }
  * 
- * public void testRenderMyPage()
- * {
+ * public void testRenderMyPage() {
  * 	//start and render the test page
  * 	tester.startPage(MyPage.class);
  * 	//assert rendered page class
@@ -87,23 +82,21 @@
  * }
  * </pre>
  * 
- * Above example is straight forward: start MyPage.class and assert Label it
- * rendered. Next, we try to navigate through link:
+ * The above example is straight forward: start <code>MyPage.class</code> and
+ * assert <code>Label</code> it rendered. Next, we try to navigate through a
+ * <code>Link</code>:
  * 
  * <pre>
  * // production page
- * public class YourPage extends WebPage
- * {
- * 	public YourPage(String message)
- * 	{
+ * public class YourPage extends WebPage {
+ * 	public YourPage(String message) {
  * 		add(new Label(&quot;yourMessage&quot;, message));
  * 		info(&quot;Wicket Rocks ;-)&quot;);
  * 	}
  * }
  * 
  * //test code
- * public void testLinkToYourPage()
- * {
+ * public void testLinkToYourPage() {
  * 	tester.startPage(MyPage.class);
  * 	//click link and render
  * 	tester.clickLink(&quot;toYourPage&quot;);
@@ -119,13 +112,10 @@
  * 
  * <pre>
  * //test code
- * public void testRenderYourPage()
- * {
+ * public void testRenderYourPage() {
  * 	// provide page instance source for WicketTester
- * 	tester.startPage(new TestPageSource()
- * 	{
- * 		public Page getTestPage()
- * 		{
+ * 	tester.startPage(new TestPageSource() {
+ * 		public Page getTestPage() {
  * 			return new YourPage(&quot;mock message&quot;);
  * 		}
  * 	});
@@ -138,23 +128,24 @@
  * 
  * 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>
- * uses a custom constructor, which is very common for transferring model data,
- * 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.
+ * instance for <code>WicketTester</code>. This is necessary because
+ * <code>YourPage</code> uses a custom constructor, which is very common for
+ * transferring model data, but cannot be instantiated by reflection. Finally,
+ * we use <code>assertInfoMessages</code> to assert there is a feedback
+ * message "Wicket Rocks ;-)" at the INFO level.
  * 
  * TODO General: Example usage of FormTester
  * 
  * @author Ingram Chen
  * @author Juergen Donnerstag
  * @author Frank Bille
+ * @since 1.2.6
  */
 public class WicketTester extends BaseWicketTester
 {
 	/**
 	 * Default dummy web application for testing. Uses {@link HttpSessionStore}
-	 * to store pages and the session.
+	 * to store pages and the <code>Session</code>.
 	 */
 	public static class DummyWebApplication extends WebApplication
 	{
@@ -237,8 +228,8 @@
 	private static final Logger log = LoggerFactory.getLogger(WicketTester.class);
 
 	/**
-	 * Create WicketTester and automatically create a WebApplication, but the
-	 * tester will have no home page.
+	 * Creates a <code>WicketTester</code> and automatically creates a
+	 * <code>WebApplication</code>, but the tester will have no home page.
 	 */
 	public WicketTester()
 	{
@@ -246,9 +237,11 @@
 	}
 
 	/**
-	 * Create WicketTester and automatically create a WebApplication.
+	 * Creates a <code>WicketTester</code> and automatically creates a
+	 * <code>WebApplication</code>.
 	 * 
 	 * @param homePage
+	 *            a home page <code>Class</code>
 	 */
 	public WicketTester(final Class homePage)
 	{
@@ -282,10 +275,11 @@
 	}
 
 	/**
-	 * Create WicketTester
+	 * Creates a <code>WicketTester</code>.
 	 * 
 	 * @param application
-	 *            The wicket tester object
+	 *            a <code>WicketTester</code> <code>WebApplication</code>
+	 *            object
 	 */
 	public WicketTester(final WebApplication application)
 	{
@@ -293,16 +287,17 @@
 	}
 
 	/**
-	 * Create WicketTester to help unit testing
+	 * Creates a <code>WicketTester</code> to help unit testing.
 	 * 
 	 * @param application
-	 *            The wicket tester object
+	 *            a <code>WicketTester</code> <code>WebApplication</code>
+	 *            object
 	 * @param path
-	 *            The absolute path on disk to the web application contents
-	 *            (e.g. war root) - may be null
+	 *            the absolute path on disk to the web application's contents
+	 *            (e.g. war root) - may be <code>null</code>
 	 * 
 	 * @see org.apache.wicket.protocol.http.MockWebApplication#MockWebApplication(
-			org.apache.wicket.protocol.http.WebApplication, String)
+	 *      org.apache.wicket.protocol.http.WebApplication, String)
 	 */
 	public WicketTester(final WebApplication application, final String path)
 	{
@@ -315,7 +310,7 @@
 
 
 	/**
-	 * Assert that the ajax location header is present
+	 * Asserts that the Ajax location header is present.
 	 */
 	public void assertAjaxLocation()
 	{
@@ -342,12 +337,12 @@
 	}
 
 	/**
-	 * assert component class
+	 * Asserts a <code>Component</code> class.
 	 * 
 	 * @param path
-	 *            path to component
+	 *            path to <code>Component</code>
 	 * @param expectedComponentClass
-	 *            expected component class
+	 *            expected <code>Component</code> class
 	 */
 	public void assertComponent(String path, Class expectedComponentClass)
 	{
@@ -355,16 +350,19 @@
 	}
 
 	/**
-	 * Test that a component has been added to a AjaxRequestTarget, using
+	 * Tests that a <code>Component</code> has been added to a
+	 * <code>AjaxRequestTarget</code>, using
 	 * {@link AjaxRequestTarget#addComponent(Component)}. This method actually
-	 * tests that a component is on the AJAX response sent back to the client.
+	 * tests that a <code>Component</code> is on the Ajax response sent back
+	 * to the client.
 	 * <p>
-	 * 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.
+	 * PLEASE NOTE! This method doesn't actually insert the
+	 * <code>Component</code> in the client DOM tree, using Javascript. But it
+	 * shouldn't be needed because you just have to trust that Wicket Ajax
+	 * Javascript works.
 	 * 
 	 * @param component
-	 *            The component to test whether it's on the response.
+	 *            a <code>Component</code> to be tested
 	 */
 	public void assertComponentOnAjaxResponse(Component component)
 	{
@@ -373,17 +371,19 @@
 	}
 
 	/**
-	 * Test that a component has been added to a AjaxRequestTarget, using
+	 * Tests that a <code>Component</code> has been added to a
+	 * <code>AjaxRequestTarget</code>, using
 	 * {@link AjaxRequestTarget#addComponent(Component)}. This method actually
-	 * tests that a component is on the AJAX response sent back to the client.
+	 * tests that a <code>Component</code> is on the Ajax response sent back
+	 * to the client.
 	 * <p>
-	 * 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.
+	 * PLEASE NOTE! This method doesn't actually insert the
+	 * <code>Component</code> in the client DOM tree, using Javascript. But it
+	 * shouldn't be needed because you just have to trust that Wicket Ajax
+	 * Javascript works.
 	 * 
 	 * @param componentPath
-	 *            The component path to the component to test whether it's on
-	 *            the response.
+	 *            a <code>Component</code> path to test
 	 */
 	public void assertComponentOnAjaxResponse(String componentPath)
 	{
@@ -391,10 +391,11 @@
 	}
 
 	/**
-	 * assert the content of last rendered page contains(matches) regex pattern.
+	 * Asserts the content of last rendered page contains (matches) a given
+	 * regex pattern.
 	 * 
 	 * @param pattern
-	 *            reqex pattern to match
+	 *            a reqex pattern to match
 	 */
 	public void assertContains(String pattern)
 	{
@@ -402,7 +403,7 @@
 	}
 
 	/**
-	 * assert error feedback messages
+	 * Asserts error-level feedback messages.
 	 * 
 	 * @param expectedErrorMessages
 	 *            expected error messages
@@ -419,7 +420,7 @@
 	}
 
 	/**
-	 * assert info feedback message
+	 * Assert info-level feedback messages.
 	 * 
 	 * @param expectedInfoMessages
 	 *            expected info messages
@@ -431,10 +432,10 @@
 	}
 
 	/**
-	 * assert component invisible.
+	 * Asserts that a <code>Component</code> is invisible.
 	 * 
 	 * @param path
-	 *            path to component
+	 *            path to <code>Component</code>
 	 */
 	public void assertInvisible(String path)
 	{
@@ -442,12 +443,12 @@
 	}
 
 	/**
-	 * assert the text of <code>Label</code> component.
+	 * Asserts the text of a <code>Label</code> <code>Component</code>.
 	 * 
 	 * @param path
-	 *            path to <code>Label</code> component
+	 *            path to <code>Label</code> <code>Component</code>
 	 * @param expectedLabelText
-	 *            expected label text
+	 *            expected text of the <code>Label</code>
 	 */
 	public void assertLabel(String path, String expectedLabelText)
 	{
@@ -456,12 +457,13 @@
 	}
 
 	/**
-	 * assert the model of {@link ListView} use expectedList
+	 * Asserts the model of a {@link ListView}.
 	 * 
 	 * @param path
-	 *            path to {@link ListView} component
+	 *            path to a {@link ListView} <code>Component</code>
 	 * @param expectedList
-	 *            expected list in the model of {@link ListView}
+	 *            expected <code>List</code> in the model of the given
+	 *            {@link ListView}
 	 */
 	public void assertListView(String path, List expectedList)
 	{
@@ -470,7 +472,7 @@
 	}
 
 	/**
-	 * assert no error feedback messages
+	 * Asserts no error-level feedback messages.
 	 */
 	public void assertNoErrorMessage()
 	{
@@ -480,7 +482,7 @@
 	}
 
 	/**
-	 * assert no info feedback messages
+	 * Asserts no info-level feedback messages.
 	 */
 	public void assertNoInfoMessage()
 	{
@@ -490,12 +492,12 @@
 	}
 
 	/**
-	 * assert <code>PageLink</code> link to page class.
+	 * Asserts a <code>PageLink</code> link to a <code>Page</code> class.
 	 * 
 	 * @param path
-	 *            path to <code>PageLink</code> component
+	 *            path to <code>PageLink</code> <code>Component</code>
 	 * @param expectedPageClass
-	 *            expected page class to link
+	 *            expected <code>Page</code> class to link
 	 */
 	public void assertPageLink(String path, Class expectedPageClass)
 	{
@@ -503,10 +505,10 @@
 	}
 
 	/**
-	 * assert last rendered Page class
+	 * Asserts a last-rendered <code>Page</code> class.
 	 * 
 	 * @param expectedRenderedPageClass
-	 *            expected class of last renered page
+	 *            expected class of last rendered <code>Page</code>
 	 */
 	public void assertRenderedPage(Class expectedRenderedPageClass)
 	{
@@ -514,16 +516,17 @@
 	}
 
 	/**
-	 * Assert last rendered Page against an expected HTML document
+	 * Asserts last-rendered <code>Page</code> against an expected HTML
+	 * document.
 	 * <p>
 	 * 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)
+	 *            <code>Class</code> used to load the file (relative to
+	 *            <code>clazz</code> package)
 	 * @param filename
-	 *            Expected output
+	 *            expected output filename <code>String</code>
 	 * @throws Exception
 	 */
 	public void assertResultPage(final Class clazz, final String filename) throws Exception
@@ -534,10 +537,11 @@
 	}
 
 	/**
-	 * assert last rendered Page against an expected HTML document as a String
+	 * Asserts last-rendered <code>Page</code> against an expected HTML
+	 * document as a <code>String</code>
 	 * 
 	 * @param expectedDocument
-	 *            Expected output
+	 *            expected output <code>String</code>
 	 * @throws Exception
 	 */
 	public void assertResultPage(final String expectedDocument) throws Exception
@@ -548,10 +552,10 @@
 	}
 
 	/**
-	 * assert component visible.
+	 * Asserts that a <code>Component</code> is visible.
 	 * 
 	 * @param path
-	 *            path to component
+	 *            path to a <code>Component</code>
 	 */
 	public void assertVisible(String path)
 	{

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java?rev=584613&r1=584612&r2=584613&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/WicketTesterHelper.java Sun Oct 14 14:31:34 2007
@@ -30,14 +30,18 @@
 import org.apache.wicket.util.string.Strings;
 
 /**
- * A WicketTester specific helper class
+ * A <code>WicketTester</code>-specific helper class.
  * 
  * @author Ingram Chen
+ * @since 1.2.6
  */
 public class WicketTesterHelper
 {
 	/**
+	 * <code>ComponentData</code> class.
 	 * 
+	 * @author Ingram Chen
+	 * @since 1.2.6
 	 */
 	public static class ComponentData implements IClusterable
 	{
@@ -54,11 +58,13 @@
 	}
 
 	/**
-	 * Get recursively all components of the page, extract the information
-	 * relevant for us and add them to a list.
+	 * Gets recursively all <code>Component</code>s of a given
+	 * <code>Page</code>, extracts the information relevant to us, and adds
+	 * them to a <code>List</code>.
 	 * 
 	 * @param page
-	 * @return List of component data objects
+	 *            the <code>Page</code> to analyze
+	 * @return a <code>List</code> of <code>Component</code> data objects
 	 */
 	public static List getComponentData(final Page page)
 	{
@@ -102,10 +108,12 @@
 	}
 
 	/**
-	 * Assert both collections contain the same elements
+	 * Asserts that both <code>Collection</code>s contain the same elements.
 	 * 
 	 * @param expects
+	 *            a <code>Collection</code> object
 	 * @param actuals
+	 *            a <code>Collection</code> object
 	 */
 	public static void assertEquals(final Collection expects, final Collection actuals)
 	{
@@ -116,10 +124,12 @@
 	}
 
 	/**
-	 * Fail with a verbose error message
+	 * Fails with a verbose error message.
 	 * 
 	 * @param expects
+	 *            a <code>Collection</code> object
 	 * @param actuals
+	 *            a <code>Collection</code> object
 	 */
 	public static void failWithVerboseMessage(final Collection expects, final Collection actuals)
 	{
@@ -128,10 +138,12 @@
 	}
 
 	/**
-	 * toString() for the collection provided.
+	 * A <code>toString</code> method for the given <code>Collection</code>.
 	 * 
 	 * @param objects
-	 * @return String
+	 *            a <code>Collection</code> object
+	 * @return a <code>String</code> representation of the
+	 *         <code>Collection</code>
 	 */
 	public static String asLined(final Collection objects)
 	{

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/package.html
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/package.html?rev=584613&r1=584612&r2=584613&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/package.html (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/tester/package.html Sun Oct 14 14:31:34 2007
@@ -16,16 +16,21 @@
 -->
 <!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 3.2 Final//NL">
 <html>
-<head>
-<title>WicketTester package</title>
-</head>
-<body>
-<p>
-A package with utility classes to ease unit testing of Wicket applications without the need for 
-a servlet container. The only classes required by users to test are WicketTester and FormTester. 
-WicketTester extends MockWebApplication and extends it with convinience methods to start (render)
-a page and to test (assert) certain conditions.<p>
-FormTester is a utility class to make unit testing a HTML form a breeze.
-</p>
-</body>
+	<head>
+		<title>
+			org.apache.wicket.util.tester package
+		</title>
+	</head>
+	<body>
+		<p>
+			A package with utility classes to ease unit testing of Wicket applications without the need for 
+			a servlet container. The only classes required by users to test are <code>WicketTester</code> 
+			and <code>FormTester</code>. <code>WicketTester</code> extends <code>MockWebApplication</code> 
+			and extends it with convenience methods to start (render) a page and to test (assert) 
+			certain conditions.
+		</p>
+		<p>
+			<code>FormTester</code> is a utility class to make unit testing an HTML form a breeze.
+		</p>
+	</body>
 </html>