You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2013/12/15 21:24:14 UTC
svn commit: r1551048 [1/3] - in /wicket/common/site/trunk/_site/guide: gapi/
gapi/DefaultPackage/ gapi/spring/ guide/ guide/pages/
guide/src/docs/guide/chapter19/ guide/src/docs/guide/chapter20/
guide/src/docs/guide/chapter22/
Author: adelbene
Date: Sun Dec 15 20:24:13 2013
New Revision: 1551048
URL: http://svn.apache.org/r1551048
Log:
Additional spell-check
Modified:
wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/BootStrap.html
wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/UrlMappings.html
wicket/common/site/trunk/_site/guide/gapi/deprecated-list.html
wicket/common/site/trunk/_site/guide/gapi/help-doc.html
wicket/common/site/trunk/_site/guide/gapi/index-all.html
wicket/common/site/trunk/_site/guide/gapi/spring/resources.html
wicket/common/site/trunk/_site/guide/guide/chapter18.html
wicket/common/site/trunk/_site/guide/guide/chapter19.html
wicket/common/site/trunk/_site/guide/guide/chapter20.html
wicket/common/site/trunk/_site/guide/guide/chapter22.html
wicket/common/site/trunk/_site/guide/guide/pages/chapter18_1.html
wicket/common/site/trunk/_site/guide/guide/pages/chapter19_1.html
wicket/common/site/trunk/_site/guide/guide/pages/chapter20_1.html
wicket/common/site/trunk/_site/guide/guide/pages/chapter20_2.html
wicket/common/site/trunk/_site/guide/guide/pages/chapter20_3.html
wicket/common/site/trunk/_site/guide/guide/pages/chapter20_4.html
wicket/common/site/trunk/_site/guide/guide/pages/chapter22_8.html
wicket/common/site/trunk/_site/guide/guide/single.html
wicket/common/site/trunk/_site/guide/guide/single.pdf
wicket/common/site/trunk/_site/guide/guide/src/docs/guide/chapter19/chapter19_1.gdoc
wicket/common/site/trunk/_site/guide/guide/src/docs/guide/chapter20/chapter20_1.gdoc
wicket/common/site/trunk/_site/guide/guide/src/docs/guide/chapter20/chapter20_2.gdoc
wicket/common/site/trunk/_site/guide/guide/src/docs/guide/chapter20/chapter20_3.gdoc
wicket/common/site/trunk/_site/guide/guide/src/docs/guide/chapter20/chapter20_4.gdoc
wicket/common/site/trunk/_site/guide/guide/src/docs/guide/chapter22/chapter22_8.gdoc
Modified: wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/BootStrap.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/BootStrap.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/BootStrap.html (original)
+++ wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/BootStrap.html Sun Dec 15 20:24:13 2013
@@ -6,9 +6,9 @@
<html>
<head>
-<!-- Generated by groovydoc (2.0.8) on Sat Dec 14 22:03:19 CET 2013 -->
+<!-- Generated by groovydoc (2.0.8) on Sun Dec 15 21:20:27 CET 2013 -->
<title>BootStrap (Groovy Documentation)</title>
-<meta name="date" content="2013-12-14">
+<meta name="date" content="2013-12-15">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../groovy.ico" type="image/x-icon" rel="shortcut icon">
<link href="../groovy.ico" type="image/x-icon" rel="icon">
Modified: wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/UrlMappings.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/UrlMappings.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/UrlMappings.html (original)
+++ wicket/common/site/trunk/_site/guide/gapi/DefaultPackage/UrlMappings.html Sun Dec 15 20:24:13 2013
@@ -6,9 +6,9 @@
<html>
<head>
-<!-- Generated by groovydoc (2.0.8) on Sat Dec 14 22:03:19 CET 2013 -->
+<!-- Generated by groovydoc (2.0.8) on Sun Dec 15 21:20:27 CET 2013 -->
<title>UrlMappings (Groovy Documentation)</title>
-<meta name="date" content="2013-12-14">
+<meta name="date" content="2013-12-15">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../groovy.ico" type="image/x-icon" rel="shortcut icon">
<link href="../groovy.ico" type="image/x-icon" rel="icon">
Modified: wicket/common/site/trunk/_site/guide/gapi/deprecated-list.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/gapi/deprecated-list.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/gapi/deprecated-list.html (original)
+++ wicket/common/site/trunk/_site/guide/gapi/deprecated-list.html Sun Dec 15 20:24:13 2013
@@ -4,7 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Generated by groovydoc (2.0.8) on -->
<title>Deprecated API (wicket-userguide)</title>
-<meta name="date" content="2013-12-14">
+<meta name="date" content="2013-12-15">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link href="groovy.ico" type="image/x-icon" rel="shortcut icon">
<link href="groovy.ico" type="image/x-icon" rel="icon">
Modified: wicket/common/site/trunk/_site/guide/gapi/help-doc.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/gapi/help-doc.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/gapi/help-doc.html (original)
+++ wicket/common/site/trunk/_site/guide/gapi/help-doc.html Sun Dec 15 20:24:13 2013
@@ -7,7 +7,7 @@
<title>API Help (wicket-userguide)</title>
<link href="groovy.ico" type="image/x-icon" rel="shortcut icon">
<link href="groovy.ico" type="image/x-icon" rel="icon">
-<meta name="date" content="2013-12-14">
+<meta name="date" content="2013-12-15">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript">
Modified: wicket/common/site/trunk/_site/guide/gapi/index-all.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/gapi/index-all.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/gapi/index-all.html (original)
+++ wicket/common/site/trunk/_site/guide/gapi/index-all.html Sun Dec 15 20:24:13 2013
@@ -4,7 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Generated by groovydoc (2.0.8) on -->
<title>Index (wicket-userguide)</title>
-<meta name="date" content="2013-12-14">
+<meta name="date" content="2013-12-15">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link href="groovy.ico" type="image/x-icon" rel="shortcut icon">
<link href="groovy.ico" type="image/x-icon" rel="icon">
Modified: wicket/common/site/trunk/_site/guide/gapi/spring/resources.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/gapi/spring/resources.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/gapi/spring/resources.html (original)
+++ wicket/common/site/trunk/_site/guide/gapi/spring/resources.html Sun Dec 15 20:24:13 2013
@@ -6,9 +6,9 @@
<html>
<head>
-<!-- Generated by groovydoc (2.0.8) on Sat Dec 14 22:03:19 CET 2013 -->
+<!-- Generated by groovydoc (2.0.8) on Sun Dec 15 21:20:27 CET 2013 -->
<title>resources (Groovy Documentation)</title>
-<meta name="date" content="2013-12-14">
+<meta name="date" content="2013-12-15">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../groovy.ico" type="image/x-icon" rel="shortcut icon">
<link href="../groovy.ico" type="image/x-icon" rel="icon">
Modified: wicket/common/site/trunk/_site/guide/guide/chapter18.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/guide/chapter18.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/guide/chapter18.html (original)
+++ wicket/common/site/trunk/_site/guide/guide/chapter18.html Sun Dec 15 20:24:13 2013
@@ -189,7 +189,7 @@ Writing a web application is not just ab
}</pre></div><p class="paragraph"/>In this example the object that we want to inject is a simple class containing a greeting message:<p class="paragraph"/><div class="code"><pre>@ManagedBean
<span class="java-keyword">public</span> class EnterpriseMessage {
<span class="java-keyword">public</span> <span class="java-object">String</span> message = <span class="java-quote">"Welcome to the EJB world!"</span>;
-}</pre></div><p class="paragraph"/>Please note that we have used annotation <code>ManagedBean to decorate our object. Now to inject it into the home page we must add a field of type EnterpriseMessage and annotate it with annotation </code>EJB:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {<p class="paragraph"/> @EJB
+}</pre></div><p class="paragraph"/>Please note that we have used annotation ManagedBean to decorate our object. Now to inject it into the home page we must add a field of type EnterpriseMessage and annotate it with annotation @EJB:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {<p class="paragraph"/> @EJB
<span class="java-keyword">private</span> EnterpriseMessage enterpriseMessage;
//getter and setter <span class="java-keyword">for</span> enterpriseMessage...<p class="paragraph"/> <span class="java-keyword">public</span> HomePage(<span class="java-keyword">final</span> PageParameters parameters) {
<span class="java-keyword">super</span>(parameters);<p class="paragraph"/> add(<span class="java-keyword">new</span> Label(<span class="java-quote">"message"</span>, enterpriseMessage.message));
Modified: wicket/common/site/trunk/_site/guide/guide/chapter19.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/guide/chapter19.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/guide/chapter19.html (original)
+++ wicket/common/site/trunk/_site/guide/guide/chapter19.html Sun Dec 15 20:24:13 2013
@@ -253,7 +253,7 @@ Remember that signOut does not discard a
<span class="java-keyword">protected</span> <span class="java-object">Class</span><? <span class="java-keyword">extends</span> WebPage> getSignInPageClass() {
<span class="java-keyword">return</span> SignInPage.class;
}
-}</pre></div><p class="paragraph"/>The authentication logic inside authenticate has been kept quite trivial in order to make the code as clean as possible. Please note also that session class must have a constructor that accepts an instance of class <code>Request</code>.<p class="paragraph"/><h3>Redirecting user to an intermediate page</h3><p class="paragraph"/>Method <code>restartResponseAtSignInPage</code> is an example of redirecting user to an intermediate page before allowing him to access to the requested page. This method internally throws exception <code>org.apache.wicket.RestartResponseAtInterceptPageException</code> which saves the URL of the requested page into session metadata and then redirects user to the page passed as constructor parameter (the sign in page).<p class="paragraph"/>Component's method <code>redirectToInterceptPage(Page)</code> works in much the same way as <code>restartResponseAtSignInPage</code> but it allows us to specify which page to use as int
ermediate page:<p class="paragraph"/><code>redirectToInterceptPage(intermediatePage);</code><p class="paragraph"/><blockquote class="note">
+}</pre></div><p class="paragraph"/>The authentication logic inside authenticate has been kept quite trivial in order to make the code as clean as possible. Please note also that session class must have a constructor that accepts an instance of class <code>Request</code>.<p class="paragraph"/><h3>Redirecting user to an intermediate page</h3><p class="paragraph"/>Method <code>restartResponseAtSignInPage</code> is an example of redirecting user to an intermediate page before allowing him to access to the requested page. This method internally throws exception <code>org.apache.wicket.RestartResponseAtInterceptPageException</code> which saves the URL of the requested page into session metadata and then redirects user to the page passed as constructor parameter (the sign in page).<p class="paragraph"/>Component's method <code>redirectToInterceptPage(Page)</code> works in much the same way as <code>restartResponseAtSignInPage</code> but it allows us to specify which page to use as int
ermediate page:<p class="paragraph"/><div class="code"><pre>redirectToInterceptPage(intermediatePage);</pre></div><p class="paragraph"/><blockquote class="note">
Since both <code>restartResponseAtSignInPage</code> and <code>redirectToInterceptPage</code> internally throw an exception, the code placed after them will not be executed.
</blockquote>
Modified: wicket/common/site/trunk/_site/guide/guide/chapter20.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/guide/chapter20.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/guide/chapter20.html (original)
+++ wicket/common/site/trunk/_site/guide/guide/chapter20.html Sun Dec 15 20:24:13 2013
@@ -178,7 +178,7 @@ function addJsClass() {
<h2 id="chapter20_1">21.1 Utility class WicketTester</h2>
-<p class="paragraph"/>A good way to start getting confident with Wicket unit testing support is looking at the test case class TestHomePage that is automatically generated by Maven when we use Wicket archetype to create a new project:<p class="paragraph"/><img border="0" class="center" src="../img/mvn-wicket-archetype.png"></img><p class="paragraph"/>Here is the content of TestHomePage:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
+<p class="paragraph"/>A good way to start getting confident with Wicket unit testing support is looking at the test case class <code>TestHomePage</code> that is automatically generated by Maven when we use Wicket archetype to create a new project:<p class="paragraph"/><img border="0" class="center" src="../img/mvn-wicket-archetype.png"></img><p class="paragraph"/>Here is the content of TestHomePage:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
<span class="java-keyword">private</span> WicketTester tester;<p class="paragraph"/> @Before
<span class="java-keyword">public</span> void setUp(){
tester = <span class="java-keyword">new</span> WicketTester(<span class="java-keyword">new</span> WicketApplication());
@@ -190,7 +190,7 @@ function addJsClass() {
//assert rendered page class
tester.assertRenderedPage(HomePage.class);
}
-}</pre></div><p class="paragraph"/>The central class in a Wicket testing is <code>org.apache.wicket.util.tester.WicketTester</code>. This utility class provides a set of methods to render a component, click links, check if page contains a given component or a feedback message, and so on.<p class="paragraph"/>The basic test case shipped with <code>TestHomePage</code> illustrates how <code>WicketTester</code> is typically instantiated (inside method <code>setUp()</code>). In order to test our components, WicketTester needs to use an instance of <code>WebApplication</code>. Usually, we will use our application class as <code>WebApplication</code>, but we can also decide to build WicketTester invoking its no-argument constructor and letting it automatically build a mock web application (an instance of class <code>org.apache.wicket.mock.MockApplication</code>).<p class="paragraph"/>The code from <code>TestHomePage</code> introduces two basic methods to test our pages. The first is m
ethod <code>startPage</code> that renders a new instance of the given page class and sets it as current rendered page for WicketTester. The second method is assertRenderedPage which checks if the current rendered page is an instance of the given class. In this way if TestHomePage succeeds we are sure that page HomePage has been rendered without any problem. The last rendered page can be retrieved with method <code>getLastRenderedPage</code>.<p class="paragraph"/>That's only a taste of what <code>WicketTester</code> can do. In the next paragraphs we will see how it can be used to test every element that composes a Wicket page (links, models, behaviors, etc...).<p class="paragraph"/><h3>Testing links</h3><p class="paragraph"/>A click on a Wicket link can be simulated with method clickLink which takes in input the link component or the page-relative path to it.<p class="paragraph"/>To see an example of usage of clickLink, let's consider again project LifeCycleStagesRevisited. As we kno
w from chapter 5 the home page of the project alternately displays two different labels (âFirst labelâ and âSecond labelâ), swapping between them each time button "reload" is clicked. The code from its test case checks that label has actually changed after button "reload" has been pressed:<p class="paragraph"/><div class="code"><pre>//…
+}</pre></div><p class="paragraph"/>The central class in a Wicket testing is <code>org.apache.wicket.util.tester.WicketTester</code>. This utility class provides a set of methods to render a component, click links, check if page contains a given component or a feedback message, and so on.<p class="paragraph"/>The basic test case shipped with <code>TestHomePage</code> illustrates how <code>WicketTester</code> is typically instantiated (inside method <code>setUp()</code>). In order to test our components, WicketTester needs to use an instance of <code>WebApplication</code>. Usually, we will use our application class as <code>WebApplication</code>, but we can also decide to build WicketTester invoking its no-argument constructor and letting it automatically build a mock web application (an instance of class <code>org.apache.wicket.mock.MockApplication</code>).<p class="paragraph"/>The code from <code>TestHomePage</code> introduces two basic methods to test our pages. The first is m
ethod <code>startPage</code> that renders a new instance of the given page class and sets it as current rendered page for WicketTester. The second method is assertRenderedPage which checks if the current rendered page is an instance of the given class. In this way if TestHomePage succeeds we are sure that page HomePage has been rendered without any problem. The last rendered page can be retrieved with method <code>getLastRenderedPage</code>.<p class="paragraph"/>That's only a taste of what <code>WicketTester</code> can do. In the next paragraphs we will see how it can be used to test every element that composes a Wicket page (links, models, behaviors, etc...).<p class="paragraph"/><h3>Testing links</h3><p class="paragraph"/>A click on a Wicket link can be simulated with method <code>clickLink</code> which takes in input the link component or the page-relative path to it.<p class="paragraph"/>To see an example of usage of clickLink, let's consider again project <code>LifeCycleStagesR
evisited</code>. As we know from chapter 5 the home page of the project alternately displays two different labels (âFirst labelâ and âSecond labelâ), swapping between them each time button "reload" is clicked. The code from its test case checks that label has actually changed after button "reload" has been pressed:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void switchLabelTest(){
//start and render the test page
@@ -204,7 +204,7 @@ function addJsClass() {
//assert rendered label
tester.assertLabel(<span class="java-quote">"label"</span>, <span class="java-quote">"Second label"</span>);
}
-//...</pre></div><p class="paragraph"/>In the code above we have used clickLink to click on the "reload" button and force page to be rendered again. In addition, we have used also method assertLabel that checks if a given label contains the expected text.<p class="paragraph"/>By default clickLink assumes that AJAX is enabled on client side. To switch AJAX off we can use another version of this method that takes in input the path to the link component and a boolean flag that indicates if AJAX must be enabled (true) or not (false).<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/>In the code above we have used <code>clickLink</code> to click on the "reload" button and force page to be rendered again. In addition, we have used also method <code>assertLabel</code> that checks if a given label contains the expected text.<p class="paragraph"/>By default <code>clickLink</code> assumes that AJAX is enabled on client side. To switch AJAX off we can use another version of this method that takes in input the path to the link component and a boolean flag that indicates if AJAX must be enabled (true) or not (false).<p class="paragraph"/><div class="code"><pre>//…
//simulate a click on a button without AJAX support
tester.clickLink(<span class="java-quote">"reload"</span>, <span class="java-keyword">false</span>);
//...</pre></div><p class="paragraph"/><h3>Testing component status</h3><p class="paragraph"/>WicketTester provides also a set of methods to test the states of a component. They are:
@@ -212,7 +212,7 @@ tester.clickLink(<span class="java-q
<li><strong class="bold">assertEnabled(String path)/assertDisabled(String path)</strong>: they test if a component is enabled or not.</li>
<li><strong class="bold">assertVisible(String path)/assertInvisible(String path)</strong>: they test component visibility.</li>
<li><strong class="bold">assertRequired(String path)</strong>: checks if a form component is required.</li>
-</ul><p class="paragraph"/>In the test case from project CustomDatepickerAjax we used assertEnabled/assertDisabled to check if button "update" really disables our datepicker:<p class="paragraph"/><div class="code"><pre>//…
+</ul><p class="paragraph"/>In the test case from project <code>CustomDatepickerAjax</code> we used <code>assertEnabled</code>/<code>assertDisabled</code> to check if button "update" really disables our datepicker:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void testDisableDatePickerWithButton(){
//start and render the test page
@@ -224,7 +224,7 @@ tester.clickLink(<span class="java-q
//assert that datepicker is disabled
tester.assertDisabled(<span class="java-quote">"form:datepicker"</span>);
}
-//...</pre></div><p class="paragraph"/><h3>Testing components in isolation</h3><p class="paragraph"/>Method startComponent(Component) can be used to test a component in isolation without having to create a container page for this purpose. The target component is rendered and both its methods onInitialize() and onBeforeRender() are executed. In the test case from project CustomFormComponentPanel we used this method to check if our custom form component correctly renders its internal label:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/><h3>Testing components in isolation</h3><p class="paragraph"/>Method <code>startComponent(Component)</code> can be used to test a component in isolation without having to create a container page for this purpose. The target component is rendered and both its methods <code>onInitialize()</code> and <code>onBeforeRender()</code> are executed. In the test case from project <code>CustomFormComponentPanel</code> we used this method to check if our custom form component correctly renders its internal label:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void testCustomPanelContainsLabel(){
TemperatureDegreeField field = <span class="java-keyword">new</span> TemperatureDegreeField(<span class="java-quote">"field"</span>, Model.of(0.00));
@@ -233,7 +233,7 @@ tester.clickLink(<span class="java-q
tester.startComponent(field);
Assert.assertNotNull(field.get(<span class="java-quote">"mesuramentUnit"</span>));
}
-//...</pre></div><p class="paragraph"/>If test requires a page we can use startComponentInPage(Component) which automatically generates a page for our component.<p class="paragraph"/><h3>Testing the response</h3><p class="paragraph"/>WicketTester allows us to access to the last response generated during testing with method getLastResponse. The returned value is an instance of class MockHttpServletResponse that provides helper methods to extract informations from mocked request.<p class="paragraph"/>In the test case from project CustomResourceMounting we extract the text contained in the last response with method getDocument and we check if it is equal to the RSS feed used for the test:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/>If test requires a page we can use <code>startComponentInPage(Component)</code> which automatically generates a page for our component.<p class="paragraph"/><h3>Testing the response</h3><p class="paragraph"/><code>WicketTester</code> allows us to access to the last response generated during testing with method <code>getLastResponse</code>. The returned value is an instance of class MockHttpServletResponse that provides helper methods to extract informations from mocked request.<p class="paragraph"/>In the test case from project <code>CustomResourceMounting</code> we extract the text contained in the last response with method <code>getDocument</code> and we check if it is equal to the RSS feed used for the test:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void testMountedResourceResponse() <span class="java-keyword">throws</span> IOException, FeedException{tester.startResource(<span class="java-keyword">new</span> RSSProducerResource());
<span class="java-object">String</span> responseTxt = tester.getLastResponse().getDocument();
@@ -244,18 +244,18 @@ tester.clickLink(<span class="java-q
//the response and the RSS must be equal
Assert.assertEquals(responseTxt, outputStream.toString());
}
-//...</pre></div><p class="paragraph"/>To simulate a request to the custom resource we used method startResource which can be used also with resource references.<p class="paragraph"/><h3>Testing URLs</h3><p class="paragraph"/>WicketTester can be pointed to an arbitrary URL with method executeUrl(String url). This can be useful to test mounted pages, resources or request mappers:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/>To simulate a request to the custom resource we used method <code>startResource</code> which can be used also with resource references.<p class="paragraph"/><h3>Testing URLs</h3><p class="paragraph"/><code>WicketTester</code> can be pointed to an arbitrary URL with method <code>executeUrl(String url)</code>. This can be useful to test mounted pages, resources or request mappers:<p class="paragraph"/><div class="code"><pre>//…
//the resource was mapped at '/foo/bar'
tester.executeUrl(<span class="java-quote">"./foo/bar"</span>);
-//...</pre></div><p class="paragraph"/><h3>Testing AJAX components</h3><p class="paragraph"/>If our application uses AJAX to refresh components markup, we can test if AjaxRequestTarget contains a given component with WicketTester's method assertComponentOnAjaxResponse:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/><h3>Testing AJAX components</h3><p class="paragraph"/>If our application uses AJAX to refresh components markup, we can test if <code>AjaxRequestTarget</code> contains a given component with <code>WicketTester</code>'s method <code>assertComponentOnAjaxResponse</code>:<p class="paragraph"/><div class="code"><pre>//…
//test <span class="java-keyword">if</span> AjaxRequestTarget contains a component (using its instance)
tester.assertComponentOnAjaxResponse(amountLabel);
//…
//test <span class="java-keyword">if</span> AjaxRequestTarget contains a component (using its path)
-tester.assertComponentOnAjaxResponse(<span class="java-quote">"pathToLabel:labelId"</span>);</pre></div><p class="paragraph"/>It's also possible to use method isComponentOnAjaxResponse(Component cmp) to know if a component has been added to AjaxRequestTarget:<p class="paragraph"/><div class="code"><pre>//…
+tester.assertComponentOnAjaxResponse(<span class="java-quote">"pathToLabel:labelId"</span>);</pre></div><p class="paragraph"/>It's also possible to use method <code>isComponentOnAjaxResponse(Component cmp)</code> to know if a component has been added to <code>AjaxRequestTarget</code>:<p class="paragraph"/><div class="code"><pre>//…
//test <span class="java-keyword">if</span> AjaxRequestTarget does NOT contain amountLabel
assertFalse(tester.isComponentOnAjaxResponse(amountLabel));
-//...</pre></div><p class="paragraph"/><h3>Testing AJAX events</h3><p class="paragraph"/>Behavior AjaxEventBehavior and its subclasses can be tested simulating AJAX events with WicketTester's method executeAjaxEvent(Component cmp, String event). Here is the sample code from project TestAjaxEventsExample:<p class="paragraph"/><strong class="bold">Home page code:</strong><p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {
+//...</pre></div><p class="paragraph"/><h3>Testing AJAX events</h3><p class="paragraph"/>Behavior <code>AjaxEventBehavior</code> and its subclasses can be tested simulating AJAX events with <code>WicketTester</code>'s method <code>executeAjaxEvent(Component cmp, String event)</code>. Here is the sample code from project <code>TestAjaxEventsExample</code>:<p class="paragraph"/><strong class="bold">Home page code:</strong><p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {
<span class="java-keyword">public</span> <span class="java-keyword">static</span> <span class="java-object">String</span> INIT_VALUE = <span class="java-quote">"Initial value"</span>;
<span class="java-keyword">public</span> <span class="java-keyword">static</span> <span class="java-object">String</span> OTHER_VALUE = <span class="java-quote">"Other value"</span>;<p class="paragraph"/> <span class="java-keyword">public</span> HomePage(<span class="java-keyword">final</span> PageParameters parameters) {
<span class="java-keyword">super</span>(parameters);
@@ -281,7 +281,7 @@ assertFalse(tester.isComponentOnAjaxResp
tester.executeAjaxEvent(<span class="java-quote">"label"</span>, <span class="java-quote">"click"</span>);
//test <span class="java-keyword">if</span> label has changed as expected
tester.assertLabel(<span class="java-quote">"label"</span>, HomePage.OTHER_VALUE);
-}</pre></div><p class="paragraph"/><h3>Testing AJAX behaviors</h3><p class="paragraph"/>To test a generic AJAX behavior we can simulate a request to it using WicketTester's method executeBehavior(AbstractAjaxBehavior behavior):<p class="paragraph"/><div class="code"><pre>//…
+}</pre></div><p class="paragraph"/><h3>Testing AJAX behaviors</h3><p class="paragraph"/>To test a generic AJAX behavior we can simulate a request to it using <code>WicketTester</code>'s method <code>executeBehavior(AbstractAjaxBehavior behavior)</code>:<p class="paragraph"/><div class="code"><pre>//…
AjaxFormComponentUpdatingBehavior ajaxBehavior =
<span class="java-keyword">new</span> AjaxFormComponentUpdatingBehavior(<span class="java-quote">"change"</span>){
@Override
@@ -293,7 +293,7 @@ component.add(ajaxBehavior);
//…
//execute AJAX behavior, i.e. onUpdate will be invoked
tester.executeBehavior(ajaxBehavior));
-//...</pre></div><p class="paragraph"/><h3>Using a custom servlet context</h3><p class="paragraph"/>In paragraph 13.9 we have seen how to configure our application to store resource files into a custom folder placed inside webapp root folder (see project CustomFolder4MarkupExample).<p class="paragraph"/>In order to write testing code for applications that use this kind of customization, we must tell WicketTester which folder to use as webapp root. This is necessary as under test environment we don't have any web server, hence it's impossible for WicketTester to retrieve this parameter from servlet context.<p class="paragraph"/>Webapp root folder can be passed to WicketTester's constructor as further parameter like we did in the test case of project CustomFolder4MarkupExample:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
+//...</pre></div><p class="paragraph"/><h3>Using a custom servlet context</h3><p class="paragraph"/>In paragraph 13.9 we have seen how to configure our application to store resource files into a custom folder placed inside webapp root folder (see project <code>CustomFolder4MarkupExample</code>).<p class="paragraph"/>In order to write testing code for applications that use this kind of customization, we must tell <code>WicketTester</code> which folder to use as webapp root. This is necessary as under test environment we don't have any web server, hence it's impossible for <code>WicketTester</code> to retrieve this parameter from servlet context.<p class="paragraph"/>Webapp root folder can be passed to <code>WicketTester</code>'s constructor as further parameter like we did in the test case of project <code>CustomFolder4MarkupExample</code>:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
<span class="java-keyword">private</span> WicketTester tester;<p class="paragraph"/> @Before
<span class="java-keyword">public</span> void setUp(){
//build the path to webapp root folder
@@ -302,7 +302,7 @@ tester.executeBehavior(ajaxBehavior));
}
//test methods…
}</pre></div><p class="paragraph"/><blockquote class="note">
-After a test method has been executed, we may need to clear any possible side effect occurred to the Application and Session objects. This can be done invoking WicketTester's method destroy():<p class="paragraph"/><div class="code"><pre>@After
+After a test method has been executed, we may need to clear any possible side effect occurred to the <code>Application</code> and <code>Session</code> objects. This can be done invoking <code>WicketTester</code>'s method <code>destroy()</code>:<p class="paragraph"/><div class="code"><pre>@After
<span class="java-keyword">public</span> void tearDown(){
//clear any side effect occurred during test.
tester.destroy();
@@ -312,24 +312,24 @@ After a test method has been executed, w
<h2 id="chapter20_2">21.2 Testing Wicket forms</h2>
-<p class="paragraph"/>Wicket provides utility class FormTester that is expressly designed to test Wicket forms. A new FormTester is returned by WicketTester's method newFormTester(String, boolean) which takes in input the page-relative path of the form we want to test and a boolean flag indicating if its form components must be filled with a blank string:<p class="paragraph"/><div class="code"><pre>//…
+<p class="paragraph"/>Wicket provides utility class FormTester that is expressly designed to test Wicket forms. A new FormTester is returned by <code>WicketTester</code>'s method <code>newFormTester(String, boolean)</code> which takes in input the page-relative path of the form we want to test and a boolean flag indicating if its form components must be filled with a blank string:<p class="paragraph"/><div class="code"><pre>//…
//create a <span class="java-keyword">new</span> form tester without filling its form components with a blank string
FormTester formTester = tester.newFormTester(<span class="java-quote">"form"</span>, <span class="java-keyword">false</span>);
-//...</pre></div><p class="paragraph"/>FormTester can simulate form submission with method submit which takes in input as optional parameter the submitting component to use instead of the default one:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/><code>FormTester</code> can simulate form submission with method submit which takes in input as optional parameter the submitting component to use instead of the default one:<p class="paragraph"/><div class="code"><pre>//…
//create a <span class="java-keyword">new</span> form tester without filling its form components with a blank string
FormTester formTester = tester.newFormTester(<span class="java-quote">"form"</span>, <span class="java-keyword">false</span>);
//submit form with <span class="java-keyword">default</span> submitter
formTester.submit();
//…
//submit form using <span class="java-keyword">inner</span> component 'button' as alternate button
-formTester.submit(<span class="java-quote">"button"</span>);</pre></div><p class="paragraph"/>If we want to submit a form with an external link component we can use method submitLink (String path, boolean pageRelative) specifying the path to the link.<p class="paragraph"/>In the next paragraphs we will see how to use WicketTester and FormTester to interact with a form and with its children components.<p class="paragraph"/><h3>Setting form components input</h3><p class="paragraph"/>The purpose of a HTML form is to collect user input. FormTester comes with the following set of methods that simulate input insertion into form's fields:
+formTester.submit(<span class="java-quote">"button"</span>);</pre></div><p class="paragraph"/>If we want to submit a form with an external link component we can use method <code>submitLink(String path, boolean pageRelative)</code> specifying the path to the link.<p class="paragraph"/>In the next paragraphs we will see how to use <code>WicketTester</code> and <code>FormTester</code> to interact with a form and with its children components.<p class="paragraph"/><h3>Setting form components input</h3><p class="paragraph"/>The purpose of a HTML form is to collect user input. <code>FormTester</code> comes with the following set of methods that simulate input insertion into form's fields:
<ul class="star">
-<li><strong class="bold">setValue(String path, String value)</strong>: inserts the given textual value into the specified component. It can be used with components TextField and TextArea. A version of this method that accepts a component instance instead of its path is also available.</li>
-<li><strong class="bold">setValue(String checkboxId, boolean value)</strong>: sets the value of a given CheckBox component.</li>
-<li><strong class="bold">setFile(String formComponentId, File file, String contentType)</strong>: sets a File object on a FileUploadField component.</li>
-<li><strong class="bold">select(String formComponentId, int index)</strong>: selects an option among a list of possible options owned by a component. It supports components that are subclasses of AbstractChoice along with RadioGroup and CheckGroup.</li>
-<li><strong class="bold">selectMultiple(String formComponentId, int indexes)</strong>: selects all the options corresponding to the given array of indexes. It can be used with multiple-choice components like CheckGroup or ListMultipleChoice.</li>
-</ul><p class="paragraph"/>setValue is used inside method insertUsernamePassword to set the username and password fields of the form used in project StatelessLoginForm:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">protected</span> void insertUsernamePassword(<span class="java-object">String</span> username, <span class="java-object">String</span> password) {
+<li><strong class="bold">setValue(String path, String value)</strong>: inserts the given textual value into the specified component. It can be used with components <code>TextField</code> and <code>TextArea</code>. A version of this method that accepts a component instance instead of its path is also available.</li>
+<li><strong class="bold">setValue(String checkboxId, boolean value)</strong>: sets the value of a given <code>CheckBox</code> component.</li>
+<li><strong class="bold">setFile(String formComponentId, File file, String contentType)</strong>: sets a <code>File</code> object on a <code>FileUploadField</code> component.</li>
+<li><strong class="bold">select(String formComponentId, int index)</strong>: selects an option among a list of possible options owned by a component. It supports components that are subclasses of <code>AbstractChoice</code> along with <code>RadioGroup</code> and <code>CheckGroup</code>.</li>
+<li><strong class="bold">selectMultiple(String formComponentId, int indexes)</strong>: selects all the options corresponding to the given array of indexes. It can be used with multiple-choice components like <code>CheckGroup</code> or <code>ListMultipleChoice</code>.</li>
+</ul><p class="paragraph"/><code>setValue</code> is used inside method <code>insertUsernamePassword</code> to set the username and password fields of the form used in project <code>StatelessLoginForm</code>:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">protected</span> void insertUsernamePassword(<span class="java-object">String</span> username, <span class="java-object">String</span> password) {
//start and render the test page
tester.startPage(HomePage.class);
FormTester formTester = tester.newFormTester(<span class="java-quote">"form"</span>);
@@ -338,12 +338,12 @@ formTester.submit(<span class="java-
formTester.setValue(<span class="java-quote">"password"</span>, password);
//submit form
formTester.submit();
-}</pre></div><p class="paragraph"/><h3>Testing feedback messages</h3><p class="paragraph"/>To check if a page contains one or more expected feedback messages we can use the following methods provided by WicketTester:
+}</pre></div><p class="paragraph"/><h3>Testing feedback messages</h3><p class="paragraph"/>To check if a page contains one or more expected feedback messages we can use the following methods provided by <code>WicketTester</code>:
<ul class="star">
<li><strong class="bold">assertFeedback(String path, String… messages)</strong>: asserts that a given panel contains the specified messages</li>
<li><strong class="bold">assertInfoMessages(String… expectedInfoMessages)</strong>: asserts that the expected info messages are rendered in the page.</li>
<li><strong class="bold">assertErrorMessages(String… expectedErrorMessages)</strong>: asserts that the expected error messages are rendered in the page.</li>
-</ul><p class="paragraph"/>assertInfoMessages and assertErrorMessages are used in the test case from project StatelessLoginForm to check that form generates a feedback message in accordance with the login result:<p class="paragraph"/>
+</ul><p class="paragraph"/><code>assertInfoMessages</code> and <code>assertErrorMessages</code> are used in the test case from project <code>StatelessLoginForm</code> to check that form generates a feedback message in accordance with the login result:<p class="paragraph"/>
<div class="code"><pre>@Test
<span class="java-keyword">public</span> void testMessageForSuccessfulLogin(){
inserUsernamePassword(<span class="java-quote">"user"</span>, <span class="java-quote">"user"</span>);
@@ -352,7 +352,7 @@ formTester.submit(<span class="java-
<span class="java-keyword">public</span> void testMessageForFailedLogin (){
inserUsernamePassword(<span class="java-quote">"wrongCredential"</span>, <span class="java-quote">"wrongCredential"</span>);
tester.assertErrorMessages(<span class="java-quote">"Wrong username or password"</span>);
-}</pre></div><p class="paragraph"/><h3>Testing models</h3><p class="paragraph"/>Component model can be tested as well. With method assertModelValue we can test if a specific component has the expected data object inside its model.<p class="paragraph"/>This method has been used in the test case of project ModelChainingExample to check if the form and the drop-down menu share the same data object:<p class="paragraph"/><div class="code"><pre>@Test
+}</pre></div><p class="paragraph"/><h3>Testing models</h3><p class="paragraph"/>Component model can be tested as well. With method <code>assertModelValue</code> we can test if a specific component has the expected data object inside its model.<p class="paragraph"/>This method has been used in the test case of project <code>ModelChainingExample</code> to check if the form and the drop-down menu share the same data object:<p class="paragraph"/><div class="code"><pre>@Test
<span class="java-keyword">public</span> void testFormSelectSameModelObject(){
PersonListDetails personListDetails = <span class="java-keyword">new</span> PersonListDetails();
DropDownChoice dropDownChoice = (DropDownChoice) personListDetails.get(<span class="java-quote">"persons"</span>);
@@ -366,7 +366,7 @@ formTester.submit(<span class="java-
<h2 id="chapter20_3">21.3 Testing markup with TagTester</h2>
-<p class="paragraph"/>If we need to test component markup at a more fine-grained level, we can use class <code>TagTester</code> from package <code>org.apache.wicket.util.tester</code>.<p class="paragraph"/>This test class allows to check if the generated markup contains one or more tags having a given attribute with a given value. TagTester can not be directly instantiated but it comes with three factory methods that return one or more TagTester matching the searching criteria. In the following test case (from project TagTesterExample) we retrieve the first tag of the home page (a <span> tag) having attribute class equal to myClass:<p class="paragraph"/><strong class="bold">HomePage markup:</strong><p class="paragraph"/><div class="code"><pre><html xmlns:wicket=<span class="java-quote">"http://wicket.apache.org"</span>>
+<p class="paragraph"/>If we need to test component markup at a more fine-grained level, we can use class <code>TagTester</code> from package <code>org.apache.wicket.util.tester</code>.<p class="paragraph"/>This test class allows to check if the generated markup contains one or more tags having a given attribute with a given value. TagTester can not be directly instantiated but it comes with three factory methods that return one or more TagTester matching the searching criteria. In the following test case (from project <code>TagTesterExample</code>) we retrieve the first tag of the home page (a <span> tag) having attribute class equal to myClass:<p class="paragraph"/><strong class="bold">HomePage markup:</strong><p class="paragraph"/><div class="code"><pre><html xmlns:wicket=<span class="java-quote">"http://wicket.apache.org"</span>>
<head>
<meta charset=<span class="java-quote">"utf-8"</span> />
<title></title>
@@ -384,7 +384,7 @@ formTester.submit(<span class="java-
<span class="java-object">String</span> responseTxt = tester.getLastResponse().getDocument();<p class="paragraph"/> TagTester tagTester = TagTester.createTagByAttribute(responseTxt, <span class="java-quote">"class"</span>, <span class="java-quote">"myClass"</span>);<p class="paragraph"/> Assert.assertNotNull(tagTester);
Assert.assertEquals(<span class="java-quote">"span"</span>, tagTester.getName());<p class="paragraph"/> List<TagTester> tagTesterList = TagTester.createTagsByAttribute(responseTxt,
<span class="java-quote">"class"</span>, <span class="java-quote">"myClass"</span>, <span class="java-keyword">false</span>);<p class="paragraph"/> Assert.assertEquals(2, tagTesterList.size());
-}</pre></div><p class="paragraph"/>The name of the tag found by TagTester can be retrieved with its method getName. Method createTagsByAttribute returns all the tags that have the given value on the class attribute. In the code above we have used this method to test that our markup contains two tags having attribute class equal to myClass.<p class="paragraph"/>Another utility class that comes in handy when we want to test components markup is ComponentRenderer in package <code>org.apache.wicket.core.util.string</code>. The purpose of this class is to render a page or a component in isolation with its static methods renderComponent and renderPage. Both methods return the generated markup as CharSequence:<p class="paragraph"/><div class="code"><pre>@Test
+}</pre></div><p class="paragraph"/>The name of the tag found by TagTester can be retrieved with its method getName. Method <code>createTagsByAttribute</code> returns all the tags that have the given value on the class attribute. In the code above we have used this method to test that our markup contains two tags having attribute class equal to myClass.<p class="paragraph"/>Another utility class that comes in handy when we want to test components markup is <code>ComponentRenderer</code> in package <code>org.apache.wicket.core.util.string</code>. The purpose of this class is to render a page or a component in isolation with its static methods <code>renderComponent</code> and <code>renderPage</code>. Both methods return the generated markup as <code>CharSequence</code>:<p class="paragraph"/><div class="code"><pre>@Test
<span class="java-keyword">public</span> void customComponentMarkupTest()
{
//instantiate MyComponent
@@ -395,7 +395,7 @@ formTester.submit(<span class="java-
<h2 id="chapter20_4">21.4 Summary</h2>
-<p class="paragraph"/>With a component-oriented framework we can test our pages and components as we use to do with any other Java entity. Wicket offers a complete support for writing testing code, offering built-in tools to test nearly all the elements that build up our applications (pages, containers, links, behaviors, etc...).<p class="paragraph"/>The main entity discussed in this chapter has been class WicketTester which can be used to write unit tests and acceptance tests for our application, but we have also seen how to test forms with FormTester and how to inspect markup with TagTester.<p class="paragraph"/>In addition to learning how to use the utility classes provided by Wicket for testing, we have also experienced the innovative approach of Wicket to web testing that allows to test components in isolation without the need of running our tests with a web server and depending only on JUnit as testing framework.<p class="paragraph"/><p class="paragraph"/>
+<p class="paragraph"/>With a component-oriented framework we can test our pages and components as we use to do with any other Java entity. Wicket offers a complete support for writing testing code, offering built-in tools to test nearly all the elements that build up our applications (pages, containers, links, behaviors, etc...).<p class="paragraph"/>The main entity discussed in this chapter has been class <code>WicketTester</code> which can be used to write unit tests and acceptance tests for our application, but we have also seen how to test forms with <code>FormTester</code> and how to inspect markup with <code>TagTester</code>.<p class="paragraph"/>In addition to learning how to use the utility classes provided by Wicket for testing, we have also experienced the innovative approach of Wicket to web testing that allows to test components in isolation without the need of running our tests with a web server and depending only on JUnit as testing framework.<p class="paragraph"/><p c
lass="paragraph"/>
<div style="clear:both;margin-top:15px;"></div>
Modified: wicket/common/site/trunk/_site/guide/guide/chapter22.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/guide/chapter22.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/guide/chapter22.html (original)
+++ wicket/common/site/trunk/_site/guide/guide/chapter22.html Sun Dec 15 20:24:13 2013
@@ -350,7 +350,7 @@ add(loginBox);</pre></div><p class="para
<h2 id="chapter22_8">23.8 Pass models extended components</h2>
-<p class="paragraph"/>Always try to pass models on to the parent component. By that, you ensure that at the end of every request the method <code>IModel.detach()</code> gets called. This method is responsible for a data cleanup. Another example: you have implemented your own model which persists the data in the <code>detach()</code> method. So the call of <code>detach()</code> is neccessary for that your data gets persisted. You can see an exemplary passing to the super constructor here:<p class="paragraph"/><strong class="bold">Listing 11:</strong><p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class RegistrationInputPanel <span class="java-keyword">extends</span> Panel{
+<p class="paragraph"/>Always try to pass models on to the parent component. By that, you ensure that at the end of every request the method <code>IModel.detach()</code> gets called. This method is responsible for a data cleanup. Another example: you have implemented your own model which persists the data in the <code>detach()</code> method. So the call of <code>detach()</code> is necessary for that your data gets persisted. You can see an exemplary passing to the super constructor here:<p class="paragraph"/><strong class="bold">Listing 11:</strong><p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class RegistrationInputPanel <span class="java-keyword">extends</span> Panel{
<span class="java-keyword">public</span> RegistrationInputPanel(<span class="java-object">String</span> id, IModel<Registration> regModel) {
<span class="java-keyword">super</span>(id, regModel)
// add components
Modified: wicket/common/site/trunk/_site/guide/guide/pages/chapter18_1.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/guide/pages/chapter18_1.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/guide/pages/chapter18_1.html (original)
+++ wicket/common/site/trunk/_site/guide/guide/pages/chapter18_1.html Sun Dec 15 20:24:13 2013
@@ -168,7 +168,7 @@ function addJsClass() {
}</pre></div><p class="paragraph"/>In this example the object that we want to inject is a simple class containing a greeting message:<p class="paragraph"/><div class="code"><pre>@ManagedBean
<span class="java-keyword">public</span> class EnterpriseMessage {
<span class="java-keyword">public</span> <span class="java-object">String</span> message = <span class="java-quote">"Welcome to the EJB world!"</span>;
-}</pre></div><p class="paragraph"/>Please note that we have used annotation <code>ManagedBean to decorate our object. Now to inject it into the home page we must add a field of type EnterpriseMessage and annotate it with annotation </code>EJB:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {<p class="paragraph"/> @EJB
+}</pre></div><p class="paragraph"/>Please note that we have used annotation ManagedBean to decorate our object. Now to inject it into the home page we must add a field of type EnterpriseMessage and annotate it with annotation @EJB:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {<p class="paragraph"/> @EJB
<span class="java-keyword">private</span> EnterpriseMessage enterpriseMessage;
//getter and setter <span class="java-keyword">for</span> enterpriseMessage...<p class="paragraph"/> <span class="java-keyword">public</span> HomePage(<span class="java-keyword">final</span> PageParameters parameters) {
<span class="java-keyword">super</span>(parameters);<p class="paragraph"/> add(<span class="java-keyword">new</span> Label(<span class="java-quote">"message"</span>, enterpriseMessage.message));
Modified: wicket/common/site/trunk/_site/guide/guide/pages/chapter19_1.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/guide/pages/chapter19_1.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/guide/pages/chapter19_1.html (original)
+++ wicket/common/site/trunk/_site/guide/guide/pages/chapter19_1.html Sun Dec 15 20:24:13 2013
@@ -229,7 +229,7 @@ Remember that signOut does not discard a
<span class="java-keyword">protected</span> <span class="java-object">Class</span><? <span class="java-keyword">extends</span> WebPage> getSignInPageClass() {
<span class="java-keyword">return</span> SignInPage.class;
}
-}</pre></div><p class="paragraph"/>The authentication logic inside authenticate has been kept quite trivial in order to make the code as clean as possible. Please note also that session class must have a constructor that accepts an instance of class <code>Request</code>.<p class="paragraph"/><h3>Redirecting user to an intermediate page</h3><p class="paragraph"/>Method <code>restartResponseAtSignInPage</code> is an example of redirecting user to an intermediate page before allowing him to access to the requested page. This method internally throws exception <code>org.apache.wicket.RestartResponseAtInterceptPageException</code> which saves the URL of the requested page into session metadata and then redirects user to the page passed as constructor parameter (the sign in page).<p class="paragraph"/>Component's method <code>redirectToInterceptPage(Page)</code> works in much the same way as <code>restartResponseAtSignInPage</code> but it allows us to specify which page to use as int
ermediate page:<p class="paragraph"/><code>redirectToInterceptPage(intermediatePage);</code><p class="paragraph"/><blockquote class="note">
+}</pre></div><p class="paragraph"/>The authentication logic inside authenticate has been kept quite trivial in order to make the code as clean as possible. Please note also that session class must have a constructor that accepts an instance of class <code>Request</code>.<p class="paragraph"/><h3>Redirecting user to an intermediate page</h3><p class="paragraph"/>Method <code>restartResponseAtSignInPage</code> is an example of redirecting user to an intermediate page before allowing him to access to the requested page. This method internally throws exception <code>org.apache.wicket.RestartResponseAtInterceptPageException</code> which saves the URL of the requested page into session metadata and then redirects user to the page passed as constructor parameter (the sign in page).<p class="paragraph"/>Component's method <code>redirectToInterceptPage(Page)</code> works in much the same way as <code>restartResponseAtSignInPage</code> but it allows us to specify which page to use as int
ermediate page:<p class="paragraph"/><div class="code"><pre>redirectToInterceptPage(intermediatePage);</pre></div><p class="paragraph"/><blockquote class="note">
Since both <code>restartResponseAtSignInPage</code> and <code>redirectToInterceptPage</code> internally throw an exception, the code placed after them will not be executed.
</blockquote>
Modified: wicket/common/site/trunk/_site/guide/guide/pages/chapter20_1.html
URL: http://svn.apache.org/viewvc/wicket/common/site/trunk/_site/guide/guide/pages/chapter20_1.html?rev=1551048&r1=1551047&r2=1551048&view=diff
==============================================================================
--- wicket/common/site/trunk/_site/guide/guide/pages/chapter20_1.html (original)
+++ wicket/common/site/trunk/_site/guide/guide/pages/chapter20_1.html Sun Dec 15 20:24:13 2013
@@ -157,7 +157,7 @@ function addJsClass() {
<h2 id="chapter20_1">21.1 Utility class WicketTester</h2>
-<p class="paragraph"/>A good way to start getting confident with Wicket unit testing support is looking at the test case class TestHomePage that is automatically generated by Maven when we use Wicket archetype to create a new project:<p class="paragraph"/><img border="0" class="center" src="../img/mvn-wicket-archetype.png"></img><p class="paragraph"/>Here is the content of TestHomePage:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
+<p class="paragraph"/>A good way to start getting confident with Wicket unit testing support is looking at the test case class <code>TestHomePage</code> that is automatically generated by Maven when we use Wicket archetype to create a new project:<p class="paragraph"/><img border="0" class="center" src="../img/mvn-wicket-archetype.png"></img><p class="paragraph"/>Here is the content of TestHomePage:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
<span class="java-keyword">private</span> WicketTester tester;<p class="paragraph"/> @Before
<span class="java-keyword">public</span> void setUp(){
tester = <span class="java-keyword">new</span> WicketTester(<span class="java-keyword">new</span> WicketApplication());
@@ -169,7 +169,7 @@ function addJsClass() {
//assert rendered page class
tester.assertRenderedPage(HomePage.class);
}
-}</pre></div><p class="paragraph"/>The central class in a Wicket testing is <code>org.apache.wicket.util.tester.WicketTester</code>. This utility class provides a set of methods to render a component, click links, check if page contains a given component or a feedback message, and so on.<p class="paragraph"/>The basic test case shipped with <code>TestHomePage</code> illustrates how <code>WicketTester</code> is typically instantiated (inside method <code>setUp()</code>). In order to test our components, WicketTester needs to use an instance of <code>WebApplication</code>. Usually, we will use our application class as <code>WebApplication</code>, but we can also decide to build WicketTester invoking its no-argument constructor and letting it automatically build a mock web application (an instance of class <code>org.apache.wicket.mock.MockApplication</code>).<p class="paragraph"/>The code from <code>TestHomePage</code> introduces two basic methods to test our pages. The first is m
ethod <code>startPage</code> that renders a new instance of the given page class and sets it as current rendered page for WicketTester. The second method is assertRenderedPage which checks if the current rendered page is an instance of the given class. In this way if TestHomePage succeeds we are sure that page HomePage has been rendered without any problem. The last rendered page can be retrieved with method <code>getLastRenderedPage</code>.<p class="paragraph"/>That's only a taste of what <code>WicketTester</code> can do. In the next paragraphs we will see how it can be used to test every element that composes a Wicket page (links, models, behaviors, etc...).<p class="paragraph"/><h3>Testing links</h3><p class="paragraph"/>A click on a Wicket link can be simulated with method clickLink which takes in input the link component or the page-relative path to it.<p class="paragraph"/>To see an example of usage of clickLink, let's consider again project LifeCycleStagesRevisited. As we kno
w from chapter 5 the home page of the project alternately displays two different labels (âFirst labelâ and âSecond labelâ), swapping between them each time button "reload" is clicked. The code from its test case checks that label has actually changed after button "reload" has been pressed:<p class="paragraph"/><div class="code"><pre>//…
+}</pre></div><p class="paragraph"/>The central class in a Wicket testing is <code>org.apache.wicket.util.tester.WicketTester</code>. This utility class provides a set of methods to render a component, click links, check if page contains a given component or a feedback message, and so on.<p class="paragraph"/>The basic test case shipped with <code>TestHomePage</code> illustrates how <code>WicketTester</code> is typically instantiated (inside method <code>setUp()</code>). In order to test our components, WicketTester needs to use an instance of <code>WebApplication</code>. Usually, we will use our application class as <code>WebApplication</code>, but we can also decide to build WicketTester invoking its no-argument constructor and letting it automatically build a mock web application (an instance of class <code>org.apache.wicket.mock.MockApplication</code>).<p class="paragraph"/>The code from <code>TestHomePage</code> introduces two basic methods to test our pages. The first is m
ethod <code>startPage</code> that renders a new instance of the given page class and sets it as current rendered page for WicketTester. The second method is assertRenderedPage which checks if the current rendered page is an instance of the given class. In this way if TestHomePage succeeds we are sure that page HomePage has been rendered without any problem. The last rendered page can be retrieved with method <code>getLastRenderedPage</code>.<p class="paragraph"/>That's only a taste of what <code>WicketTester</code> can do. In the next paragraphs we will see how it can be used to test every element that composes a Wicket page (links, models, behaviors, etc...).<p class="paragraph"/><h3>Testing links</h3><p class="paragraph"/>A click on a Wicket link can be simulated with method <code>clickLink</code> which takes in input the link component or the page-relative path to it.<p class="paragraph"/>To see an example of usage of clickLink, let's consider again project <code>LifeCycleStagesR
evisited</code>. As we know from chapter 5 the home page of the project alternately displays two different labels (âFirst labelâ and âSecond labelâ), swapping between them each time button "reload" is clicked. The code from its test case checks that label has actually changed after button "reload" has been pressed:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void switchLabelTest(){
//start and render the test page
@@ -183,7 +183,7 @@ function addJsClass() {
//assert rendered label
tester.assertLabel(<span class="java-quote">"label"</span>, <span class="java-quote">"Second label"</span>);
}
-//...</pre></div><p class="paragraph"/>In the code above we have used clickLink to click on the "reload" button and force page to be rendered again. In addition, we have used also method assertLabel that checks if a given label contains the expected text.<p class="paragraph"/>By default clickLink assumes that AJAX is enabled on client side. To switch AJAX off we can use another version of this method that takes in input the path to the link component and a boolean flag that indicates if AJAX must be enabled (true) or not (false).<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/>In the code above we have used <code>clickLink</code> to click on the "reload" button and force page to be rendered again. In addition, we have used also method <code>assertLabel</code> that checks if a given label contains the expected text.<p class="paragraph"/>By default <code>clickLink</code> assumes that AJAX is enabled on client side. To switch AJAX off we can use another version of this method that takes in input the path to the link component and a boolean flag that indicates if AJAX must be enabled (true) or not (false).<p class="paragraph"/><div class="code"><pre>//…
//simulate a click on a button without AJAX support
tester.clickLink(<span class="java-quote">"reload"</span>, <span class="java-keyword">false</span>);
//...</pre></div><p class="paragraph"/><h3>Testing component status</h3><p class="paragraph"/>WicketTester provides also a set of methods to test the states of a component. They are:
@@ -191,7 +191,7 @@ tester.clickLink(<span class="java-q
<li><strong class="bold">assertEnabled(String path)/assertDisabled(String path)</strong>: they test if a component is enabled or not.</li>
<li><strong class="bold">assertVisible(String path)/assertInvisible(String path)</strong>: they test component visibility.</li>
<li><strong class="bold">assertRequired(String path)</strong>: checks if a form component is required.</li>
-</ul><p class="paragraph"/>In the test case from project CustomDatepickerAjax we used assertEnabled/assertDisabled to check if button "update" really disables our datepicker:<p class="paragraph"/><div class="code"><pre>//…
+</ul><p class="paragraph"/>In the test case from project <code>CustomDatepickerAjax</code> we used <code>assertEnabled</code>/<code>assertDisabled</code> to check if button "update" really disables our datepicker:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void testDisableDatePickerWithButton(){
//start and render the test page
@@ -203,7 +203,7 @@ tester.clickLink(<span class="java-q
//assert that datepicker is disabled
tester.assertDisabled(<span class="java-quote">"form:datepicker"</span>);
}
-//...</pre></div><p class="paragraph"/><h3>Testing components in isolation</h3><p class="paragraph"/>Method startComponent(Component) can be used to test a component in isolation without having to create a container page for this purpose. The target component is rendered and both its methods onInitialize() and onBeforeRender() are executed. In the test case from project CustomFormComponentPanel we used this method to check if our custom form component correctly renders its internal label:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/><h3>Testing components in isolation</h3><p class="paragraph"/>Method <code>startComponent(Component)</code> can be used to test a component in isolation without having to create a container page for this purpose. The target component is rendered and both its methods <code>onInitialize()</code> and <code>onBeforeRender()</code> are executed. In the test case from project <code>CustomFormComponentPanel</code> we used this method to check if our custom form component correctly renders its internal label:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void testCustomPanelContainsLabel(){
TemperatureDegreeField field = <span class="java-keyword">new</span> TemperatureDegreeField(<span class="java-quote">"field"</span>, Model.of(0.00));
@@ -212,7 +212,7 @@ tester.clickLink(<span class="java-q
tester.startComponent(field);
Assert.assertNotNull(field.get(<span class="java-quote">"mesuramentUnit"</span>));
}
-//...</pre></div><p class="paragraph"/>If test requires a page we can use startComponentInPage(Component) which automatically generates a page for our component.<p class="paragraph"/><h3>Testing the response</h3><p class="paragraph"/>WicketTester allows us to access to the last response generated during testing with method getLastResponse. The returned value is an instance of class MockHttpServletResponse that provides helper methods to extract informations from mocked request.<p class="paragraph"/>In the test case from project CustomResourceMounting we extract the text contained in the last response with method getDocument and we check if it is equal to the RSS feed used for the test:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/>If test requires a page we can use <code>startComponentInPage(Component)</code> which automatically generates a page for our component.<p class="paragraph"/><h3>Testing the response</h3><p class="paragraph"/><code>WicketTester</code> allows us to access to the last response generated during testing with method <code>getLastResponse</code>. The returned value is an instance of class MockHttpServletResponse that provides helper methods to extract informations from mocked request.<p class="paragraph"/>In the test case from project <code>CustomResourceMounting</code> we extract the text contained in the last response with method <code>getDocument</code> and we check if it is equal to the RSS feed used for the test:<p class="paragraph"/><div class="code"><pre>//…
@Test
<span class="java-keyword">public</span> void testMountedResourceResponse() <span class="java-keyword">throws</span> IOException, FeedException{tester.startResource(<span class="java-keyword">new</span> RSSProducerResource());
<span class="java-object">String</span> responseTxt = tester.getLastResponse().getDocument();
@@ -223,18 +223,18 @@ tester.clickLink(<span class="java-q
//the response and the RSS must be equal
Assert.assertEquals(responseTxt, outputStream.toString());
}
-//...</pre></div><p class="paragraph"/>To simulate a request to the custom resource we used method startResource which can be used also with resource references.<p class="paragraph"/><h3>Testing URLs</h3><p class="paragraph"/>WicketTester can be pointed to an arbitrary URL with method executeUrl(String url). This can be useful to test mounted pages, resources or request mappers:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/>To simulate a request to the custom resource we used method <code>startResource</code> which can be used also with resource references.<p class="paragraph"/><h3>Testing URLs</h3><p class="paragraph"/><code>WicketTester</code> can be pointed to an arbitrary URL with method <code>executeUrl(String url)</code>. This can be useful to test mounted pages, resources or request mappers:<p class="paragraph"/><div class="code"><pre>//…
//the resource was mapped at '/foo/bar'
tester.executeUrl(<span class="java-quote">"./foo/bar"</span>);
-//...</pre></div><p class="paragraph"/><h3>Testing AJAX components</h3><p class="paragraph"/>If our application uses AJAX to refresh components markup, we can test if AjaxRequestTarget contains a given component with WicketTester's method assertComponentOnAjaxResponse:<p class="paragraph"/><div class="code"><pre>//…
+//...</pre></div><p class="paragraph"/><h3>Testing AJAX components</h3><p class="paragraph"/>If our application uses AJAX to refresh components markup, we can test if <code>AjaxRequestTarget</code> contains a given component with <code>WicketTester</code>'s method <code>assertComponentOnAjaxResponse</code>:<p class="paragraph"/><div class="code"><pre>//…
//test <span class="java-keyword">if</span> AjaxRequestTarget contains a component (using its instance)
tester.assertComponentOnAjaxResponse(amountLabel);
//…
//test <span class="java-keyword">if</span> AjaxRequestTarget contains a component (using its path)
-tester.assertComponentOnAjaxResponse(<span class="java-quote">"pathToLabel:labelId"</span>);</pre></div><p class="paragraph"/>It's also possible to use method isComponentOnAjaxResponse(Component cmp) to know if a component has been added to AjaxRequestTarget:<p class="paragraph"/><div class="code"><pre>//…
+tester.assertComponentOnAjaxResponse(<span class="java-quote">"pathToLabel:labelId"</span>);</pre></div><p class="paragraph"/>It's also possible to use method <code>isComponentOnAjaxResponse(Component cmp)</code> to know if a component has been added to <code>AjaxRequestTarget</code>:<p class="paragraph"/><div class="code"><pre>//…
//test <span class="java-keyword">if</span> AjaxRequestTarget does NOT contain amountLabel
assertFalse(tester.isComponentOnAjaxResponse(amountLabel));
-//...</pre></div><p class="paragraph"/><h3>Testing AJAX events</h3><p class="paragraph"/>Behavior AjaxEventBehavior and its subclasses can be tested simulating AJAX events with WicketTester's method executeAjaxEvent(Component cmp, String event). Here is the sample code from project TestAjaxEventsExample:<p class="paragraph"/><strong class="bold">Home page code:</strong><p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {
+//...</pre></div><p class="paragraph"/><h3>Testing AJAX events</h3><p class="paragraph"/>Behavior <code>AjaxEventBehavior</code> and its subclasses can be tested simulating AJAX events with <code>WicketTester</code>'s method <code>executeAjaxEvent(Component cmp, String event)</code>. Here is the sample code from project <code>TestAjaxEventsExample</code>:<p class="paragraph"/><strong class="bold">Home page code:</strong><p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class HomePage <span class="java-keyword">extends</span> WebPage {
<span class="java-keyword">public</span> <span class="java-keyword">static</span> <span class="java-object">String</span> INIT_VALUE = <span class="java-quote">"Initial value"</span>;
<span class="java-keyword">public</span> <span class="java-keyword">static</span> <span class="java-object">String</span> OTHER_VALUE = <span class="java-quote">"Other value"</span>;<p class="paragraph"/> <span class="java-keyword">public</span> HomePage(<span class="java-keyword">final</span> PageParameters parameters) {
<span class="java-keyword">super</span>(parameters);
@@ -260,7 +260,7 @@ assertFalse(tester.isComponentOnAjaxResp
tester.executeAjaxEvent(<span class="java-quote">"label"</span>, <span class="java-quote">"click"</span>);
//test <span class="java-keyword">if</span> label has changed as expected
tester.assertLabel(<span class="java-quote">"label"</span>, HomePage.OTHER_VALUE);
-}</pre></div><p class="paragraph"/><h3>Testing AJAX behaviors</h3><p class="paragraph"/>To test a generic AJAX behavior we can simulate a request to it using WicketTester's method executeBehavior(AbstractAjaxBehavior behavior):<p class="paragraph"/><div class="code"><pre>//…
+}</pre></div><p class="paragraph"/><h3>Testing AJAX behaviors</h3><p class="paragraph"/>To test a generic AJAX behavior we can simulate a request to it using <code>WicketTester</code>'s method <code>executeBehavior(AbstractAjaxBehavior behavior)</code>:<p class="paragraph"/><div class="code"><pre>//…
AjaxFormComponentUpdatingBehavior ajaxBehavior =
<span class="java-keyword">new</span> AjaxFormComponentUpdatingBehavior(<span class="java-quote">"change"</span>){
@Override
@@ -272,7 +272,7 @@ component.add(ajaxBehavior);
//…
//execute AJAX behavior, i.e. onUpdate will be invoked
tester.executeBehavior(ajaxBehavior));
-//...</pre></div><p class="paragraph"/><h3>Using a custom servlet context</h3><p class="paragraph"/>In paragraph 13.9 we have seen how to configure our application to store resource files into a custom folder placed inside webapp root folder (see project CustomFolder4MarkupExample).<p class="paragraph"/>In order to write testing code for applications that use this kind of customization, we must tell WicketTester which folder to use as webapp root. This is necessary as under test environment we don't have any web server, hence it's impossible for WicketTester to retrieve this parameter from servlet context.<p class="paragraph"/>Webapp root folder can be passed to WicketTester's constructor as further parameter like we did in the test case of project CustomFolder4MarkupExample:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
+//...</pre></div><p class="paragraph"/><h3>Using a custom servlet context</h3><p class="paragraph"/>In paragraph 13.9 we have seen how to configure our application to store resource files into a custom folder placed inside webapp root folder (see project <code>CustomFolder4MarkupExample</code>).<p class="paragraph"/>In order to write testing code for applications that use this kind of customization, we must tell <code>WicketTester</code> which folder to use as webapp root. This is necessary as under test environment we don't have any web server, hence it's impossible for <code>WicketTester</code> to retrieve this parameter from servlet context.<p class="paragraph"/>Webapp root folder can be passed to <code>WicketTester</code>'s constructor as further parameter like we did in the test case of project <code>CustomFolder4MarkupExample</code>:<p class="paragraph"/><div class="code"><pre><span class="java-keyword">public</span> class TestHomePage{
<span class="java-keyword">private</span> WicketTester tester;<p class="paragraph"/> @Before
<span class="java-keyword">public</span> void setUp(){
//build the path to webapp root folder
@@ -281,7 +281,7 @@ tester.executeBehavior(ajaxBehavior));
}
//test methods…
}</pre></div><p class="paragraph"/><blockquote class="note">
-After a test method has been executed, we may need to clear any possible side effect occurred to the Application and Session objects. This can be done invoking WicketTester's method destroy():<p class="paragraph"/><div class="code"><pre>@After
+After a test method has been executed, we may need to clear any possible side effect occurred to the <code>Application</code> and <code>Session</code> objects. This can be done invoking <code>WicketTester</code>'s method <code>destroy()</code>:<p class="paragraph"/><div class="code"><pre>@After
<span class="java-keyword">public</span> void tearDown(){
//clear any side effect occurred during test.
tester.destroy();