Java Doc for WicketTester.java in  » J2EE » wicket » wicket » util » tester » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » wicket » wicket.util.tester 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


wicket.protocol.http.MockWebApplication
   wicket.util.tester.WicketTester

All known Subclasses:   wicket.util.tester.apps_1.MyMockApplication,  wicket.resource.DummyApplication,  wicket.properties.MyApplication,  wicket.properties.MyTesterApplication,
WicketTester
public class WicketTester extends MockWebApplication (Code)
A helper to ease unit testing of Wicket applications without the need for a servlet container. To start a test, we can use either startPage() or startPanel():
 // production page  
 public class MyPage extends WebPage
 {
 public MyPage()
 {
 add(new Label("myMessage", "Hello!"));
 add(new Link("toYourPage")
 {
 public void onClick()
 {
 setResponsePage(new YourPage("Hi!"));
 }
 });
 }
 }
 
 // test code
 private WicketTester tester;
 public void setUp()
 {
 tester = new WicketTester();
 }
 public void testRenderMyPage()
 {
 //start and render the test page
 tester.startPage(MyPage.class);
 //assert rendered page class
 tester.assertRenderedPage(MyPage.class);
 //assert rendered label component 
 tester.assertLabel("myMessage", "Hello!");
 }
 
Above example is straight forward: start MyPage.class and assert Label it rendered. Next, we try to navigate through link:
 // production page  
 public class YourPage extends WebPage
 {
 public YourPage(String message)
 {
 add(new Label("yourMessage", message));
 info("Wicket Rocks ;-)");
 }
 }
 //test code
 public void testLinkToYourPage()
 {
 tester.startPage(MyPage.class);
 //click link and render
 tester.clickLink("toYourPage");
 tester.assertRenderedPage(YourPage.class);
 tester.assertLabel("yourMessage", "Hi!");
 }
 
tester.clickLink(path); will simulate user click on the component (in this case, it's a Link) and render the response page YourPage. Ok, unit test of MyPage is completed. Now we test YourPage standalone:
 //test code
 public void testRenderYourPage()
 {
 // provide page instance source for WicketTester
 tester.startPage(new TestPageSource()
 {
 public Page getTestPage()
 {
 return new YourPage("mock message");
 }
 });
 tester.assertRenderedPage(YourPage.class);
 tester.assertLabel("yourMessage", "mock message");
 // assert feedback messages in INFO Level 
 tester.assertInfoMessages(new String[] { "Wicket Rocks ;-)" });
 }
 
Instead of tester.startPage(pageClass), we define a wicket.util.tester.ITestPageSource to provide testing page instance for WicketTester. This is necessary because YourPage uses a custom constructor, which is very common for transfering model data, can not be instansiated by reflection. Finally, we use assertInfoMessages to assert there is a feedback message "Wicket Rocks ;-)" in INFO level. TODO General: Example usage of FormTester
author:
   Ingram Chen
author:
   Juergen Donnerstag
author:
   Frank Bille



Constructor Summary
public  WicketTester()
    
public  WicketTester(String path)
     create a WicketTester to help unit testing.
Parameters:
  path - The absolute path on disk to the web application contents(e.g.

Method Summary
public  voidassertComponent(String path, Class expectedComponentClass)
    
public  voidassertComponentOnAjaxResponse(Component component)
     Test that a component has been added to a AjaxRequestTarget, using AjaxRequestTarget.addComponent(Component) .
public  voidassertContains(String pattern)
     assert the content of last rendered page contains(matches) regex pattern.
public  voidassertErrorMessages(String[] expectedErrorMessages)
    
public  voidassertInfoMessages(String[] expectedInfoMessages)
    
public  voidassertInvisible(String path)
     assert component invisible.
public  voidassertLabel(String path, String expectedLabelText)
     assert the text of Label component.
public  voidassertListView(String path, List expectedList)
    
public  voidassertNoErrorMessage()
    
public  voidassertNoInfoMessage()
    
public  voidassertPageLink(String path, Class expectedPageClass)
     assert PageLink link to page class.
public  voidassertRenderedPage(Class expectedReneredPageClass)
    
public  voidassertVisible(String path)
     assert component visible.
public  voidclickLink(String path)
     Click the Link in the last rendered Page.
public  voidclickLink(String path, boolean isAjax)
     Click the Link in the last rendered Page.

This method also works for AjaxLink , AjaxFallbackLink and AjaxSubmitLink .

On AjaxLinks and AjaxFallbackLinks the onClick method is invoked with a valid AjaxRequestTarget.

public  voiddebugComponentTrees()
    
public  voiddebugComponentTrees(String filter)
     Dump the component trees to log.
public  voiddumpPage()
    
public  voidexecuteAjaxEvent(String componentPath, String event)
     Simulate that an AJAX event has been fired.
See Also:   WicketTester.executeAjaxEvent(Component,String)
since:
   1.2.3
Parameters:
  componentPath - The component path.
Parameters:
  event - The event which we simulate is fired.
public  voidexecuteAjaxEvent(Component component, String event)
     Simulate that an AJAX event has been fired.
public  ComponentgetComponentFromLastRenderedPage(String path)
     Gets the component with the given path from last rendered page.
public  ListgetMessages(int level)
     get feedback messages
Parameters:
  level - level of feedback message, ex.FeedbackMessage.DEBUG or FeedbackMessage.INFO..
public  TagTestergetTagById(String id)
     Get a TagTester based on an dom id.
public  TagTestergetTagByWicketId(String wicketId)
     Get a TagTester based on a wicket:id.
public  FormTesternewFormTester(String path)
     create a FormTester for the form at path, and fill all child wicket.markup.html.form.FormComponent s with blank String initially.
public  FormTesternewFormTester(String path, boolean fillBlankString)
     create a FormTester for the form at path.
Parameters:
  path - path to Form component
Parameters:
  fillBlankString - specify whether fill all childwicket.markup.html.form.FormComponents withblankString initially.
public  voidsetParameterForNextRequest(String componentPath, Object value)
     Sets a parameter for the component with the given path to be used with the next request.
final public  PagestartPage(ITestPageSource testPageSource)
     Render a page defined in TestPageSource.
final public  PagestartPage(Page page)
    
final public  PagestartPage(Class pageClass)
     Render a page from its default constructor.
final public  PanelstartPanel(TestPanelSource testPanelSource)
     Render a panel defined in TestPanelSource.
final public  PanelstartPanel(Class panelClass)
     Render a panel from Panel(String id) constructor.
public  voidsubmitForm(String path)
     submit the Form in the last rendered Page.


Constructor Detail
WicketTester
public WicketTester()(Code)
create WicketTester with null path
See Also:   WicketTester.WicketTester(String)



WicketTester
public WicketTester(String path)(Code)
create a WicketTester to help unit testing.
Parameters:
  path - The absolute path on disk to the web application contents(e.g. war root) - may be null
See Also:   wicket.protocol.http.MockWebApplication.MockWebApplication(String)




Method Detail
assertComponent
public void assertComponent(String path, Class expectedComponentClass)(Code)
assert component class
Parameters:
  path - path to component
Parameters:
  expectedComponentClass - expected component class



assertComponentOnAjaxResponse
public void assertComponentOnAjaxResponse(Component component)(Code)
Test that a component has been added to a AjaxRequestTarget, using AjaxRequestTarget.addComponent(Component) . This method actually tests that a component is on the AJAX response sent back to the client.

PLEASE NOTE! This method doesn't actually insert the component in the client DOM tree, using javascript. But it shouldn't be needed because you have to trust that the Wicket Ajax Javascript just works.
Parameters:
  component - The component to test whether it's on the response.




assertContains
public void assertContains(String pattern)(Code)
assert the content of last rendered page contains(matches) regex pattern.
Parameters:
  pattern - reqex pattern to match



assertErrorMessages
public void assertErrorMessages(String[] expectedErrorMessages)(Code)
assert error feedback messages
Parameters:
  expectedErrorMessages - expected error messages



assertInfoMessages
public void assertInfoMessages(String[] expectedInfoMessages)(Code)
assert info feedback message
Parameters:
  expectedInfoMessages - expected info messages



assertInvisible
public void assertInvisible(String path)(Code)
assert component invisible.
Parameters:
  path - path to component



assertLabel
public void assertLabel(String path, String expectedLabelText)(Code)
assert the text of Label component.
Parameters:
  path - path to Label component
Parameters:
  expectedLabelText - expected label text



assertListView
public void assertListView(String path, List expectedList)(Code)
assert the model of ListView use expectedList
Parameters:
  path - path to ListView component
Parameters:
  expectedList - expected list in the model of ListView



assertNoErrorMessage
public void assertNoErrorMessage()(Code)
assert no error feedback messages



assertNoInfoMessage
public void assertNoInfoMessage()(Code)
assert no info feedback messages



assertPageLink
public void assertPageLink(String path, Class expectedPageClass)(Code)
assert PageLink link to page class.
Parameters:
  path - path to PageLink component
Parameters:
  expectedPageClass - expected page class to link



assertRenderedPage
public void assertRenderedPage(Class expectedReneredPageClass)(Code)
assert last rendered Page class
Parameters:
  expectedReneredPageClass - expected class of last renered page



assertVisible
public void assertVisible(String path)(Code)
assert component visible.
Parameters:
  path - path to component



clickLink
public void clickLink(String path)(Code)
Click the Link in the last rendered Page.

Simulate that AJAX is enabled.
See Also:   WicketTester.clickLink(Stringboolean)
Parameters:
  path - Click the Link in the last rendered Page.




clickLink
public void clickLink(String path, boolean isAjax)(Code)
Click the Link in the last rendered Page.

This method also works for AjaxLink , AjaxFallbackLink and AjaxSubmitLink .

On AjaxLinks and AjaxFallbackLinks the onClick method is invoked with a valid AjaxRequestTarget. In that way you can test the flow of your application when using AJAX.

When clicking an AjaxSubmitLink the form, which the AjaxSubmitLink is attached to is first submitted, and then the onSubmit method on AjaxSubmitLink is invoked. If you have changed some values in the form during your test, these will also be submitted. This should not be used as a replacement for the FormTester to test your forms. It should be used to test that the code in your onSubmit method in AjaxSubmitLink actually works.

This method is also able to simulate that AJAX (javascript) is disabled on the client. This is done by setting the isAjax parameter to false. If you have an AjaxFallbackLink you can then check that it doesn't fail when invoked as a normal link.
Parameters:
  path - path to Link component
Parameters:
  isAjax - Whether to simulate that AJAX (javascript) is enabled or not.If it's false then AjaxLink and AjaxSubmitLink will fail,since it wouldn't work in real life. AjaxFallbackLink will beinvoked with null as the AjaxRequestTarget parameter.




debugComponentTrees
public void debugComponentTrees()(Code)
dump component tree



debugComponentTrees
public void debugComponentTrees(String filter)(Code)
Dump the component trees to log.
Parameters:
  filter - Show only the components, which path contains thefilterstring.



dumpPage
public void dumpPage()(Code)
dump the source of last rendered page



executeAjaxEvent
public void executeAjaxEvent(String componentPath, String event)(Code)
Simulate that an AJAX event has been fired.
See Also:   WicketTester.executeAjaxEvent(Component,String)
since:
   1.2.3
Parameters:
  componentPath - The component path.
Parameters:
  event - The event which we simulate is fired. If the event is null,the test will fail.



executeAjaxEvent
public void executeAjaxEvent(Component component, String event)(Code)
Simulate that an AJAX event has been fired. You add an AJAX event to a component by using:
 ...
 component.add(new AjaxEventBehavior("ondblclick") {
 public void onEvent(AjaxRequestTarget) {
 // Do something.
 }
 });
 ...
 
You can then test that the code inside onEvent actually does what it's supposed to, using the WicketTester:
 ...
 tester.executeAjaxEvent(component, "ondblclick");
 // Test that the code inside onEvent is correct.
 ...
 
This also works with AjaxFormSubmitBehavior, where it will "submit" the form before executing the command.

PLEASE NOTE! This method doesn't actually insert the component in the client DOM tree, using javascript.
Parameters:
  component - The component which has the AjaxEventBehavior we wan't totest. If the component is null, the test will fail.
Parameters:
  event - The event which we simulate is fired. If the event is null,the test will fail.




getComponentFromLastRenderedPage
public Component getComponentFromLastRenderedPage(String path)(Code)
Gets the component with the given path from last rendered page. This method fails in case the component couldn't be found, and it will return null if the component was found, but is not visible.
Parameters:
  path - Path to component The component at the path
See Also:   wicket.MarkupContainer.get(String)



getMessages
public List getMessages(int level)(Code)
get feedback messages
Parameters:
  level - level of feedback message, ex.FeedbackMessage.DEBUG or FeedbackMessage.INFO.. etc List list of messages (in String)
See Also:   FeedbackMessage



getTagById
public TagTester getTagById(String id)(Code)
Get a TagTester based on an dom id. If more components exists with the same id in the markup only the first one is returned.
Parameters:
  id - The dom id to search for. The TagTester for the tag which has the given dom id.



getTagByWicketId
public TagTester getTagByWicketId(String wicketId)(Code)
Get a TagTester based on a wicket:id. If more components exists with the same wicket:id in the markup only the first one is returned.
Parameters:
  wicketId - The wicket:id to search for. The TagTester for the tag which has the given wicket:id.



newFormTester
public FormTester newFormTester(String path)(Code)
create a FormTester for the form at path, and fill all child wicket.markup.html.form.FormComponent s with blank String initially.
Parameters:
  path - path to Form component FormTester A FormTester instance for testing form
See Also:   WicketTester.newFormTester(String,boolean)



newFormTester
public FormTester newFormTester(String path, boolean fillBlankString)(Code)
create a FormTester for the form at path.
Parameters:
  path - path to Form component
Parameters:
  fillBlankString - specify whether fill all childwicket.markup.html.form.FormComponents withblankString initially. FormTester A FormTester instance for testing form
See Also:   FormTester



setParameterForNextRequest
public void setParameterForNextRequest(String componentPath, Object value)(Code)
Sets a parameter for the component with the given path to be used with the next request. NOTE: this method only works when a page was rendered first.
Parameters:
  componentPath - path of the component
Parameters:
  value - the parameter value to set



startPage
final public Page startPage(ITestPageSource testPageSource)(Code)
Render a page defined in TestPageSource. This usually used when a page does not have default consturctor. For example, a ViewBook page requires a Book instance:
 tester.startPage(new TestPageSource()
 {
 public Page getTestPage()
 {
 Book mockBook = new Book("myBookName");
 return new ViewBook(mockBook);
 }
 });
 

Parameters:
  testPageSource - a page factory that creating test page instance Page rendered page



startPage
final public Page startPage(Page page)(Code)
Render the page
Parameters:
  page - The page rendered



startPage
final public Page startPage(Class pageClass)(Code)
Render a page from its default constructor.
Parameters:
  pageClass - a test page class with default constructor Page Rendered Page



startPanel
final public Panel startPanel(TestPanelSource testPanelSource)(Code)
Render a panel defined in TestPanelSource. The usage is similar with WicketTester.startPage(ITestPageSource) . Please note that testing panel must use supplied panelId as component id.
 tester.startPanel(new TestPanelSource()
 {
 public Panel getTestPanel(String panelId)
 {
 MyData mockMyData = new MyData();
 return new MyPanel(panelId, mockMyData);
 }
 });
 

Parameters:
  testPanelSource - a panel factory that creating test panel instance Panel rendered panel



startPanel
final public Panel startPanel(Class panelClass)(Code)
Render a panel from Panel(String id) constructor.
Parameters:
  panelClass - a test panel class with Panel(String id)constructor Panel rendered panel



submitForm
public void submitForm(String path)(Code)
submit the Form in the last rendered Page.
Parameters:
  path - path to Form component



Methods inherited from wicket.protocol.http.MockWebApplication
public WebRequestCycle createRequestCycle()(Code)(Java Doc)
public Class getHomePage()(Code)(Java Doc)
public Page getLastRenderedPage()(Code)(Java Doc)
public Map getParametersForNextRequest()(Code)(Java Doc)
public Page getPreviousRenderedPage()(Code)(Java Doc)
public ServletContext getServletContext()(Code)(Java Doc)
public MockHttpServletRequest getServletRequest()(Code)(Java Doc)
public MockHttpServletResponse getServletResponse()(Code)(Java Doc)
public MockHttpSession getServletSession()(Code)(Java Doc)
public WebRequest getWicketRequest()(Code)(Java Doc)
public WebResponse getWicketResponse()(Code)(Java Doc)
public WebSession getWicketSession()(Code)(Java Doc)
protected ISessionStore newSessionStore()(Code)(Java Doc)
public void processRequestCycle(Component component)(Code)(Java Doc)
public void processRequestCycle()(Code)(Java Doc)
public void processRequestCycle(WebRequestCycle cycle)(Code)(Java Doc)
public void setHomePage(Class clazz)(Code)(Java Doc)
public void setParametersForNextRequest(Map parametersForNextRequest)(Code)(Java Doc)
public void setupRequestAndResponse()(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.