junit.extensions.jfcunit.finder
Class Finder

java.lang.Object
  extended byjunit.extensions.jfcunit.finder.Finder
Direct Known Subclasses:
AbstractButtonFinder, AbstractWindowFinder, ComponentFinder, JLabelFinder, JMenuItemFinder, JPopupMenuFinder, LabeledComponentFinder, NamedComponentFinder

public abstract class Finder
extends java.lang.Object

Abstract class for defining call back classes to test whether a Component that is being searched for has been found.

Author:
Vijay Aravamudhan : ThoughtWorks Inc.

Field Summary
private  boolean m_caseIndependent
          Ignore case.
private  boolean m_debug
          The debug state of the finder.
private  boolean m_ignoreVisiblity
          visibility property defaults to false.
private  int m_operation
          Operation to be performed when selecting items.
private  org.apache.regexp.RE m_patternMatcher
          This member is used to evaluate regular expressions.
private  boolean m_showDebug
          Show Debug.
private  int m_wait
          The max wait time for a window to appear in milliseconds.
private static java.lang.String[] OP_CODE_STRINGS
          String so for the OP codes.
static int OP_CONTAINS
          Check that the value is contained.
static int OP_ENDSWITH
          Check that the value ends with the given value.
static int OP_EQUALS
          Check that the values are equal.
static int OP_MATCH
          Match the item using a Regular expression.
static int OP_STARTSWITH
          Check that the value starts with the given value.
private static int s_defaultWait
          Default wait time.
private static RobotTestHelper s_robot
          Robot for debug mode of finders.
private static boolean s_robotException
          Robot Exception received.
 
Constructor Summary
Finder()
           
 
Method Summary
protected  void createPatternMatcher(java.lang.String patternString, boolean caseIndependent)
          This method is used to filter components' attributes based on a pattern specified by the user.
 boolean evaluate(java.lang.String leftside, java.lang.String rightside)
          Evaluate the current operation.
 java.awt.Component find()
          Find the first component.
protected  java.awt.Component find(java.awt.Container[] conts, int index)
          Find the Component matching this finder at the given index within the container specified.
 java.awt.Component find(java.awt.Container cont, int index)
          Find the Component matching this finder at the given index within the container specified.
 java.awt.Component find(int index)
          Find the component at the index.
 java.util.List findAll()
          Find all of the resulting items in the entire GUI application.
 java.util.List findAll(java.awt.Container cont)
          Find all of the items matching this finder in the container give.
 java.util.List findAll(java.awt.Container[] cont)
          Find all of the components for this finder in the set of containers given.
protected  java.util.List findAll(java.awt.Container[] cont, java.util.List results)
          This find all uses a recursive pattern for internal processing.
static java.util.List findComponentList(Finder finder, java.awt.Container cont, java.util.List pList, int index)
          Method that calls itself repetitively to build up a list of all components in the container instance that is passed in.
 boolean getDebug()
          Get the debug state of the finder.
static int getDefaultWait()
          Get the default wait duration in seconds.
 int getOperation()
          Get the operation.
static int getOperation(java.lang.String code)
          Convert the String to a Operation code.
static java.lang.String getOperationString(int code)
          Get the string version of the operation.
 boolean getShowDebug()
          Get the debug state of the finder.
 int getWait()
          Get the wait time.
 boolean isCaseIndependent()
          Get the state of ignore case.
protected  boolean isValidForProcessing(java.awt.Component comp, java.lang.Class cls)
          This method is used to check that the window object is an instance of the specified class and is also visible.
protected  boolean matchPattern(java.lang.String componentAttribute, java.lang.String patternString)
          This method is used to filter components' attributes based on a pattern specified by the user.
protected  boolean matchPattern(java.lang.String componentAttribute, java.lang.String patternString, boolean caseIndependent)
          This method is used to filter components' attributes based on a pattern specified by the user.
protected  boolean matchPattern(java.lang.String componentAttribute, java.lang.String patternString, org.apache.regexp.RE re)
          This method is used to filter components' attributes based on a pattern specified by the user.
protected  void pause(long date)
          Puase the finder for a bit.
protected  void recreatePatternMatcher(java.lang.String patternString, boolean caseIndependent)
          Recreate the pattern.
 void setCaseIndependent(boolean ignoreCase)
          Set the finder into a case independent mode.
 void setDebug(boolean value)
          Set the debug state of the finder.
static void setDefaultWait(int wait)
          Set the default wait time for the finders.
 void setIgnoreVisibility(boolean value)
          Set the ignore visiblity property, to generate the proper index when a dialog is closed.
 void setOperation(int operation)
          Set the operation to be performed by this finder.
 void setShowDebug(boolean value)
          Set the debug state of the finder.
 void setWait(int wait)
          Set the max wait time for a window to appear.
abstract  boolean testComponent(java.awt.Component comp)
          Method that returns true if the given component matches the search criteria.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_robot

private static RobotTestHelper s_robot
Robot for debug mode of finders.


s_robotException

private static boolean s_robotException
Robot Exception received.


OP_CODE_STRINGS

private static final java.lang.String[] OP_CODE_STRINGS
String so for the OP codes.


OP_MATCH

public static final int OP_MATCH
Match the item using a Regular expression.

See Also:
Constant Field Values

OP_STARTSWITH

public static final int OP_STARTSWITH
Check that the value starts with the given value.

See Also:
Constant Field Values

OP_ENDSWITH

public static final int OP_ENDSWITH
Check that the value ends with the given value.

See Also:
Constant Field Values

OP_EQUALS

public static final int OP_EQUALS
Check that the values are equal.

See Also:
Constant Field Values

OP_CONTAINS

public static final int OP_CONTAINS
Check that the value is contained.

See Also:
Constant Field Values

m_patternMatcher

private org.apache.regexp.RE m_patternMatcher
This member is used to evaluate regular expressions.


m_caseIndependent

private boolean m_caseIndependent
Ignore case.


m_debug

private boolean m_debug
The debug state of the finder.


m_ignoreVisiblity

private boolean m_ignoreVisiblity
visibility property defaults to false.


m_showDebug

private boolean m_showDebug
Show Debug.


m_operation

private int m_operation
Operation to be performed when selecting items.


s_defaultWait

private static int s_defaultWait
Default wait time.


m_wait

private int m_wait
The max wait time for a window to appear in milliseconds.

Constructor Detail

Finder

public Finder()
Method Detail

getOperation

public static final int getOperation(java.lang.String code)
Convert the String to a Operation code.

Parameters:
code - String version of the Operation.
Returns:
int version of the operation.

getOperationString

public static final java.lang.String getOperationString(int code)
Get the string version of the operation.

Parameters:
code - int Finder.OP_code
Returns:
String version of the operation.

getDebug

public final boolean getDebug()
Get the debug state of the finder.

Returns:
true if debugging should be enabled.

setOperation

public final void setOperation(int operation)
Set the operation to be performed by this finder.

Parameters:
operation - Operation to be performed.
See Also:
Exact match, Matches a Regular Expression, Starts with, Ends with, Contains

getOperation

public final int getOperation()
Get the operation.

Returns:
the operation to be performed by the finder.

setShowDebug

public final void setShowDebug(boolean value)
Set the debug state of the finder.

Parameters:
value - true if debugging should be enabled.

getShowDebug

public final boolean getShowDebug()
Get the debug state of the finder.

Returns:
true if debugging should be enabled.

setWait

public final void setWait(int wait)
Set the max wait time for a window to appear.

Parameters:
wait - time in seconds.

getWait

public final int getWait()
Get the wait time.

Returns:
Wait time in seconds. Default wait time is 10 seconds.

setDefaultWait

public static final void setDefaultWait(int wait)
Set the default wait time for the finders. This effects all new Finders which are created.

Parameters:
wait - int duration to wait by default.

getDefaultWait

public static final int getDefaultWait()
Get the default wait duration in seconds. The default effects all new finders created.

Returns:
int default duration to wait.

evaluate

public final boolean evaluate(java.lang.String leftside,
                              java.lang.String rightside)
Evaluate the current operation.

Parameters:
leftside - String to be compared.
rightside - String or Regular expression.
Returns:
result of operation

setCaseIndependent

public void setCaseIndependent(boolean ignoreCase)
Set the finder into a case independent mode.

Parameters:
ignoreCase - true if case should be ignored.

isCaseIndependent

public boolean isCaseIndependent()
Get the state of ignore case.

Returns:
boolean true if the case is ignored.

setDebug

public final void setDebug(boolean value)
Set the debug state of the finder.

Parameters:
value - true if debugging should be enabled.

setIgnoreVisibility

public final void setIgnoreVisibility(boolean value)
Set the ignore visiblity property, to generate the proper index when a dialog is closed.

Parameters:
value - true if the visibility should be ignored.

testComponent

public abstract boolean testComponent(java.awt.Component comp)
Method that returns true if the given component matches the search criteria.

Parameters:
comp - The Component to test
Returns:
true if this Component is a match

find

protected java.awt.Component find(java.awt.Container[] conts,
                                  int index)
Find the Component matching this finder at the given index within the container specified.

Parameters:
conts - Container to be searched.
index - Index of the item.
Returns:
Component found.

find

public final java.awt.Component find(int index)
Find the component at the index. Scope to search is all frames/dialogs.

Parameters:
index - Index of the item to be found.
Returns:
Item at the given index.

find

public java.awt.Component find(java.awt.Container cont,
                               int index)
Find the Component matching this finder at the given index within the container specified.

Parameters:
cont - Container to be searched.
index - Index of the item.
Returns:
Component found.

find

public final java.awt.Component find()
Find the first component. Scope to search is all frames/dialogs.

Returns:
First Item.

findAll

public java.util.List findAll()
Find all of the resulting items in the entire GUI application.

Returns:
List resulting items matching finder.

findAll

public java.util.List findAll(java.awt.Container cont)
Find all of the items matching this finder in the container give.

Parameters:
cont - Container to be searched.
Returns:
List resulting items matching finder.

findAll

public java.util.List findAll(java.awt.Container[] cont)
Find all of the components for this finder in the set of containers given.

Parameters:
cont - Container[] Set of containers to search.
Returns:
List resulting items matching finder.

findAll

protected java.util.List findAll(java.awt.Container[] cont,
                                 java.util.List results)
This find all uses a recursive pattern for internal processing.

Parameters:
cont - Container[] Container list.
results - List to which resulting items should be added.
Returns:
List resulting list.

findComponentList

public static final java.util.List findComponentList(Finder finder,
                                                     java.awt.Container cont,
                                                     java.util.List pList,
                                                     int index)
Method that calls itself repetitively to build up a list of all components in the container instance that is passed in.

Parameters:
finder - An instance of the finder which implements the testComponent() method.
cont - The Container inside which the component is to be found.
pList - The return list.
index - The index of the component. The first component matching the criteria will have index 0, the second 1, etc.
Returns:
The component that has been found (or null if none found).

isValidForProcessing

protected final boolean isValidForProcessing(java.awt.Component comp,
                                             java.lang.Class cls)
This method is used to check that the window object is an instance of the specified class and is also visible.

Parameters:
comp - The Component to be checked
cls - The type of the component
Returns:
true if the component is of the specified type and is visible.

recreatePatternMatcher

protected void recreatePatternMatcher(java.lang.String patternString,
                                      boolean caseIndependent)
Recreate the pattern.

Parameters:
patternString - String pattern string.
caseIndependent - boolean true if the case should be ignored.

createPatternMatcher

protected void createPatternMatcher(java.lang.String patternString,
                                    boolean caseIndependent)
This method is used to filter components' attributes based on a pattern specified by the user. For example, to search for all windows with title matching 'testWindow*'. Note: If the patternString is null, we need to avoid the PatternCompiler.compile() throwing a NullPointerException and in this case, return true if the componentAttribute is also null. The pattern syntax can be found at the Jakarta RegExp API Documentation in RE.

Parameters:
patternString - The pattern to match with
caseIndependent - Whether the match should be case independent (true) or not (false)

matchPattern

protected boolean matchPattern(java.lang.String componentAttribute,
                               java.lang.String patternString,
                               boolean caseIndependent)
This method is used to filter components' attributes based on a pattern specified by the user. For example, to search for all windows with title matching 'testWindow*'. Note: If the patternString is null, we need to avoid the PatternCompiler.compile() throwing a NullPointerException and in this case, return true if the componentAttribute is also null. The pattern syntax can be found at the Jakarta RegExp API Documentation in RE.

Parameters:
componentAttribute - The attribute text of the component to match against
patternString - The pattern to match with
caseIndependent - Whether the match should be case independent (true) or not (false)
Returns:
boolean whether the pattern is contained within the components' attribute text
See Also:
createPatternMatcher(String, boolean), #matchPattern(String, String)}

matchPattern

protected boolean matchPattern(java.lang.String componentAttribute,
                               java.lang.String patternString)
This method is used to filter components' attributes based on a pattern specified by the user. For example, to search for all windows with title matching 'testWindow*'. Note: If the patternString is null, we need to avoid the PatternCompiler.compile() throwing a NullPointerException and in this case, return true if the componentAttribute is also null. The pattern syntax can be found at the Jakarta RegExp API Documentation in RE.

Parameters:
componentAttribute - The attribute text of the component to match against
patternString - The pattern to match with
Returns:
boolean whether the pattern is contained within the components' attribute text

matchPattern

protected final boolean matchPattern(java.lang.String componentAttribute,
                                     java.lang.String patternString,
                                     org.apache.regexp.RE re)
This method is used to filter components' attributes based on a pattern specified by the user. For example, to search for all windows with title matching 'testWindow*'. Note: If the patternString is null, we need to avoid the PatternCompiler.compile() throwing a NullPointerException and in this case, return true if the componentAttribute is also null. The pattern syntax can be found at the Jakarta RegExp API Documentation in RE.

Parameters:
componentAttribute - The attribute text of the component to match against
patternString - The pattern to match with
re - The RE pattern matcher to be used
Returns:
boolean whether the pattern is contained within the components' attribute text

pause

protected final void pause(long date)
Puase the finder for a bit.

Parameters:
date - Termination time of the finder.


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