org.openxava.tests
Class ModuleTestBase

java.lang.Object
  extended by TestCase
      extended by org.openxava.tests.ModuleTestBase

public class ModuleTestBase
extends TestCase

Base class for creating a junit test that runs against an OpenXava module.

Look an introduction to OpenXava module testing at wiki .

Author:
Javier Paniza

Constructor Summary
ModuleTestBase(java.lang.String nameTest, java.lang.String module)
          To test the specified module of the default application.
ModuleTestBase(java.lang.String nameTest, java.lang.String application, java.lang.String module)
          To test the specified module of the specified application.
 
Method Summary
protected  void assertAction(java.lang.String action)
           
protected  void assertActions(java.lang.String[] expectedActions)
           
protected  void assertCollectionColumnCount(java.lang.String collection, int expected)
           
protected  void assertCollectionRowCount(java.lang.String collection, int expectedCount)
          Row count displayed with data.
protected  void assertContentType(java.lang.String type)
          Util for web applications, but using it make the test web dependent.
protected  void assertContentTypeForPopup(java.lang.String type)
          Util for web applications, but using it make the test web dependent.
protected  void assertDescriptionValue(java.lang.String name, java.lang.String value)
           
protected  void assertEditable(java.lang.String name)
           
protected  void assertError(java.lang.String message)
           
protected  void assertErrorsCount(int expectedCount)
           
protected  void assertExists(java.lang.String name)
           
protected  void assertFocusOn(java.lang.String name)
           
protected  void assertLabel(java.lang.String name, java.lang.String expectedLabel)
           
protected  void assertLabelInCollection(java.lang.String collection, int column, java.lang.String label)
           
protected  void assertLabelInList(int column, java.lang.String label)
           
protected  void assertListColumnCount(int expected)
           
protected  void assertListNotEmpty()
           
protected  void assertListRowCount(int expected)
          Rows count displayed with data.
protected  void assertListTitle(java.lang.String expectedTitle)
           
protected  void assertMessage(java.lang.String message)
           
protected  void assertMessagesCount(int expectedCount)
           
protected  void assertNoAction(java.lang.String action)
           
protected  void assertNoEditable(java.lang.String name)
           
protected  void assertNoError(java.lang.String message)
           
protected  void assertNoErrors()
           
protected  void assertNoListTitle()
           
protected  void assertNoMessage(java.lang.String message)
           
protected  void assertNoMessages()
           
protected  void assertNoPopup()
           
protected  void assertNoRowStyleInCollection(java.lang.String collection, int row)
           
protected  void assertNoRowStyleInList(int row)
           
protected  void assertNotExists(java.lang.String name)
           
protected  void assertRowChecked(int row)
           
protected  void assertRowCollectionChecked(java.lang.String collection, int row)
           
protected  void assertRowCollectionUnchecked(java.lang.String collection, int row)
           
protected  void assertRowsChecked(int[] rows)
           
protected  void assertRowsChecked(int f1, int f2)
           
protected  void assertRowStyleInCollection(java.lang.String collection, int row, java.lang.String expectedStyle)
           
protected  void assertRowStyleInList(int row, java.lang.String expectedStyle)
           
protected  void assertRowUnchecked(int row)
           
protected  void assertValidValues(java.lang.String name, java.lang.String[][] values)
           
protected  void assertValidValuesCount(java.lang.String name, int count)
           
protected  void assertValue(java.lang.String name, java.lang.String value)
           
protected  void assertValue(java.lang.String model, java.lang.String name, java.lang.String value)
           
protected  void assertValueIgnoringCase(java.lang.String name, java.lang.String value)
           
protected  void assertValueInCollection(java.lang.String collection, int row, int column, java.lang.String value)
           
protected  void assertValueInCollection(java.lang.String collection, int row, java.lang.String name, java.lang.String value)
           
protected  void assertValueInCollectionIgnoringCase(java.lang.String collection, int row, int column, java.lang.String value)
           
protected  void assertValueInList(int row, int column, java.lang.String value)
           
protected  void assertValueInList(int row, java.lang.String name, java.lang.String value)
           
protected  void assertValues(java.lang.String name, java.lang.String[] values)
          For multiple values property.
protected  void changeModule(java.lang.String module)
           
protected  void changeModule(java.lang.String application, java.lang.String module)
           
protected  void checkRow(int row)
           
protected  void checkRow(java.lang.String id, java.lang.String value)
           
protected  void checkRowCollection(java.lang.String collection, int row)
           
protected  void execute(java.lang.String action)
          Execute the action clicking in the link or button.
protected  void execute(java.lang.String action, java.lang.String arguments)
           
protected  void executeDefaultAction()
           
protected  boolean existsAction(java.lang.String action)
           
protected  int getCollectionColumnCount(java.lang.String collection)
           
protected  int getCollectionRowCount(java.lang.String collection)
          Row count displayed with data.
protected  java.lang.String getDescriptionValue(java.lang.String name)
          In the case of combo (descriptionsEditor.jsp) (or his read only version) the value that is visualized to user.
protected  HtmlForm getForm()
          Current HtmlForm (of HtmlUnit).
protected  java.lang.String getHtml()
          Current HTML code.
protected  java.lang.String[] getKeysValidValues(java.lang.String name)
           
protected  java.lang.String getLabel(java.lang.String name)
           
protected  int getListColumnCount()
           
protected  int getListRowCount()
          Rows count displayed with data.
protected  java.lang.String getLocale()
           
protected  java.lang.String getMessage()
          The first message
protected  java.lang.String getPopupText()
          The text of the response for popup window
static java.lang.String getProperty(java.lang.String id)
          From file xava-junit.properties
static java.lang.String getProperty(java.lang.String id, java.lang.String defaultValue)
          From file xava-junit.properties
protected  java.lang.String getText()
          The text of the response
protected  java.lang.String getValue(java.lang.String name)
           
protected  java.lang.String getValue(java.lang.String model, java.lang.String name)
          In case we does not work with main view.
protected  java.lang.String getValueInCollection(java.lang.String collection, int row, int column)
           
protected  java.lang.String getValueInCollection(java.lang.String collection, int row, java.lang.String name)
           
protected  java.lang.String getValueInList(int row, int column)
           
protected  java.lang.String getValueInList(int row, java.lang.String name)
           
protected  java.lang.String[] getValues(java.lang.String name)
          For properties with multiple values
protected  WebClient getWebClient()
          This allows you testing using HtmlUnit APIs directly.
protected static boolean isJetspeed2Enabled()
           
protected static boolean isLiferayEnabled()
           
static boolean isOX3()
          Warning: Does not rely heavily in this method, it can change in the future.
static boolean isPortalEnabled()
          Jetspeed2 or Liferay
protected  void login(java.lang.String user, java.lang.String password)
           
protected  void logout()
          User logout.
protected  void printHtml()
          Only for debug.
protected  void resetModule()
          Like close navigator, open again, and reexecute the module.
protected  void setConditionComparators(java.lang.String[] values)
           
protected  void setConditionComparators(java.lang.String collection, java.lang.String[] values)
           
protected  void setConditionValues(java.lang.String[] values)
           
protected  void setConditionValues(java.lang.String collection, java.lang.String[] values)
           
protected  void setFileValue(java.lang.String name, java.lang.String filePath)
           
protected  void setLocale(java.lang.String locale)
           
protected  void setModel(java.lang.String defaultModel)
          The model used as prefix to method like getValue, assertValue, etc.
protected  void setModelToModuleSetting()
          Put the model of the module as the default model of the test.
protected  void setUp()
           
protected  void setValue(java.lang.String name, java.lang.String value)
           
protected  void setValue(java.lang.String model, java.lang.String name, java.lang.String value)
          In case we do not work with main view.
protected  void setValueNotNotify(java.lang.String name, java.lang.String value)
           
protected  void setValues(java.lang.String name, java.lang.String[] values)
          For multiple values properties
protected  void tearDown()
           
protected  java.lang.String toKeyString(java.lang.Object pojo)
          Returns a string representations of the key of a POJO from the POJO itself.
protected  void uncheckRow(int row)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModuleTestBase

public ModuleTestBase(java.lang.String nameTest,
                      java.lang.String application,
                      java.lang.String module)
To test the specified module of the specified application.

You can send null for null in such a case you must use changeModule(java.lang.String) at the very first of your test methods.


ModuleTestBase

public ModuleTestBase(java.lang.String nameTest,
                      java.lang.String module)
To test the specified module of the default application.

In this case the application is obtained from the application property in xava-junit.properties file.
You can send null for null in such a case you must use changeModule(java.lang.String) at the very first of your test methods.

Method Detail

setUp

protected void setUp()
              throws java.lang.Exception
Throws:
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.lang.Exception
Throws:
java.lang.Exception

login

protected void login(java.lang.String user,
                     java.lang.String password)
              throws java.lang.Exception
Throws:
java.lang.Exception

isOX3

public static boolean isOX3()
Warning: Does not rely heavily in this method, it can change in the future.


logout

protected void logout()
               throws java.lang.Exception
User logout.

At the moment only works against Liferay and JetSpeed2.

Throws:
java.lang.Exception

resetModule

protected void resetModule()
                    throws java.lang.Exception
Like close navigator, open again, and reexecute the module.

Throws:
java.lang.Exception

changeModule

protected void changeModule(java.lang.String module)
                     throws java.lang.Exception
Throws:
java.lang.Exception

changeModule

protected void changeModule(java.lang.String application,
                            java.lang.String module)
                     throws java.lang.Exception
Throws:
java.lang.Exception

setModel

protected void setModel(java.lang.String defaultModel)
The model used as prefix to method like getValue, assertValue, etc.

By default is the model of module. The effect of the this setting is only for the life of one test.


setModelToModuleSetting

protected void setModelToModuleSetting()
Put the model of the module as the default model of the test.

This is the default setting, hence this method is called to restore the original setting.


execute

protected void execute(java.lang.String action)
                throws java.lang.Exception
Execute the action clicking in the link or button.

Throws:
java.lang.Exception

assertFocusOn

protected void assertFocusOn(java.lang.String name)
                      throws java.lang.Exception
Throws:
java.lang.Exception

execute

protected void execute(java.lang.String action,
                       java.lang.String arguments)
                throws java.lang.Exception
Throws:
java.lang.Exception

executeDefaultAction

protected void executeDefaultAction()
                             throws java.lang.Exception
Throws:
java.lang.Exception

assertExists

protected void assertExists(java.lang.String name)
                     throws java.lang.Exception
Throws:
java.lang.Exception

assertNotExists

protected void assertNotExists(java.lang.String name)
                        throws java.lang.Exception
Throws:
java.lang.Exception

getDescriptionValue

protected java.lang.String getDescriptionValue(java.lang.String name)
                                        throws java.lang.Exception
In the case of combo (descriptionsEditor.jsp) (or his read only version) the value that is visualized to user.

Returns:
Throws:
java.lang.Exception

getValue

protected java.lang.String getValue(java.lang.String name)
                             throws java.lang.Exception
Throws:
java.lang.Exception

getValues

protected java.lang.String[] getValues(java.lang.String name)
                                throws java.lang.Exception
For properties with multiple values

Throws:
java.lang.Exception

getLabel

protected java.lang.String getLabel(java.lang.String name)
                             throws java.lang.Exception
Throws:
java.lang.Exception

getValue

protected java.lang.String getValue(java.lang.String model,
                                    java.lang.String name)
                             throws java.lang.Exception
In case we does not work with main view.

Throws:
java.lang.Exception

printHtml

protected void printHtml()
                  throws java.lang.Exception
Only for debug.

Throws:
java.lang.Exception

assertContentType

protected void assertContentType(java.lang.String type)
Util for web applications, but using it make the test web dependent.

Parameters:
type - text/html, application/pdf, etc.

assertContentTypeForPopup

protected void assertContentTypeForPopup(java.lang.String type)
Util for web applications, but using it make the test web dependent.

Parameters:
type - text/html, application/pdf, etc.

assertNoPopup

protected void assertNoPopup()
                      throws java.lang.Exception
Throws:
java.lang.Exception

getHtml

protected java.lang.String getHtml()
                            throws java.io.IOException
Current HTML code.

It is not very advisable because this will cause dependency to HTML and it will be difficult migrate to another presentation technology.

Throws:
java.io.IOException

getText

protected java.lang.String getText()
                            throws java.io.IOException
The text of the response

Throws:
java.io.IOException

getPopupText

protected java.lang.String getPopupText()
                                 throws java.io.IOException
The text of the response for popup window

Throws:
java.io.IOException

setConditionValues

protected void setConditionValues(java.lang.String[] values)
                           throws java.lang.Exception
Throws:
java.lang.Exception

setConditionComparators

protected void setConditionComparators(java.lang.String[] values)
                                throws java.lang.Exception
Throws:
java.lang.Exception

setConditionValues

protected void setConditionValues(java.lang.String collection,
                                  java.lang.String[] values)
                           throws java.lang.Exception
Throws:
java.lang.Exception

setConditionComparators

protected void setConditionComparators(java.lang.String collection,
                                       java.lang.String[] values)
                                throws java.lang.Exception
Throws:
java.lang.Exception

setValueNotNotify

protected void setValueNotNotify(java.lang.String name,
                                 java.lang.String value)
                          throws java.lang.Exception
Throws:
java.lang.Exception

setValue

protected void setValue(java.lang.String name,
                        java.lang.String value)
                 throws java.lang.Exception
Throws:
java.lang.Exception

setValues

protected void setValues(java.lang.String name,
                         java.lang.String[] values)
                  throws java.lang.Exception
For multiple values properties

Throws:
java.lang.Exception

setFileValue

protected void setFileValue(java.lang.String name,
                            java.lang.String filePath)
                     throws java.lang.Exception
Throws:
java.lang.Exception

setValue

protected void setValue(java.lang.String model,
                        java.lang.String name,
                        java.lang.String value)
                 throws java.lang.Exception
In case we do not work with main view.

Throws:
java.lang.Exception

assertLabel

protected void assertLabel(java.lang.String name,
                           java.lang.String expectedLabel)
                    throws java.lang.Exception
Throws:
java.lang.Exception

assertValue

protected void assertValue(java.lang.String name,
                           java.lang.String value)
                    throws java.lang.Exception
Throws:
java.lang.Exception

assertValues

protected void assertValues(java.lang.String name,
                            java.lang.String[] values)
                     throws java.lang.Exception
For multiple values property.

Throws:
java.lang.Exception

assertValueIgnoringCase

protected void assertValueIgnoringCase(java.lang.String name,
                                       java.lang.String value)
                                throws java.lang.Exception
Throws:
java.lang.Exception

assertValue

protected void assertValue(java.lang.String model,
                           java.lang.String name,
                           java.lang.String value)
                    throws java.lang.Exception
Throws:
java.lang.Exception

assertDescriptionValue

protected void assertDescriptionValue(java.lang.String name,
                                      java.lang.String value)
                               throws java.lang.Exception
Throws:
java.lang.Exception

existsAction

protected boolean existsAction(java.lang.String action)

assertAction

protected void assertAction(java.lang.String action)

assertNoAction

protected void assertNoAction(java.lang.String action)

assertActions

protected void assertActions(java.lang.String[] expectedActions)
                      throws java.lang.Exception
Throws:
java.lang.Exception

getValueInList

protected java.lang.String getValueInList(int row,
                                          java.lang.String name)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

getValueInList

protected java.lang.String getValueInList(int row,
                                          int column)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

getValueInCollection

protected java.lang.String getValueInCollection(java.lang.String collection,
                                                int row,
                                                java.lang.String name)
                                         throws java.lang.Exception
Throws:
java.lang.Exception

getValueInCollection

protected java.lang.String getValueInCollection(java.lang.String collection,
                                                int row,
                                                int column)
                                         throws java.lang.Exception
Throws:
java.lang.Exception

assertRowStyleInList

protected void assertRowStyleInList(int row,
                                    java.lang.String expectedStyle)
                             throws java.lang.Exception
Throws:
java.lang.Exception

assertRowStyleInCollection

protected void assertRowStyleInCollection(java.lang.String collection,
                                          int row,
                                          java.lang.String expectedStyle)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

assertNoRowStyleInList

protected void assertNoRowStyleInList(int row)
                               throws java.lang.Exception
Throws:
java.lang.Exception

assertNoRowStyleInCollection

protected void assertNoRowStyleInCollection(java.lang.String collection,
                                            int row)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

getListRowCount

protected int getListRowCount()
                       throws java.lang.Exception
Rows count displayed with data.

Exclude heading and footing, and the not displayed data (maybe in cache).

Throws:
java.lang.Exception

getListColumnCount

protected int getListColumnCount()
                          throws java.lang.Exception
Throws:
java.lang.Exception

getCollectionColumnCount

protected int getCollectionColumnCount(java.lang.String collection)
                                throws java.lang.Exception
Throws:
java.lang.Exception

getCollectionRowCount

protected int getCollectionRowCount(java.lang.String collection)
                             throws java.lang.Exception
Row count displayed with data.

Excludes heading and footing, and not displayed data (but cached).

Throws:
java.lang.Exception

assertCollectionRowCount

protected void assertCollectionRowCount(java.lang.String collection,
                                        int expectedCount)
                                 throws java.lang.Exception
Row count displayed with data.

Excludes heading and footing, and not displayed data (but cached).

Throws:
java.lang.Exception

assertListRowCount

protected void assertListRowCount(int expected)
                           throws java.lang.Exception
Rows count displayed with data.

Exclude headers and footing, and the not displayed data (maybe cached).

Throws:
java.lang.Exception

assertListColumnCount

protected void assertListColumnCount(int expected)
                              throws java.lang.Exception
Throws:
java.lang.Exception

assertCollectionColumnCount

protected void assertCollectionColumnCount(java.lang.String collection,
                                           int expected)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

assertValueInList

protected void assertValueInList(int row,
                                 java.lang.String name,
                                 java.lang.String value)
                          throws java.lang.Exception
Throws:
java.lang.Exception

assertValueInList

protected void assertValueInList(int row,
                                 int column,
                                 java.lang.String value)
                          throws java.lang.Exception
Throws:
java.lang.Exception

assertValueInCollection

protected void assertValueInCollection(java.lang.String collection,
                                       int row,
                                       java.lang.String name,
                                       java.lang.String value)
                                throws java.lang.Exception
Throws:
java.lang.Exception

assertValueInCollection

protected void assertValueInCollection(java.lang.String collection,
                                       int row,
                                       int column,
                                       java.lang.String value)
                                throws java.lang.Exception
Throws:
java.lang.Exception

assertValueInCollectionIgnoringCase

protected void assertValueInCollectionIgnoringCase(java.lang.String collection,
                                                   int row,
                                                   int column,
                                                   java.lang.String value)
                                            throws java.lang.Exception
Throws:
java.lang.Exception

assertLabelInCollection

protected void assertLabelInCollection(java.lang.String collection,
                                       int column,
                                       java.lang.String label)
                                throws java.lang.Exception
Throws:
java.lang.Exception

assertLabelInList

protected void assertLabelInList(int column,
                                 java.lang.String label)
                          throws java.lang.Exception
Throws:
java.lang.Exception

checkRow

protected void checkRow(int row)
                 throws java.lang.Exception
Throws:
java.lang.Exception

uncheckRow

protected void uncheckRow(int row)
                   throws java.lang.Exception
Throws:
java.lang.Exception

checkRowCollection

protected void checkRowCollection(java.lang.String collection,
                                  int row)
                           throws java.lang.Exception
Throws:
java.lang.Exception

checkRow

protected void checkRow(java.lang.String id,
                        java.lang.String value)
                 throws java.lang.Exception
Throws:
java.lang.Exception

assertRowChecked

protected void assertRowChecked(int row)

assertRowCollectionChecked

protected void assertRowCollectionChecked(java.lang.String collection,
                                          int row)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

assertRowsChecked

protected void assertRowsChecked(int f1,
                                 int f2)

assertRowsChecked

protected void assertRowsChecked(int[] rows)

assertRowUnchecked

protected void assertRowUnchecked(int row)

assertRowCollectionUnchecked

protected void assertRowCollectionUnchecked(java.lang.String collection,
                                            int row)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

assertError

protected void assertError(java.lang.String message)
                    throws java.lang.Exception
Throws:
java.lang.Exception

assertErrorsCount

protected void assertErrorsCount(int expectedCount)
                          throws java.lang.Exception
Throws:
java.lang.Exception

assertMessagesCount

protected void assertMessagesCount(int expectedCount)
                            throws java.lang.Exception
Throws:
java.lang.Exception

assertNoError

protected void assertNoError(java.lang.String message)
                      throws java.lang.Exception
Throws:
java.lang.Exception

assertNoMessage

protected void assertNoMessage(java.lang.String message)
                        throws java.lang.Exception
Throws:
java.lang.Exception

getMessage

protected java.lang.String getMessage()
                               throws java.lang.Exception
The first message

Throws:
java.lang.Exception

assertMessage

protected void assertMessage(java.lang.String message)
                      throws java.lang.Exception
Throws:
java.lang.Exception

assertNoErrors

protected void assertNoErrors()
                       throws java.lang.Exception
Throws:
java.lang.Exception

assertNoMessages

protected void assertNoMessages()
                         throws java.lang.Exception
Throws:
java.lang.Exception

assertValidValues

protected void assertValidValues(java.lang.String name,
                                 java.lang.String[][] values)
                          throws java.lang.Exception
Throws:
java.lang.Exception

assertValidValuesCount

protected void assertValidValuesCount(java.lang.String name,
                                      int count)
                               throws java.lang.Exception
Throws:
java.lang.Exception

getKeysValidValues

protected java.lang.String[] getKeysValidValues(java.lang.String name)
                                         throws java.lang.Exception
Throws:
java.lang.Exception

assertEditable

protected void assertEditable(java.lang.String name)
                       throws java.lang.Exception
Throws:
java.lang.Exception

assertNoEditable

protected void assertNoEditable(java.lang.String name)
                         throws java.lang.Exception
Throws:
java.lang.Exception

assertListTitle

protected void assertListTitle(java.lang.String expectedTitle)
                        throws java.lang.Exception
Throws:
java.lang.Exception

assertNoListTitle

protected void assertNoListTitle()
                          throws java.lang.Exception
Throws:
java.lang.Exception

assertListNotEmpty

protected void assertListNotEmpty()
                           throws java.lang.Exception
Throws:
java.lang.Exception

isJetspeed2Enabled

protected static boolean isJetspeed2Enabled()

isLiferayEnabled

protected static boolean isLiferayEnabled()

isPortalEnabled

public static boolean isPortalEnabled()
Jetspeed2 or Liferay


getProperty

public static java.lang.String getProperty(java.lang.String id)
From file xava-junit.properties


getProperty

public static java.lang.String getProperty(java.lang.String id,
                                           java.lang.String defaultValue)
From file xava-junit.properties


getForm

protected HtmlForm getForm()
Current HtmlForm (of HtmlUnit).

This allow you to access directly to html form elements, but it is not very advisable because this will cause dependency to HTML and HtmlUnit so it will be difficult migrate to another presentation technology.


getWebClient

protected WebClient getWebClient()
This allows you testing using HtmlUnit APIs directly.

The use of this method is discoraged because binds your test to a HTML implemenation. Before to use this method look for another more abstract method in this class.


getLocale

protected java.lang.String getLocale()

setLocale

protected void setLocale(java.lang.String locale)
                  throws java.lang.Exception
Throws:
java.lang.Exception

toKeyString

protected java.lang.String toKeyString(java.lang.Object pojo)
                                throws java.lang.Exception
Returns a string representations of the key of a POJO from the POJO itself.

Useful for obtaining the value to put into a combo (a descriptions list) from a POJO object.

Throws:
java.lang.Exception