abbot.script
Class Script

java.lang.Object
  extended by abbot.script.Step
      extended by abbot.script.Sequence
          extended by abbot.script.Script
All Implemented Interfaces:
Resolver, XMLConstants, XMLifiable, Serializable
Direct Known Subclasses:
Fixture

public class Script
extends Sequence
implements Resolver

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 ScriptFixture and ScriptTestSuite to generate a suite by auto-generating a collection of Scripts.

See Also:
StepRunner, Fixture, Launch, Serialized Form

Field Summary
static String INTERPRETER
           
protected static String UNTITLED
           
static String UNTITLED_FILE
           
(package private) static boolean validate
           
 
Fields inherited from interface abbot.script.XMLConstants
TAG_ACTION, TAG_APPLETVIEWER, TAG_ARCHIVE, TAG_ARGS, TAG_ASSERT, TAG_AWT, TAG_AWTTESTSCRIPT, TAG_BORDER_TITLE, TAG_CALL, TAG_CLASS, TAG_CLASSPATH, TAG_CODE, TAG_CODEBASE, TAG_COMMENT, TAG_COMPONENT, TAG_COUNT, TAG_DELEGATE, TAG_DESC, TAG_DOCBASE, TAG_EVENT, TAG_EXPR, TAG_FILENAME, TAG_FIXTURE, TAG_FORKED, TAG_HEIGHT, TAG_HORDER, TAG_ICON, TAG_ID, TAG_INDEX, TAG_INVERT, TAG_INVOKER, TAG_KEYCHAR, TAG_KEYCODE, TAG_KIND, TAG_LABEL, TAG_LAUNCH, TAG_METHOD, TAG_MODIFIERS, TAG_NAME, TAG_PARAMS, TAG_PARENT, TAG_POLL_INTERVAL, TAG_PROPERTY, TAG_ROOT, TAG_SAMPLE, TAG_SCRIPT, TAG_SEQUENCE, TAG_SLOW, TAG_STOP_ON_ERROR, TAG_STOP_ON_FAILURE, TAG_TAG, TAG_TERMINATE, TAG_TEXT, TAG_THREADED, TAG_TIMEOUT, TAG_TITLE, TAG_TRIGGER, TAG_TYPE, TAG_VALUE, TAG_VMARGS, TAG_VORDER, TAG_WAIT, TAG_WEIGHTED, TAG_WIDTH, TAG_WINDOW, TAG_X, TAG_Y
 
Constructor Summary
Script()
          Deprecated. Use an explicit Hierarchy instead.
Script(Hierarchy h)
           
Script(Resolver parent, Map attributes)
           
Script(String filename)
          Deprecated. Use an explicit Hierarchy instead.
Script(String filename, Hierarchy h)
          Create a Script from the given file.
 
Method Summary
 ComponentReference addComponent(Component comp)
          Add a new component reference for the given component.
 void addComponentReference(ComponentReference ref)
          Add a component reference directly, replacing any existing one with the same ID.
(package private)  ComponentReference addComponentReference(Element el)
          Add a new component reference to the script.
 Element addContent(Element el)
          Save component references in addition to everything else.
 void addStep(int index, Step step)
          Inserts a step at the given index in the sequence.
 void addStep(Step step)
          Adds a step to the end of the sequence.
 void changeFile(File file)
          Deprecated. Use setFile(File).
 void clear()
          Set up a blank script, discarding any current state.
static int countLines(Sequence seq, int index)
          Return the number of XML lines in the given sequence that precede the given index.
protected static Map createDefaultMap(String filename)
           
 Map getAttributes()
          Provide XML attributes for this Step.
 ComponentReference getComponentReference(Component comp)
          Return the reference for the given component, or null if none yet exists.
 ComponentReference getComponentReference(String name)
          Convert the given reference ID into a component reference.
 Collection getComponentReferences()
          Returns a sorted collection of ComponentReferences.
 String getContext(Step step)
          Return a meaningful description of where the Step came from.
 ClassLoader getContextClassLoader()
          Defer to the UIContext to obtain a ClassLoader, or use the current Thread's context class loader.
 String getDefaultDescription()
          Return a default description for this Script.
 File getDirectory()
          All relative files should be accessed relative to this directory, which is the directory where the script resides.
 File getFile()
          Return the file where this script is saved.
static File getFile(Step step)
          Return the file which defines the given step.
 String getFilename()
          Return the (possibly relative) path to this script.
protected  String getFullXMLString()
           
 Hierarchy getHierarchy()
          Return the currently effective Hierarchy of components.
static int getLine(Step step)
          Return the approximate line number of the given step.
 String getName()
           
 Object getProperty(String name)
          Provide retrieval of values from temporary storage.
 File getRelativeTo()
          By default, all pathnames are relative to the current working directory.
 UIContext getUIContext()
           
 String getUsage()
          Returns a string describing the proper XML usage for this class.
 String getVMArgs()
           
 String getXMLTag()
          Define the XML tag to use for this script step.
 boolean hasLaunch()
          Return whether this Script is launchable.
 boolean hasTerminate()
           
 boolean isAWTMode()
           
 boolean isDirty()
          Has this script changed since the last save.
 boolean isForked()
           
static boolean isScript(File file)
          Return whether the given file looks like a valid AWT script.
 boolean isSlowPlayback()
           
 void load()
          Read the script from the currently set file.
 void load(Reader reader)
          Loads the XML test script.
protected  void parseAttributes(Map map)
          Parse XML attributes for the Script.
protected  void parseChild(Element el)
           
static File resolveRelativeReferences(File file)
          It turns out that getAbsolutePath doesn't remove any relative path entries such as ..
protected  void runStep(StepRunner runner)
          Process each event in our list, using the given runner.
 void save()
          Write the script to file.
 void save(Writer writer)
          Write the current state of the script to file.
 void setAWTMode(boolean awt)
           
 void setFile(File file)
          Set the file system basis for this script object.
 void setForked(boolean fork)
           
 void setHierarchy(Hierarchy h)
           
 void setProperty(String name, Object value)
          Provide temporary storage of String values.
 void setRelativeTo(File dir)
          Indicate that when invoking toXML, a path relative to the given one should be shown.
 void setSlowPlayback(boolean slow)
           
 void setStep(int index, Step step)
          Replaces the step at the given index.
 void setVMArgs(String args)
           
 String toEditableString()
          Only thing directly editable on a script is its file path.
 
Methods inherited from class abbot.script.Sequence
getStep, indexOf, parseChildren, removeStep, removeStep, runStep, size, steps
 
Methods inherited from class abbot.script.Step
addAttributes, createAttributeMap, createStep, createStep, getDescription, getResolver, parseStepAttributes, resolveClass, resolveTester, run, setDescription, setScriptError, simpleClassName, toString, toXML, toXMLString, usage, usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTERPRETER

public static final String INTERPRETER
See Also:
Constant Field Values

validate

static boolean validate

UNTITLED_FILE

public static final String UNTITLED_FILE

UNTITLED

protected static final String UNTITLED
Constructor Detail

Script

public Script()
Deprecated. Use an explicit Hierarchy instead.

Create a new, empty Script. Used as a temporary Resolver, uses the default Hierarchy.


Script

public Script(String filename)
Deprecated. Use an explicit Hierarchy instead.

Create a Script from the given filename. Uses the default Hierarchy.


Script

public Script(Hierarchy h)

Script

public Script(String filename,
              Hierarchy h)
Create a Script from the given file.


Script

public Script(Resolver parent,
              Map attributes)
Method Detail

createDefaultMap

protected static Map createDefaultMap(String filename)

setHierarchy

public void setHierarchy(Hierarchy h)

getName

public String getName()

setForked

public void setForked(boolean fork)

isForked

public boolean isForked()

setVMArgs

public void setVMArgs(String args)

getVMArgs

public String getVMArgs()

isSlowPlayback

public boolean isSlowPlayback()

setSlowPlayback

public void setSlowPlayback(boolean slow)

isAWTMode

public boolean isAWTMode()

setAWTMode

public void setAWTMode(boolean awt)

getFile

public File getFile()
Return the file where this script is saved. Will always be an absolute path.


changeFile

public void changeFile(File file)
Deprecated. Use setFile(File).

Change the file system basis for the current script. Does not affect the script contents.


setFile

public void setFile(File file)
Set the file system basis for this script object. Use this to set the file from which the existing script will be loaded.


save

public void save(Writer writer)
          throws IOException
Write the current state of the script to file.

Throws:
IOException

toEditableString

public String toEditableString()
Only thing directly editable on a script is its file path.

Specified by:
toEditableString in interface XMLifiable
Overrides:
toEditableString in class Sequence

isDirty

public boolean isDirty()
Has this script changed since the last save.


save

public void save()
          throws 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.

Throws:
IOException

parseChild

protected void parseChild(Element el)
                   throws InvalidScriptException
Overrides:
parseChild in class Sequence
Throws:
InvalidScriptException

parseAttributes

protected void parseAttributes(Map map)
Parse XML attributes for the Script.


load

public void load(Reader reader)
          throws InvalidScriptException,
                 IOException
Loads the XML test script. Performs a check against the XML schema.

Parameters:
reader - Provides the script data
Throws:
InvalidScriptException
IOException

addStep

public void addStep(int index,
                    Step step)
Description copied from class: Sequence
Inserts a step at the given index in the sequence.

Overrides:
addStep in class Sequence

addStep

public void addStep(Step step)
Description copied from class: Sequence
Adds a step to the end of the sequence.

Overrides:
addStep in class Sequence

setStep

public void setStep(int index,
                    Step step)
Replaces the step at the given index.

Overrides:
setStep in class Sequence

load

public void load()
          throws IOException
Read the script from the currently set file.

Throws:
IOException

getFullXMLString

protected String getFullXMLString()

getXMLTag

public String getXMLTag()
Description copied from class: Step
Define the XML tag to use for this script step.

Overrides:
getXMLTag in class Sequence

addContent

public Element addContent(Element el)
Save component references in addition to everything else.

Overrides:
addContent in class Sequence

getFilename

public String getFilename()
Return the (possibly relative) path to this script.


getAttributes

public Map getAttributes()
Provide XML attributes for this Step. This class adds its filename.

Overrides:
getAttributes in class Step

runStep

protected void runStep(StepRunner runner)
                throws Throwable
Description copied from class: Sequence
Process each event in our list, using the given runner.

Overrides:
runStep in class Sequence
Throws:
Throwable

clear

public void clear()
Set up a blank script, discarding any current state.

Overrides:
clear in class Sequence

getUsage

public String getUsage()
Description copied from class: Sequence
Returns a string describing the proper XML usage for this class.

Overrides:
getUsage in class Sequence

getDefaultDescription

public String getDefaultDescription()
Return a default description for this Script.

Overrides:
getDefaultDescription in class Sequence

hasLaunch

public boolean hasLaunch()
Return whether this Script is launchable.


getUIContext

public UIContext getUIContext()
Returns:
The UIContext responsible for setting up a UI context for this script, or null if the script has no UI to speak of.

getContextClassLoader

public ClassLoader getContextClassLoader()
Defer to the UIContext to obtain a ClassLoader, or use the current Thread's context class loader.

Specified by:
getContextClassLoader in interface Resolver
See Also:
Thread.getContextClassLoader()

hasTerminate

public boolean hasTerminate()

getRelativeTo

public File getRelativeTo()
By default, all pathnames are relative to the current working directory.


setRelativeTo

public void setRelativeTo(File dir)
Indicate that when invoking toXML, a path relative to the given one should be shown. Note that this is a runtime setting only and never shows up in saved XML.


resolveRelativeReferences

public static File resolveRelativeReferences(File file)
It turns out that getAbsolutePath doesn't remove any relative path entries such as .. the alternative getCannonicalPath can cause problems with version control systems that make a lot of use of symolic links. For example a directory in a source control view might contain local checked out files and symlinks to un-checked out files (These files might be located on another machine in some cases). This means that files that are next to each other in the view appear to be in quite different paths when resolved using getCannonicalPath. Therefore we are reduced to tidying up the paths manually.

Parameters:
file - The input file to tidy up.
Returns:
An absolute path with all . and .. removed
Throws:
IllegalArgumentException - If the number of ".." entries outnumber those of the normal path entries.

isScript

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


getDirectory

public File getDirectory()
All relative files should be accessed relative to this directory, which is the directory where the script resides. It will always return an absolute path.

Specified by:
getDirectory in interface Resolver

getComponentReferences

public Collection getComponentReferences()
Returns a sorted collection of ComponentReferences.

Specified by:
getComponentReferences in interface Resolver

addComponentReference

public void addComponentReference(ComponentReference ref)
Add a component reference directly, replacing any existing one with the same ID.

Specified by:
addComponentReference in interface Resolver

addComponent

public ComponentReference addComponent(Component comp)
Add a new component reference for the given component.

Specified by:
addComponent in interface Resolver

addComponentReference

ComponentReference addComponentReference(Element el)
                                   throws InvalidScriptException
Add a new component reference to the script. For use only when parsing a script.

Throws:
InvalidScriptException

getComponentReference

public ComponentReference getComponentReference(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(String name)
Convert the given reference ID into a component reference. If it's not in the Script's list, returns null.

Specified by:
getComponentReference in interface Resolver

setProperty

public void setProperty(String name,
                        Object value)
Description copied from interface: Resolver
Provide temporary storage of String values.

Specified by:
setProperty in interface Resolver

getProperty

public Object getProperty(String name)
Description copied from interface: Resolver
Provide retrieval of values from temporary storage.

Specified by:
getProperty in interface Resolver

getHierarchy

public Hierarchy getHierarchy()
Return the currently effective Hierarchy of components.

Specified by:
getHierarchy in interface Resolver

getContext

public String getContext(Step step)
Return a meaningful description of where the Step came from.

Specified by:
getContext in interface Resolver

getFile

public static File getFile(Step step)
Return the file which defines the given step.


getLine

public static int getLine(Step step)
Return the approximate line number of the given step. File lines are one-based (there is no line zero).


countLines

public static int countLines(Sequence seq,
                             int index)
Return the number of XML lines in the given sequence that precede the given index. If the index is -1, return the number of XML lines used by the whole sequence.



Copyright © 2002-2008 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge