wheel.testing
Class WheelTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by wheel.testing.WheelTestCase
All Implemented Interfaces:
junit.framework.Test

public abstract class WheelTestCase
extends junit.framework.TestCase

A JUnit-test case to extend your own tests when testing wheel components and pages. Example:

 public class MyPageTest extends WheelTestCase {
  public void testSomething() {
      //first create an instance of the page/component you want to test
      MyPage page = new MyPage();

      //possibly set some properties to initialize state etc.
      page.setPropertyX(...);

      //set the component on the "test bench"
      setComponent(page);

      //trigger rendering
      render();

      //then do assertions with normal JUnit-assertions or then ones provided by WheelTestCase
      assertXPath("desired output", "//h1[@id='componentId']");
      assertPresent("//div[@id='componentId']");
  }
 }
 

Author:
Henri Frilund

Constructor Summary
WheelTestCase()
           
 
Method Summary
protected  void addFormField(java.lang.String name, java.lang.String value)
          Adds field value to the mock form.
protected  void assertPresent(java.lang.String xpathExpression)
          Checks that an element is present in the output html.
protected  void assertXpath(java.lang.String expectedValue, java.lang.String xpathExpression)
          Enables to make Xpath-based assertions on the html-code created when the component was rendered with a call to render() method.
protected  void createForm(java.lang.String id)
          Creates a mock form where you can manually set values and then submit it to the component.
protected  StandaloneComponent getPage()
          Returns the Page being used.
protected  void render()
          Causes an immidiate rendering of the component.
protected  void reset()
          Resets the html-output from the previous rendering.
protected  void setBasePackageForPages(java.lang.String basePackage)
          By default the basePackage will be "wheel.testing" for components that are not Pages and the package-part of the class name for Page-instances.
protected  void setComponent(RenderableComponent component)
          Pre-requirement for using any of the methods in this class.
protected  void setResult(org.w3c.dom.Document document)
           
protected  void setUp()
           
protected  void submitForm()
          Submits the mock form created with createForm() method.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WheelTestCase

public WheelTestCase()
Method Detail

setUp

protected void setUp()
              throws java.lang.Exception
Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

render

protected void render()
Causes an immidiate rendering of the component. Call this method always before doing assertXpath() or assertPresent() calls. Also remember to re-render the component after state-changes.


createForm

protected void createForm(java.lang.String id)
Creates a mock form where you can manually set values and then submit it to the component. Useful for testing form validations.

Parameters:
id - Must match the componentId of the Form-component you want to mock.

addFormField

protected void addFormField(java.lang.String name,
                            java.lang.String value)
Adds field value to the mock form. Call createForm() before calling this method. Call this method with the same name-parameter multiple times to mock an array field value (like in multiselect).

Parameters:
name -
value -

setComponent

protected void setComponent(RenderableComponent component)
Pre-requirement for using any of the methods in this class. Calling this method indicates the component you want to test.

Parameters:
component - The component can be any as long as instanceof RenderableComponent is true.

submitForm

protected void submitForm()
Submits the mock form created with createForm() method. Calling this method causes a new rendering of the component also.


assertXpath

protected void assertXpath(java.lang.String expectedValue,
                           java.lang.String xpathExpression)
Enables to make Xpath-based assertions on the html-code created when the component was rendered with a call to render() method.

Parameters:
expectedValue - Expected result of the xpath-expression.
xpathExpression - A valid Xpath-expression

assertPresent

protected void assertPresent(java.lang.String xpathExpression)
Checks that an element is present in the output html.

Parameters:
xpathExpression - A valid Xpath-expression

reset

protected void reset()
Resets the html-output from the previous rendering.


getPage

protected StandaloneComponent getPage()
Returns the Page being used. If you've called setComponent() with a component that isn't an instance of Page, this method will return an instance of MockPage where your component is attached.

Returns:

setBasePackageForPages

protected void setBasePackageForPages(java.lang.String basePackage)
By default the basePackage will be "wheel.testing" for components that are not Pages and the package-part of the class name for Page-instances. Example: if you call setComponent() with an instance of com.foo.bar.pages.MyPage, the basePackageForPages in the MockEngine would be set to com.foo.bar.pages. By calling this method you can set the basePackage to any value you like if the defaults aren't ok.

Parameters:
basePackage -

setResult

protected void setResult(org.w3c.dom.Document document)


Copyright © 2007-2008. All Rights Reserved.