abbot.script
Class Launch

java.lang.Object
  extended by abbot.script.Step
      extended by abbot.script.Call
          extended by abbot.script.Launch
All Implemented Interfaces:
UIContext, XMLConstants, XMLifiable, Serializable
Direct Known Subclasses:
Appletviewer

public class Launch
extends Call
implements UIContext

Provides scripted static method invocation. Usage:

<launch class="package.class" method="methodName" args="..." classpath="..." [threaded=true]>

The args attribute is a comma-separated list of arguments to pass to the class method, and may use square brackets to denote an array, e.g. "[one,two,three]" will be interpreted as an array length 3 of String. The square brackets may be escaped ('\[' or '\]') to include them literally in an argument.

The class path attribute may use either colon or semicolon as a path separator, but should preferably use relative paths to avoid making the containing script platform- and location-dependent.

In most cases, the classes under test will only be found under the custom class path, and so the parent class loader will fail to find them. If this is the case then the classes under test will be properly discarded on each launch when a new class loader is created.

The 'threaded' attribute is provided in case your code under test requires GUI event processing prior to returning from its invoked method. An example might be a main method which invokes dialog and waits for the response before continuing. In general, it's better to refactor the code if possible so that the main method turns over control to the event dispatch thread as soon as possible. Otherwise, if the application under test is background threaded by the Launch step, any runtime exceptions thrown from the launch code will cause errors in the launch step out of sequence with the other script steps. While this won't cause any problems for the Abbot framework, it can be very confusing for the user.

Note that if the "reload" attribute is set true (i.e. Abbot's class loader is used to reload code under test), ComponentTester extensions must also be loaded by that class loader, so the path to extensions should be included in the Launch class path.

See Also:
Serialized Form

Nested Class Summary
static interface Launch.ThreadedLaunchListener
           
 
Field Summary
 
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
Launch(Resolver resolver, Map attributes)
           
Launch(Resolver resolver, String description, String className, String methodName, String[] args)
           
Launch(Resolver resolver, String description, String className, String methodName, String[] args, String classpath, boolean threaded)
           
 
Method Summary
protected  AppClassLoader createClassLoader()
           
 boolean equivalent(UIContext context)
          No two launches are ever considered equivalent.
 Map getAttributes()
          Attributes to save in script.
 String getClasspath()
           
 ClassLoader getContextClassLoader()
          Return the class loader that uses the classpath defined in this step.
 String getDefaultDescription()
          Return a reasonable default description for this script step.
 Hierarchy getHierarchy()
          A context must maintain the same Hierarchy for the lifetime of the fixture.
 Method getMethod()
          Return the method to be used for invocation.
protected  Object getTarget(Method m)
          Return the target for the method invocation.
 Class getTargetClass()
          Get the class of the target of the method invocation.
 String getUsage()
          Provide a usage String for this step.
 String getXMLTag()
          Define the XML tag to use for this script step.
protected  void install()
          Install the class loader context for the code being launched.
 boolean isLaunched()
           
 boolean isThreaded()
           
 void launch(StepRunner runner)
          Launches the UI described by this Launch step, using the given runner as controller/monitor.
 Class resolveClass(String className)
          Overrides the default implementation to always use the class loader defined by this step.
 void runStep()
          Implement the step's behavior here.
 void setClasspath(String cp)
           
 void setThreaded(boolean thread)
           
 void setThreadedLaunchListener(Launch.ThreadedLaunchListener l)
          Set a listener to respond to events when the launch step is threaded.
protected  void synchronizedRunStep()
           
 void terminate()
          Perform steps necessary to remove any setup performed by this Launch step.
 
Methods inherited from class abbot.script.Call
disambiguateMethod, evaluateParameter, evaluateParameters, getArgs, getArguments, getArgumentsDescription, getEncodedArguments, getMethodName, getMethods, getTargetClassName, invoke, resolveMethod, resolveMethods, setArguments, setArguments, setMethodName, setTargetClassName
 
Methods inherited from class abbot.script.Step
addAttributes, addContent, createAttributeMap, createStep, createStep, getDescription, getResolver, parseStepAttributes, resolveTester, run, setDescription, setScriptError, simpleClassName, toEditableString, toString, toXML, toXMLString, usage, usage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Launch

public Launch(Resolver resolver,
              Map attributes)

Launch

public Launch(Resolver resolver,
              String description,
              String className,
              String methodName,
              String[] args)

Launch

public Launch(Resolver resolver,
              String description,
              String className,
              String methodName,
              String[] args,
              String classpath,
              boolean threaded)
Method Detail

getClasspath

public String getClasspath()

setClasspath

public void setClasspath(String cp)

isThreaded

public boolean isThreaded()

setThreaded

public void setThreaded(boolean thread)

createClassLoader

protected AppClassLoader createClassLoader()

install

protected void install()
Install the class loader context for the code being launched. The context class loader for the current thread is modified.


synchronizedRunStep

protected void synchronizedRunStep()
                            throws Throwable
Throws:
Throwable

terminate

public void terminate()
Perform steps necessary to remove any setup performed by this Launch step.

Specified by:
terminate in interface UIContext

launch

public void launch(StepRunner runner)
            throws Throwable
Launches the UI described by this Launch step, using the given runner as controller/monitor.

Specified by:
launch in interface UIContext
Throws:
Throwable

isLaunched

public boolean isLaunched()
Specified by:
isLaunched in interface UIContext
Returns:
Whether the code described by this launch step is currently active.

getHierarchy

public Hierarchy getHierarchy()
Description copied from interface: UIContext
A context must maintain the same Hierarchy for the lifetime of the fixture.

Specified by:
getHierarchy in interface UIContext

runStep

public void runStep()
             throws Throwable
Description copied from class: Step
Implement the step's behavior here.

Overrides:
runStep in class Call
Throws:
Throwable

resolveClass

public Class resolveClass(String className)
                   throws ClassNotFoundException
Overrides the default implementation to always use the class loader defined by this step. This works in cases where the Launch step has not yet been added to a Script; otherwise the Script will provide an implementation equivalent to this one.

Overrides:
resolveClass in class Step
Throws:
ClassNotFoundException

getContextClassLoader

public ClassLoader getContextClassLoader()
Return the class loader that uses the classpath defined in this step.

Specified by:
getContextClassLoader in interface UIContext
Returns:
A ClassLoader providing access to classes in this context.

getTargetClass

public Class getTargetClass()
                     throws ClassNotFoundException
Description copied from class: Call
Get the class of the target of the method invocation. This is public to provide editors access to the class being used (for example, providing a menu of all available methods).

Overrides:
getTargetClass in class Call
Throws:
ClassNotFoundException

getTarget

protected Object getTarget(Method m)
Return the target for the method invocation. All launch invocations must be static, so this always returns null.

Overrides:
getTarget in class Call

getMethod

public Method getMethod()
                 throws ClassNotFoundException,
                        NoSuchMethodException
Return the method to be used for invocation.

Overrides:
getMethod in class Call
Throws:
ClassNotFoundException
NoSuchMethodException

getAttributes

public Map getAttributes()
Description copied from class: Call
Attributes to save in script.

Overrides:
getAttributes in class Call

getDefaultDescription

public 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 Call

getUsage

public String getUsage()
Description copied from class: Step
Provide a usage String for this step.

Overrides:
getUsage in class Call

getXMLTag

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

Overrides:
getXMLTag in class Call

setThreadedLaunchListener

public void setThreadedLaunchListener(Launch.ThreadedLaunchListener l)
Set a listener to respond to events when the launch step is threaded.


equivalent

public boolean equivalent(UIContext context)
No two launches are ever considered equivalent. If you want a shared UIContext, use a Fixture.

Specified by:
equivalent in interface UIContext
Returns:
Whether this UIContext is equivalent to another.
See Also:
UIContext.equivalent(abbot.script.UIContext), StepRunner.run(Step)


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

SourceForge