This documentation is for an old version of fiftyfive-wicket (2.0.9).


fiftyfive.wicket.test
Class WicketTestUtils

java.lang.Object
  extended by fiftyfive.wicket.test.WicketTestUtils

public abstract class WicketTestUtils
extends Object

Helper functions and assertions for easier testing of Wicket pages and components. Care has been taken to ensure that these helpers automatically work with both XHTML and HTML5 documents. In some cases there are separate methods to handle the two cases.

See Also:
startComponentWithHtml(), startComponentWithXHtml()

Constructor Summary
WicketTestUtils()
           
 
Method Summary
static void assertValidMarkup(WicketTester tester)
          Assert that the last rendered page has a content-type of text/html and is valid markup.
static void assertValidMarkup(WicketTester tester, int linesContext)
          Assert that the last rendered page has a content-type of text/html and is valid markup.
static void assertXPath(int count, WicketTester wt, String expr)
          Asserts that exactly count number of instances of a given XPath expression can be found in the most recently rendered Wicket page.
static void assertXPath(WicketTester wt, String expr)
          Asserts that an XPath expression can be found in the most recently rendered Wicket page.
static Node markupAsDOM(WicketTester tester)
          Parses the most recently rendered Wicket page into an XML Document object.
static void setDocumentBuilderFactoryClassName(String className)
          Change the DocumentBuilderFactory implementation used by the DOM and XPath helper methods of this class.
static void setTransformerFactoryClassName(String className)
          Change the TransformerFactory implementation used by the DOM and XPath helper methods of this class.
static void startComponentWithHtml(WicketTester tester, Component c, String markup)
          Renders a component using a snippet of HTML5 markup.
static void startComponentWithHtml(WicketTester tester, PageParameters parameters, Component c, String markup)
          A variation of startComponentWithHtml() that accepts PageParameters.
static void startComponentWithXHtml(WicketTester tester, Component c, String markup)
          Renders a component using a snippet of XHTML 1.0 Strict markup.
static void startComponentWithXHtml(WicketTester tester, PageParameters parameters, Component c, String markup)
          A variation of startComponentWithXHtml() that accepts PageParameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WicketTestUtils

public WicketTestUtils()
Method Detail

setDocumentBuilderFactoryClassName

public static void setDocumentBuilderFactoryClassName(String className)
Change the DocumentBuilderFactory implementation used by the DOM and XPath helper methods of this class. The default JRE-provided class should be sufficient: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.


setTransformerFactoryClassName

public static void setTransformerFactoryClassName(String className)
Change the TransformerFactory implementation used by the DOM and XPath helper methods of this class. The default JRE-provided class should be sufficient: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.


markupAsDOM

public static Node markupAsDOM(WicketTester tester)
                        throws SAXException,
                               ParserConfigurationException,
                               TransformerException
Parses the most recently rendered Wicket page into an XML Document object. Uses TagSoup under the hood to parse even the sloppiest HTML. You can then use things like xpath expressions against the document.

Returns:
The root Node of the resulting DOM
Throws:
SAXException
ParserConfigurationException
TransformerException

assertXPath

public static void assertXPath(WicketTester wt,
                               String expr)
                        throws IOException,
                               SAXException,
                               ParserConfigurationException,
                               TransformerException,
                               XPathExpressionException
Asserts that an XPath expression can be found in the most recently rendered Wicket page. Uses TagSoup under the hood to parse even the sloppiest HTML into XML that can be queryied by XPath. It is therefore possible that the XPath assertion will pass, even though assertValidMarkup() fails.

Throws:
IOException
SAXException
ParserConfigurationException
TransformerException
XPathExpressionException

assertXPath

public static void assertXPath(int count,
                               WicketTester wt,
                               String expr)
                        throws IOException,
                               SAXException,
                               ParserConfigurationException,
                               TransformerException,
                               XPathExpressionException
Asserts that exactly count number of instances of a given XPath expression can be found in the most recently rendered Wicket page. Uses TagSoup under the hood to parse even the sloppiest HTML into XML that can be queryied by XPath. It is therefore possible that the XPath assertion will pass, even though assertValidMarkup() fails.

Throws:
IOException
SAXException
ParserConfigurationException
TransformerException
XPathExpressionException

assertValidMarkup

public static void assertValidMarkup(WicketTester tester)
                              throws IOException
Assert that the last rendered page has a content-type of text/html and is valid markup. Will autodetect whether the document is HTML5 or XHTML and use the appropriate validator. An HTML5 document must start with <!DOCTYPE html>, anything else is assumed to be XHTML.

Parameters:
tester - A WicketTester object that has just rendered a page.
Throws:
IOException

assertValidMarkup

public static void assertValidMarkup(WicketTester tester,
                                     int linesContext)
                              throws IOException
Assert that the last rendered page has a content-type of text/html and is valid markup. Will autodetect whether the document is HTML5 or XHTML and use the appropriate validator. An HTML5 document must start with <!DOCTYPE html>, anything else is assumed to be XHTML.

Parameters:
tester - A WicketTester object that has just rendered a page.
linesContext - The number of lines of context to include around each validation error.
Throws:
IOException

startComponentWithXHtml

public static void startComponentWithXHtml(WicketTester tester,
                                           Component c,
                                           String markup)
Renders a component using a snippet of XHTML 1.0 Strict markup. Example:
 startComponentWithXHtml(
     tester,
     new Label("label", "Hello, world!),
     "<span wicket:id=\"label\">replaced by Wicket</span>"
 );

This method will place the component in a simple XHTML Page and render it using the normal WicketTester request/response. In the above example, the rendered output will be:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
   <title>untitled</title>
 </head>
 <body>
 <span wicket:id="label">Hello, world!</span>
 </body>
 </html>

You can then use helper method like assertXPath or WicketTester.assertContains(String) to verify the component rendered as expected.


startComponentWithXHtml

public static void startComponentWithXHtml(WicketTester tester,
                                           PageParameters parameters,
                                           Component c,
                                           String markup)
A variation of startComponentWithXHtml() that accepts PageParameters. These page parameters are passed to the page that wraps the component under test.

Since:
2.0.4

startComponentWithHtml

public static void startComponentWithHtml(WicketTester tester,
                                          Component c,
                                          String markup)
Renders a component using a snippet of HTML5 markup. Example:
 startComponentWithHtml(
     tester,
     new Label("label", "Hello, world!),
     "<span wicket:id=\"label\">replaced by Wicket</span>"
 );

This method will place the component in a simple HTML5 Page and render it using the normal WicketTester request/response. In the above example, the rendered output will be:

 <!DOCTYPE html>
 <html>
 <head>
   <title>untitled</title>
 </head>
 <body>
 <span wicket:id="label">Hello, world!</span>
 </body>
 </html>

You can then use helper method like assertXPath or WicketTester.assertContains(String) to verify the component rendered as expected.


startComponentWithHtml

public static void startComponentWithHtml(WicketTester tester,
                                          PageParameters parameters,
                                          Component c,
                                          String markup)
A variation of startComponentWithHtml() that accepts PageParameters. These page parameters are passed to the page that wraps the component under test.

Since:
2.0.4


Copyright © 2011 55 Minutes. All Rights Reserved.