|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object junit.extensions.jfcunit.TestHelper
A helper class that provides facilities for locating and posting events to components within a GUI. To use, create a new instance of TestHelper in your setUp. Caveat: Windows can only be located once they have been shown once to the user.
Field Summary | |
static long |
DEFAULTSLEEP
The length of time that the test class will sleep for between each event being posted. |
private static java.lang.Object |
LOCK
Lock for setting the key mapping. |
private int |
m_step
Step size for mouse movement events. |
private static KeyMapping |
s_keyMapping
KeyMapping to be used with the helper. |
private static java.util.HashMap |
s_systemWindows
System Windows List. |
private static JFCTestCase |
s_test
Current test. |
Constructor Summary | |
protected |
TestHelper()
Constructor. |
Method Summary | |
static void |
addSystemWindow(java.lang.String matchTitleRE)
Add a regular expression to match the window titles which should not be closed during cleanup. |
protected void |
adjustModifiers(java.awt.Component ultimate,
int modifiers,
int newModifiers)
Send the modifier key release event for the modifiers. |
static java.awt.Point |
calcNextPoint(java.awt.Point src,
java.awt.Point dest,
int step)
Calculate the next point along the path to the destingation point. |
static void |
cleanUp(JFCTestCase testCase)
This method is used to clean up any existing open windows, etc if ase lettersa test fails midway. |
static void |
cleanUp(JFCTestCase testCase,
long awtSleepTime)
This method is used to clean up any existing open windows, etc if a test fails midway. |
static void |
disposeWindow(java.awt.Window window,
JFCTestCase testCase)
This method does the actual work of destroying the window. |
static void |
disposeWindow(java.awt.Window window,
JFCTestCase testCase,
long awtSleepTime)
This method does the actual work of destroying the window and any dialogs that it owns. |
void |
enterClickAndLeave(AbstractMouseEventData evtData)
Helper method to fire appropriate events to click(s) a component with a custom wait method. |
void |
enterDragAndLeave(AbstractMouseEventData srcEvtData,
AbstractMouseEventData dstEvtData,
int incr)
Helper method to fire appropriate events to drag and drop a component with a custom wait method. |
void |
enterDragAndLeave(DragEventData ded)
Helper method to fire appropriate events to drag and drop a component with a custom wait method. |
void |
enterMouseWheel(MouseWheelEventData evtData)
Enter a mouseWheel event. |
static java.awt.Component |
findComponent(java.lang.Class compCls,
java.awt.Container cont,
int index)
Deprecated. 2.02 Use new ComponentFinder(compCls).find(cont, index); |
static java.awt.Component |
findComponent(java.lang.Class compCls,
int index)
Deprecated. 2.02 Use new ComponentFinder(aClass).find(index); |
static java.awt.Component |
findComponent(Finder finder,
java.awt.Container cont,
int index)
Deprecated. 2.02 use finder.find(cont, index); |
static java.awt.Component |
findComponent(Finder finder,
int index)
Deprecated. 2.02 Use finder.find(index); |
static java.awt.Component |
findNamedComponent(java.lang.Class aClass,
java.awt.Container cont,
int index)
Deprecated. 2.02 Use new NamedComponentFinder(aClass, null).find(cont, index); |
static java.awt.Component |
findNamedComponent(java.lang.Class compCls,
int index)
Deprecated. 2.02 Use new ComponentFinder(compCls).find(cont, index); |
static java.awt.Component |
findNamedComponent(java.lang.Class aClass,
java.lang.String name,
java.awt.Container cont,
int index)
Deprecated. 2.02 Use new NamedComponentFinder(aClass, name).find(cont, index); |
static java.awt.Component |
findNamedComponent(java.lang.Class compCls,
java.lang.String name,
int index)
Deprecated. 2.02 Use new NamedComponentFinder(compCls, name).find(index); |
static java.awt.Component |
findNamedComponent(java.lang.String name,
java.awt.Container cont,
int index)
Deprecated. 2.02 Use new NamedComponentFinder(null, name).find(cont, index); |
static java.awt.Component |
findNamedComponent(java.lang.String name,
int index)
Deprecated. 2.02 Use new NamedComponentFinder(null,name).find(index); |
static java.awt.Window[] |
getAllWindows()
Deprecated. 2.02 use WindowMonitor.getWindows(); |
static JFCTestCase |
getCurrentTestCase()
Get the current test case. |
private static int |
getDir(int src,
int dest)
Calculate the direction of travel given the src and dest point. |
static KeyMapping |
getKeyMapping()
Get the key mapping to be used. |
java.lang.String |
getMessageFromJDialog(javax.swing.JDialog dialog)
A helper method to find the message being displayed in a dialog box. |
static java.util.List |
getShowingDialogs()
Deprecated. 2.05 Use DialogFinder(null).findAll() |
static java.util.List |
getShowingDialogs(java.util.List ret,
java.awt.Window[] owners,
Finder finder)
Deprecated. 2.05 use new DialogFinder(null).findAll(owners); |
static java.util.List |
getShowingDialogs(java.util.List ret,
java.awt.Window[] owners,
java.lang.String titlematch)
Deprecated. 2.05 Use new DialogFinder(titlematch).findAll(owners); |
static java.util.List |
getShowingDialogs(java.lang.String titlematch)
Deprecated. 2.05 use new DialogFinder(titlematch).findAll(); |
static java.util.List |
getShowingDialogs(java.awt.Window win)
Deprecated. 2.05 Use new DialogFinder(null).findAll(win); |
static java.util.List |
getShowingDialogs(java.awt.Window[] owners,
java.lang.String titlematch)
Deprecated. 2.05 use new DialogFinder(titlematch).findAll(owners); |
static java.util.List |
getShowingDialogs(java.awt.Window win,
java.lang.String titlematch)
Deprecated. 2.05 use new DialogFinder(titleMatch).findAll(win); |
javax.swing.JFileChooser |
getShowingJFileChooser(java.awt.Window win)
Deprecated. 2.05 use JFileChooserFinder(null).find(win, 0); |
java.util.List |
getShowingJFileChoosers(java.awt.Window win)
Deprecated. 2.05 use JFileChooserFinder(null).findAl(win); |
int |
getStep()
Returns the step size for the move events. |
static java.util.Set |
getSystemWindows()
Returns a unmodifiable list of the system window regular expressions. |
static java.awt.Window |
getWindow(AbstractWindowFinder finder)
Returns a single window that is showing that passes the filtration by the Finder passed in. |
static java.awt.Window |
getWindow(java.lang.String title)
Deprecated. 2.02 use new FrameFinder(title).getWindow |
static java.util.List |
getWindows()
Returns a set of all the Windows that are currently visible. |
static java.util.List |
getWindows(AbstractWindowFinder finder)
Deprecated. 2.05 use finder.findAll(); |
static java.util.List |
getWindows(java.util.List ret,
java.awt.Window[] windows,
Finder finder)
Deprecated. 2.05 use finder.findAll(windows); |
static java.util.List |
getWindows(java.util.List ret,
java.awt.Window[] windows,
java.lang.String titlematch)
Deprecated. 2.05 use new FrameFinder(titlematch).findAll(); |
static java.util.List |
getWindows(java.lang.String titlematch)
Returns a set of all the Windows that are currently visible and the title contains the given titlematch string. |
static int |
indexOf(Finder finder,
java.awt.Container cont,
java.awt.Component comp)
Find the index of the component given. |
protected static boolean |
isBounded(int val,
int vMin,
int vMax)
Check to see if the value is bounded by the min and max. |
protected abstract void |
keyPressed(java.awt.Component ultimate,
JFCKeyStroke stroke)
Process a key press event on a component. |
protected abstract void |
keyReleased(java.awt.Component ultimate,
JFCKeyStroke stroke)
Process a key release event on a component. |
protected abstract void |
mouseMoved(java.awt.Component ultimate,
int x,
int y)
Process a mouse move event on a component. |
protected abstract void |
mousePressed(java.awt.Component ultimate,
int modifiers,
int click,
boolean isPopupTrigger)
Process a mouse press event on a component. |
protected abstract void |
mouseReleased(java.awt.Component ultimate,
int modifiers,
int click,
boolean isPopupTrigger)
Process a mouse release event on a component. |
protected static int |
mouseToKeyModifiers(int modifiers)
Convert the modifiers from mouse modifiers to keyboard modifiers. |
protected abstract void |
mouseWheel(java.awt.Component ultimate,
int amount,
int rotation)
Simulate rotating the mouseWheel. |
protected void |
pressModifiers(java.awt.Component ultimate,
int modifiers)
Send the modifier key press event for the modifiers. |
protected void |
releaseModifiers(java.awt.Component ultimate,
int modifiers)
Send the modifier key release event for the modifiers. |
static void |
removeAllSystemWindows()
Remove all System Window regular expressions. |
static void |
removeSystemWindow(java.lang.String matchTitleRE)
Remove a regular expression to match the window titles which should not be closed during cleanup. |
void |
sendKeyAction(KeyEventData evtData)
This method is used to send KeyPressed, KeyTyped and KeyReleased events (in that order) to the specified component. |
void |
sendString(AbstractKeyEventData evtData)
This method is used to send KeyPressed, KeyTyped and KeyReleased events (in that order) to the specified component. |
static void |
setCurrentTestCase(JFCTestCase tc)
Set the current test case. |
static void |
setKeyMapping(KeyMapping km)
Set the key mapping to be used. |
void |
setStep(int step)
Set the step size of mouse move events. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final long DEFAULTSLEEP
private static JFCTestCase s_test
private static KeyMapping s_keyMapping
private static java.util.HashMap s_systemWindows
private static final java.lang.Object LOCK
private int m_step
Constructor Detail |
protected TestHelper()
Method Detail |
public static java.awt.Window[] getAllWindows()
public static void setCurrentTestCase(JFCTestCase tc)
tc
- TestCase to set as the current test.public static JFCTestCase getCurrentTestCase()
public static final java.util.Set getSystemWindows()
public static final void addSystemWindow(java.lang.String matchTitleRE) throws org.apache.regexp.RESyntaxException
matchTitleRE
- Regular expression defining the windows
which should not be closed.
org.apache.regexp.RESyntaxException
- if the syntax is not a valid Regular expression.public static void setKeyMapping(KeyMapping km)
km
- KeyMapping to be used.public static KeyMapping getKeyMapping()
public static java.util.List getShowingDialogs()
public static java.util.List getShowingDialogs(java.awt.Window win)
win
- The window to find dialogs for.
public static java.util.List getShowingDialogs(java.lang.String titlematch)
titlematch
- The string pattern to search for in the dialog's title.
public static java.util.List getShowingDialogs(java.awt.Window win, java.lang.String titlematch)
win
- The window to find dialogs for.titlematch
- The string pattern to search for in the dialog's title.
public static java.util.List getShowingDialogs(java.awt.Window[] owners, java.lang.String titlematch)
owners
- The array of windows to find dialogs for.titlematch
- The string pattern to search for in the dialog's title.
public static java.util.List getShowingDialogs(java.util.List ret, java.awt.Window[] owners, java.lang.String titlematch)
ret
- The list of already filtered and accepted dialogs.owners
- The array of windows to find dialogs for.titlematch
- The string pattern to search for in the dialog's title.
public static java.util.List getShowingDialogs(java.util.List ret, java.awt.Window[] owners, Finder finder)
ret
- The list of already filtered and accepted dialogs.owners
- The array of windows to find dialogs for.finder
- The DialogFinder which is used to filter using a title match
public static java.util.List getWindows(AbstractWindowFinder finder)
finder
- The AbstractWindowFinder which is used to filter
public static java.util.List getWindows(java.util.List ret, java.awt.Window[] windows, java.lang.String titlematch)
ret
- The list of already filtered and accepted windows.windows
- The array of windows to filter and add.titlematch
- The string pattern to search for in the window's title.
public static java.util.List getWindows(java.util.List ret, java.awt.Window[] windows, Finder finder)
ret
- The list of already filtered and accepted windows.windows
- The array of windows to filter and add.finder
- The FrameFinder which is used to filter using a title match
public static java.awt.Point calcNextPoint(java.awt.Point src, java.awt.Point dest, int step)
src
- Source point.dest
- Dest point.step
- Number of pixels to step.
public static void cleanUp(JFCTestCase testCase)
testCase
- The test case that is firing the event.addSystemWindow(java.lang.String)
,
removeSystemWindow(java.lang.String)
,
removeAllSystemWindows()
public static void cleanUp(JFCTestCase testCase, long awtSleepTime)
testCase
- The test case that is firing the event.awtSleepTime
- The wait time in ms between each event.public static void disposeWindow(java.awt.Window window, JFCTestCase testCase)
window
- The window that needs to be destroyed.testCase
- The test case that is firing the event.public static void disposeWindow(java.awt.Window window, JFCTestCase testCase, long awtSleepTime)
window
- The window that needs to be destroyed.testCase
- The test case that is firing the event.awtSleepTime
- The wait time in ms between each event.public static final void removeAllSystemWindows()
public static final void removeSystemWindow(java.lang.String matchTitleRE)
matchTitleRE
- Regular expression defining the windows
which should not be closed.public java.lang.String getMessageFromJDialog(javax.swing.JDialog dialog)
dialog
- The dialog box displaying the message
public static java.awt.Window getWindow(java.lang.String title)
title
- The string that should be present in the title.
public static java.awt.Window getWindow(AbstractWindowFinder finder)
finder
- The AbstractWindowFinder which is used to filter
public static java.util.List getWindows()
public static java.util.List getWindows(java.lang.String titlematch)
titlematch
- The string pattern to search for in the window's title.
public javax.swing.JFileChooser getShowingJFileChooser(java.awt.Window win)
win
- The window to owning the chooser.
public java.util.List getShowingJFileChoosers(java.awt.Window win)
win
- The window to owning the chooser.
public static java.awt.Component findComponent(java.lang.Class compCls, int index)
compCls
- Component classindex
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findComponent(java.lang.Class compCls, java.awt.Container cont, int index)
compCls
- The class of the component.cont
- The container that the component will be in.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findComponent(Finder finder, int index)
finder
- Finder class to be used for locating components.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findComponent(Finder finder, java.awt.Container cont, int index)
finder
- The Finder that is used to test components for a
match.cont
- The container that the component will be in.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findNamedComponent(java.lang.Class compCls, int index)
compCls
- Component classindex
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findNamedComponent(java.lang.String name, int index)
name
- The pattern for the name of the component to find.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findNamedComponent(java.lang.Class compCls, java.lang.String name, int index)
compCls
- Component classname
- The pattern for the name of the component to find.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findNamedComponent(java.lang.String name, java.awt.Container cont, int index)
name
- The pattern for the name of the component to find.cont
- The container that the component will be in.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findNamedComponent(java.lang.Class aClass, java.awt.Container cont, int index)
aClass
- The component's class.cont
- The container that the component will be in.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static java.awt.Component findNamedComponent(java.lang.Class aClass, java.lang.String name, java.awt.Container cont, int index)
aClass
- The component's class.name
- The pattern for the name of the component to find.cont
- The container that the component will be in.index
- The index of the component. The first component matching the
criteria will have index 0, the second 1, etc.
public static int indexOf(Finder finder, java.awt.Container cont, java.awt.Component comp)
finder
- Finder used for indexing.cont
- Container to look for the component in.comp
- Component to find the index of.
public void setStep(int step)
step
- size in pixels.public int getStep()
public void enterClickAndLeave(AbstractMouseEventData evtData)
evtData
- The event data containerpublic void enterDragAndLeave(AbstractMouseEventData srcEvtData, AbstractMouseEventData dstEvtData, int incr)
srcEvtData
- The source event data containerdstEvtData
- The destination event data containerincr
- Amount to increment the coords while "moving" from
source to destination.public void enterDragAndLeave(DragEventData ded)
ded
- The destination event data containerpublic void enterMouseWheel(MouseWheelEventData evtData)
evtData
- MouseWheelEventData to be processed.public void sendKeyAction(KeyEventData evtData)
evtData
- The event data container.public void sendString(AbstractKeyEventData evtData)
evtData
- The event data container.protected static int mouseToKeyModifiers(int modifiers)
modifiers
- The mouse modifiers that need to be converted.
protected final void adjustModifiers(java.awt.Component ultimate, int modifiers, int newModifiers)
ultimate
- Component to receive the events.modifiers
- The modifiers to be released.newModifiers
- The new modifiers which should be pressed.protected final void pressModifiers(java.awt.Component ultimate, int modifiers)
ultimate
- Component to receive the events.modifiers
- The modifiers to be pressed.protected final void releaseModifiers(java.awt.Component ultimate, int modifiers)
ultimate
- Component to receive the events.modifiers
- The modifiers to be released.protected static boolean isBounded(int val, int vMin, int vMax)
val
- Value to be checked.vMin
- minimum value of range.vMax
- maximum value of range.
protected abstract void keyPressed(java.awt.Component ultimate, JFCKeyStroke stroke)
ultimate
- The ultimate parent Componentstroke
- The JFCKeyStroke to be performed.protected abstract void keyReleased(java.awt.Component ultimate, JFCKeyStroke stroke)
ultimate
- The ultimate parent Componentstroke
- The JFCKeyStroke to be performed.protected abstract void mouseMoved(java.awt.Component ultimate, int x, int y)
ultimate
- The ultimate parent Componentx
- The x coordinate of the point where the mouse is being moved to.y
- The y coordinate of the point where the mouse is being moved to.protected abstract void mousePressed(java.awt.Component ultimate, int modifiers, int click, boolean isPopupTrigger)
ultimate
- The ultimate parent Componentmodifiers
- The modifiers associated with this mouse event.click
- The number of clicks associated with this mouse event.isPopupTrigger
- Whether this mouse event will generate a popup.protected abstract void mouseReleased(java.awt.Component ultimate, int modifiers, int click, boolean isPopupTrigger)
ultimate
- The ultimate parent Componentmodifiers
- The modifiers associated with this mouse event.click
- The number of clicks associated with this mouse event.isPopupTrigger
- Whether this mouse event will generate a popup.protected abstract void mouseWheel(java.awt.Component ultimate, int amount, int rotation)
ultimate
- Component to fire the events on.amount
- Amount to scroll for each rotation.rotation
- clicks to rotate the mouse wheel.private static int getDir(int src, int dest)
src
- Sourcedest
- Destination
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |