Package org.apache.tapestry5.test
Class PageTester
- java.lang.Object
- 
- org.apache.tapestry5.test.PageTester
 
- 
 public class PageTester extends Object This class is used to run a Tapestry app in a single-threaded, in-process testing environment. You can ask it to render a certain page and check the DOM object created. You can also ask it to click on a link element in the DOM object to get the next page. Because no servlet container is required, it is very fast and you can directly debug into your code in your IDE. When using the PageTester in your tests, you should add theorg.apache.tapestry:tapestry-test-constantsmodule as a dependency.
- 
- 
Field SummaryFields Modifier and Type Field Description static StringDEFAULT_CONTEXT_PATH
 - 
Constructor SummaryConstructors Constructor Description PageTester(String appPackage, String appName)Initializes a PageTester without overriding any services and assuming that the context root is in src/main/webapp.PageTester(String appPackage, String appName, String contextPath, Class... moduleClasses)Initializes a PageTester that acts as a browser and a servlet container to test drive your Tapestry pages.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description DocumentclickLink(Element linkElement)Simulates a click on a link.TestableResponseclickLinkAndReturnResponse(Element linkElement)Simulates a click on a link.DocumentclickSubmit(Element submitButton, Map<String,String> fieldValues)Simulates a submission of the form by clicking the specified submit button.TestableResponseclickSubmitAndReturnResponse(Element submitButton, Map<String,String> fieldValues)Simulates a submission of the form by clicking the specified submit button.RegistrygetRegistry()Returns the Registry that was created for the application.<T> TgetService(Class<T> serviceInterface)Allows a service to be retrieved via its service interface.protected ModuleDef[]provideExtraModuleDefs()Overridden in subclasses to provide additional module definitions beyond those normally located.DocumentrenderPage(String pageName)Renders a page specified by its name.TestableResponserenderPageAndReturnResponse(String pageName)Renders a page specified by its name and returns the response.voidsetPreferedLanguage(Locale preferedLanguage)Sets the simulated browser's preferred language, i.e., the value returned fromRequest.getLocale().voidsetupRequestFromURI(String URI)voidshutdown()Invoke this method when done using the PageTester; it shuts down the internalRegistryused by the tester.DocumentsubmitForm(Element form, Map<String,String> parameters)Simulates a submission of the form specified.TestableResponsesubmitFormAndReturnResponse(Element form, Map<String,String> parameters)Simulates a submission of the form specified.
 
- 
- 
- 
Field Detail- 
DEFAULT_CONTEXT_PATHpublic static final String DEFAULT_CONTEXT_PATH - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
PageTesterpublic PageTester(String appPackage, String appName) Initializes a PageTester without overriding any services and assuming that the context root is in src/main/webapp.
 - 
PageTesterpublic PageTester(String appPackage, String appName, String contextPath, Class... moduleClasses) Initializes a PageTester that acts as a browser and a servlet container to test drive your Tapestry pages.- Parameters:
- appPackage- The same value you would specify using the tapestry.app-package context parameter. As this testing environment is not run in a servlet container, you need to specify it.
- appName- The same value you would specify as the filter name. It is used to form the name of the module class for your app. If you don't have one, pass an empty string.
- contextPath- The path to the context root so that Tapestry can find the templates (if they're put there).
- moduleClasses- Classes of additional modules to load
 
 
- 
 - 
Method Detail- 
provideExtraModuleDefsprotected ModuleDef[] provideExtraModuleDefs() Overridden in subclasses to provide additional module definitions beyond those normally located. This implementation returns an empty array.
 - 
shutdownpublic void shutdown() Invoke this method when done using the PageTester; it shuts down the internalRegistryused by the tester.
 - 
getRegistrypublic Registry getRegistry() Returns the Registry that was created for the application.
 - 
getServicepublic <T> T getService(Class<T> serviceInterface) Allows a service to be retrieved via its service interface. UsegetRegistry()for more complicated queries.- Parameters:
- serviceInterface- used to select the service
 
 - 
renderPagepublic Document renderPage(String pageName) Renders a page specified by its name.- Parameters:
- pageName- The name of the page to be rendered.
- Returns:
- The DOM created. Typically you will assert against it.
 
 - 
renderPageAndReturnResponsepublic TestableResponse renderPageAndReturnResponse(String pageName) Renders a page specified by its name and returns the response.- Parameters:
- pageName- The name of the page to be rendered.
- Returns:
- The response object to assert against
- Since:
- 5.2.3
 
 - 
clickLinkpublic Document clickLink(Element linkElement) Simulates a click on a link.- Parameters:
- linkElement- The Link object to be "clicked" on.
- Returns:
- The DOM created. Typically you will assert against it.
 
 - 
clickLinkAndReturnResponsepublic TestableResponse clickLinkAndReturnResponse(Element linkElement) Simulates a click on a link.- Parameters:
- linkElement- The Link object to be "clicked" on.
- Returns:
- The response object to assert against
- Since:
- 5.2.3
 
 - 
setupRequestFromURIpublic void setupRequestFromURI(String URI) 
 - 
submitFormpublic Document submitForm(Element form, Map<String,String> parameters) Simulates a submission of the form specified. The caller can specify values for the form fields, which act as overrides on the values stored inside the elements.- Parameters:
- form- the form to be submitted.
- parameters- the query parameter name/value pairs
- Returns:
- The DOM created. Typically you will assert against it.
 
 - 
submitFormAndReturnResponsepublic TestableResponse submitFormAndReturnResponse(Element form, Map<String,String> parameters) Simulates a submission of the form specified. The caller can specify values for the form fields, which act as overrides on the values stored inside the elements.- Parameters:
- form- the form to be submitted.
- parameters- the query parameter name/value pairs
- Returns:
- The response object to assert against.
- Since:
- 5.2.3
 
 - 
clickSubmitpublic Document clickSubmit(Element submitButton, Map<String,String> fieldValues) Simulates a submission of the form by clicking the specified submit button. The caller can specify values for the form fields.- Parameters:
- submitButton- the submit button to be clicked.
- fieldValues- the field values keyed on field names.
- Returns:
- The DOM created. Typically you will assert against it.
 
 - 
clickSubmitAndReturnResponsepublic TestableResponse clickSubmitAndReturnResponse(Element submitButton, Map<String,String> fieldValues) Simulates a submission of the form by clicking the specified submit button. The caller can specify values for the form fields.- Parameters:
- submitButton- the submit button to be clicked.
- fieldValues- the field values keyed on field names.
- Returns:
- The response object to assert against.
- Since:
- 5.2.3
 
 - 
setPreferedLanguagepublic void setPreferedLanguage(Locale preferedLanguage) Sets the simulated browser's preferred language, i.e., the value returned fromRequest.getLocale().- Parameters:
- preferedLanguage- preferred language setting
 
 
- 
 
-