junit.extensions.awt.script
Class Script

java.lang.Object
  |
  +--junit.extensions.awt.script.Step
        |
        +--junit.extensions.awt.script.Sequence
              |
              +--junit.extensions.awt.script.Script
All Implemented Interfaces:
Resolver, StepListener, Tags, XMLifiable

public class Script
extends Sequence
implements Resolver, StepListener

Provide a structure to encapsulate actions invoked on GUI components and tests performed on those components. Scripts need to be short and concise (and therefore easy to read/write). Extensions don't have to be.

This takes a single filename as a constructor argument.
Use AWTTestCase/AWTTestSuite to generate a suite (auto-generate the collection).


Fields inherited from class junit.extensions.awt.script.Step
listeners, parser, STEP_END, STEP_ERROR, STEP_FAILURE, STEP_PROGRESS, STEP_START
 
Fields inherited from interface junit.extensions.awt.script.Tags
TAG_ACTION, TAG_ARGS, TAG_ASSERT, TAG_AWTTESTSCRIPT, TAG_CLASS, TAG_COMPONENT, TAG_COUNT, TAG_DESC, TAG_EVENT, TAG_FILENAME, TAG_ID, TAG_INVERT, TAG_INVOKER, TAG_KEYCHAR, TAG_KEYCODE, TAG_KIND, TAG_LAUNCH, TAG_METHOD, TAG_MODIFIERS, TAG_NAME, TAG_PARENT, TAG_POLL_INTERVAL, TAG_SCRIPT, TAG_SEQUENCE, TAG_STOP_ON_ERROR, TAG_STOP_ON_FAILURE, TAG_TAG, TAG_TERMINATE, TAG_THREADED, TAG_TIMEOUT, TAG_TITLE, TAG_TRIGGER, TAG_TYPE, TAG_VALUE, TAG_WAIT, TAG_WINDOW, TAG_X, TAG_Y
 
Constructor Summary
Script(ComponentFinder finder, java.util.HashMap atts)
          Create a script included from another.
Script(java.io.File file, ComponentFinder finder)
          Create a script.
 
Method Summary
 ComponentReference addComponent(java.awt.Component comp)
          Add a new component reference for the given component.
 void clear()
          Set up a blank script, discarding any current state.
 java.lang.String getAttributes()
          Attributes to save in script.
 ComponentReference getComponentReference(java.awt.Component comp)
          Return the reference for the given component, or null if none yet exists.
 ComponentReference getComponentReference(java.lang.String name)
          Convert the given reference ID into a component reference.
 java.util.Collection getComponentReferences()
          Returns a collection of all the existing references.
protected  java.lang.String getDefaultDescription()
          Return a reasonable default description for this script step.
 java.io.File getFile()
           
 java.lang.String getName()
           
 java.lang.String getUniqueID(ComponentReference ref)
          Return a unique reference ID.
protected  java.lang.String getUsage()
          Returns a string describing the proper XML usage for this class.
 java.lang.String getXMLTag()
          For use in embedding this script in another.
 boolean hasLaunch()
           
 boolean hasTerminate()
           
static boolean isScript(java.io.File file)
          Return whether the given file looks like a valid AWT script.
 void launch()
          Convenience function to run the first step of the script if it's a Launch step.
 void load()
          Parse the script file and build internal structures.
protected  void parseChild(org.w3c.dom.Element el)
           
 void run()
          Make sure we've loaded before running.
 void save()
          Write the script to file.
 void setFile(java.io.File outputFile)
           
 void terminate()
          Convenience function to run the last step of the script if it's a terminate step.
 java.lang.String toString()
          Return a description of this script step.
 
Methods inherited from class junit.extensions.awt.script.Sequence
addStep, addStep, clearFailures, getContents, getStep, indexOf, parseChildren, removeStep, removeStep, runStep, setStep, size, stateChanged, steps
 
Methods inherited from class junit.extensions.awt.script.Step
addStepListener, createAttributeMap, createStep, createStep, fireStepEnd, fireStepError, fireStepEvent, fireStepEvent, fireStepEvent, fireStepFailure, fireStepProgress, fireStepStart, getDescription, getError, getFailure, getFinder, getResolver, getStopOnError, getStopOnFailure, getTester, parseAttributes, removeStepListener, resolve, resolveTester, setDescription, setError, setFailure, setStopOnError, setStopOnFailure, simpleClassName, toXML, usage, usage
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface junit.extensions.awt.script.StepListener
stateChanged
 

Constructor Detail

Script

public Script(java.io.File file,
              ComponentFinder finder)
Create a script. Actual reading of the script is deferred.

Script

public Script(ComponentFinder finder,
              java.util.HashMap atts)
       throws InvalidScriptException
Create a script included from another.
Method Detail

getName

public java.lang.String getName()

getFile

public java.io.File getFile()

setFile

public void setFile(java.io.File outputFile)

save

public void save()
          throws java.io.IOException
Write the script to file. Note that this differs from the toXML for the script, which simply indicates the file on which it is based.

parseChild

protected void parseChild(org.w3c.dom.Element el)
                   throws InvalidScriptException
Overrides:
parseChild in class Sequence

load

public void load()
          throws InvalidScriptException,
                 java.io.IOException
Parse the script file and build internal structures.

getXMLTag

public java.lang.String getXMLTag()
For use in embedding this script in another.
Overrides:
getXMLTag in class Sequence

getAttributes

public java.lang.String getAttributes()
Description copied from class: Step
Attributes to save in script. FIXME use a hash table?
Overrides:
getAttributes in class Step

run

public void run()
         throws java.lang.Throwable
Make sure we've loaded before running.
Overrides:
run in class Step

getUniqueID

public java.lang.String getUniqueID(ComponentReference ref)
Return a unique reference ID.
Specified by:
getUniqueID in interface Resolver

getComponentReferences

public java.util.Collection getComponentReferences()
Description copied from interface: Resolver
Returns a collection of all the existing references.
Specified by:
getComponentReferences in interface Resolver

addComponent

public ComponentReference addComponent(java.awt.Component comp)
Add a new component reference for the given component.
Specified by:
addComponent in interface Resolver

getComponentReference

public ComponentReference getComponentReference(java.awt.Component comp)
Return the reference for the given component, or null if none yet exists.
Specified by:
getComponentReference in interface Resolver

getComponentReference

public ComponentReference getComponentReference(java.lang.String name)
                                         throws ComponentNotFoundException
Convert the given reference ID into a component reference.
Specified by:
getComponentReference in interface Resolver

clear

public void clear()
Set up a blank script, discarding any current state.
Overrides:
clear in class Sequence

getUsage

protected java.lang.String getUsage()
Description copied from class: Sequence
Returns a string describing the proper XML usage for this class.
Overrides:
getUsage in class Sequence

getDefaultDescription

protected java.lang.String getDefaultDescription()
Description copied from class: Step
Return a reasonable default description for this script step. This value is used in the absence of an explicit description.
Overrides:
getDefaultDescription in class Sequence

hasLaunch

public boolean hasLaunch()

hasTerminate

public boolean hasTerminate()

launch

public void launch()
            throws java.lang.Throwable
Convenience function to run the first step of the script if it's a Launch step.

terminate

public void terminate()
Convenience function to run the last step of the script if it's a terminate step.

isScript

public static boolean isScript(java.io.File file)
Return whether the given file looks like a valid AWT script.

toString

public java.lang.String toString()
Description copied from class: Step
Return a description of this script step.
Overrides:
toString in class Step