Java Reference
In-Depth Information
<a4j:commandButton value="Cancel" reRender="rep"
action="#{albumDetailsBean.cancel}"/>
</rich:panel>
<rich:spacer height="1" />
<rich:panel bodyClass="rich-laguna-panel-no-header">
<h:outputText id="rep" name="rep"
value="#{albumDetailsBean.status}" />
</rich:panel>
</td>
...
Although we already covered this page in listing 15.7, let's review it briefly. In our JSP ,
we use the RichFaces and Ajax4jsf tag libraries to implement the desired Ajax behavior.
We start by defining two rich:panel components B and E to hold the rest of our
components. In the first panel, we put a commandButton to submit the form to the bean
specified in the action parameter C . The command button also submits a status
parameter to the bean D . Notice the reRender parameter of the commandButton . This
attribute specifies an ID of another component that needs to be rerendered. In our
case, we specify an outputText F . You can see the screen for this JSP in figure 15.2.
Now let's implement some tests for this Ajax scenario. JSFU nit relies heavily on the
HtmlUnit headless browser. You can use the JSFClientSession and click anything,
regardless of the fact that the request to the bean will be submitted via JavaScript. The
code for these tests is shown in listing 15.12.
E
F
Listing 15.12
Testing the Ajax components from the album_details.jsp
[...]
public class TestPurchaseAlbum extends ServletTestCase {
public static Test suite() {
return new TestSuite( TestPurchaseAlbum.class );
}
public void testCommandButton() throws IOException, SAXException {
JSFSession jsfSession = new JSFSession( "/album_details.jsp" );
B
C
D
JSFServerSession server = jsfSession.getJSFServerSession();
JSFClientSession client = jsfSession.getJSFClientSession();
E
client.click( "PurchaseButton" );
Object userBeanValue = server.getManagedBeanValue(
"#{albumDetailsBean.status}");
F
G
H
assertEquals( "Successfully purchased: ", userBeanValue );
String spanContent =((HtmlPage) client.getContentPage())
.getElementsByTagName( "span" ).item( 0 ).getTextContent();
assertEquals(spanContent, "Successfully purchased:");
}
}
As usual, we start the implementation by declaring a test case by extending the Servlet-
TestCase B . In the test method C we obtain a JSFServerSession object and extract
the JSFServerSession/JSFClientSession D . Then we click the "PurchaseButton"
I
 
 
 
Search WWH ::




Custom Search