junit.extensions.xml.elements
Class IndexOfTagHandler

java.lang.Object
  extended byjunit.extensions.xml.elements.AbstractTagHandler
      extended byjunit.extensions.xml.elements.IndexOfTagHandler
All Implemented Interfaces:
XMLConstants

public class IndexOfTagHandler
extends AbstractTagHandler

Provide a mechanism for finding row/column in a table for a given value. It will return throw an assertion if the value is not found.

Tag Name:

indexof

Attributes

 refid   - the object to inspect                [required]
 id      - the id of the results                [required]
 value   - the expected value                   [required]
 type    - the field type of the object         [required]

   tablecell - locate a table cell in the
               specified row or column. row and column
               attributes may be used to narrow the search.

   listcell  - locate a item in the list.

   tab       - locate a tab.

   tablecolumn - locate a table column.
 

Optional

 index     - the x'th instance of the value to find [optional]
 operation - The type of matching operation to perform.
             match - Use a regular expression match.
             equals - (default) if not specified.
             contains - The item contains the value.
             startswith - The item starts with the value.
             endswith   - The item ends with the value.

 useRE     - (depricated use operation="match")
             allow the value to contain
             a regular expression [optional]
           default - is false exact string match needed
           If set to true partial strings will work.
 

Output

 Successful execution will set the following:

tablecell

id to the value of the cell. id.row to the row of the tablecell.

id.column to the column of the tablecell.

tablecolumn

id to the value of the header. id.index to the column of the table header. listitem

id to the value of the item. id.index to the index of the list item.

tab

id to the value of the title. id.index to the index of the tab.

Unsuccessfull id will be set to null and -1 will be set as the index, row and column.

Examples:

Return the cell where the value Joe is found in a specific column

     <indexof id="cell" refid="JTable1" type="tablecell" column="1" value="Joe"/>
 
Return the cell where the value Joe is found in a specific row
     <indexof id="cell" refid="JTable1" type="tablecell" row="1" value="Joe"/>
 
Return the 2nd cell where the value Joe is found in the table
     <indexof id="cell" refid="JTable1" type="tablecell" value="Joe" index="2"/>
 
Return the index of the column header containing SearchCode
     <indexof id="table" refid="JTable1" type="tablecolumn" value="SearchCode" index="0"/>
 
Return the index of the tab containing the General.
     <indexof id="tab" refid="TabPane1" type="tab" value="General" index="0"/>
 
Return the index of the tab containing the Peanut.
     <indexof id="item" refid="JList1" type="listitem" value="Peanut" index="0"/>
 
Return the index of the list containing the Watermellon.
     <indexof id="item" refid="JComboBox1" type="listitem"
           value="Watermellon" index="0"/>
 

Author:
Kevin Wilson, John Yunker

Field Summary
 
Fields inherited from class junit.extensions.xml.elements.AbstractTagHandler
 
Fields inherited from interface junit.extensions.xml.XMLConstants
ACTION, ACTUALOBJ, ACTUALREFID, ADD, ASSERTENABLED, ASSERTEQUALS, ASSERTNOTEQUALS, ASSERTNOTNULL, ASSERTNOTSAME, ASSERTNULL, ASSERTSAME, CALL, CASE, CHOOSE, CLASSNAME, COLUMN, CONFIRM, DEBUG, DEFAULT, DELIMITER, DIALOG, DUMP, ECHO, ENABLED, ENCODING, EVALUATE, EXPECTEDOBJ, EXPECTEDREFID, FAIL, FILE, FOCUS, FOREACH, ID, INDEX, JFCFILELOC, LESSTHAN, LISTITEM, LOG, MARK, MESSAGE, METHOD, MODE, NAME, OTHERWISE, PATHREFID, PROCEDURE, PROPERTY, RECURSIVE, REFID, RELATIVE, REMOVE, ROW, SAVE, STDERR, STDOUT, STOPWATCH, SUITE, SWITCH, TABLECELL, TAGHANDLERS, TAGNAME, TEST, TYPE, USERE, VALUE, WHEN, WHILE
 
Constructor Summary
IndexOfTagHandler(org.w3c.dom.Element element, IXMLTestCase testcase)
          Constructor.
 
Method Summary
private  boolean evaluate(int operation, java.lang.String tableval, java.lang.String expectedval)
          Evaluate the operation.
protected  boolean getCaseIndependent()
          Get the case independent attribute.
protected  int getOperation()
          Get the operation from the string value.
 void processElement()
          Locate the index or cell matching the value.
 void validateElement()
          Insure that the id, refid, type and value attributes are specified.
 
Methods inherited from class junit.extensions.xml.elements.AbstractTagHandler
checkAtLeastOneRequiredAttribute, checkAtLeastOneRequiredAttribute, checkElementTagName, checkOneRequiredAttribute, checkOneRequiredAttribute, checkRequiredAttribute, checkRequiredAttribute, getBoolean, getBoolean, getBoolean, getBoolean, getElement, getInt, getInt, getLong, getLong, getPoint, getPoint, getString, getString, getString, getString, getTagName, getTest, getTestCase, getXMLTestCase, getXMLTestSuite, resolveVariables
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexOfTagHandler

public IndexOfTagHandler(org.w3c.dom.Element element,
                         IXMLTestCase testcase)
Constructor.

Parameters:
element - Element to be processed.
testcase - Containing test case.
Method Detail

processElement

public void processElement()
                    throws XMLException
Locate the index or cell matching the value.

Specified by:
processElement in class AbstractTagHandler
Throws:
XMLException - exception maybe thrown.

validateElement

public void validateElement()
                     throws XMLException
Insure that the id, refid, type and value attributes are specified.

Overrides:
validateElement in class AbstractTagHandler
Throws:
XMLException - if one or more of the above attributes are missing.

getCaseIndependent

protected boolean getCaseIndependent()
Get the case independent attribute.

Returns:
boolean true if case should be ignored.

getOperation

protected int getOperation()
Get the operation from the string value.

Returns:
int representing the operation.

evaluate

private boolean evaluate(int operation,
                         java.lang.String tableval,
                         java.lang.String expectedval)
Evaluate the operation.

Parameters:
operation - Operation to be evaluated.
tableval - Actual value.
expectedval - expected value.
Returns:
true if a match is found.


Licensed under: GNU Lesser General Public License, Ver 2.1, February 1999