protoj.lang
Class ScriptSession

java.lang.Object
  extended by protoj.lang.ScriptSession

public final class ScriptSession
extends java.lang.Object

Provides the ability to programmatically issue commands to a project script, which is useful in writing tests for example.

Simply create an instance with the location of the project shell script and load the session up with commands to be executed by repeated calls to addCommand(String, ArgRunnable, String).

The listener arguments also supplied get called back at the end of each command execution, providing an opportunity to test proper behavior with assertions. Where the same listener is added for different commands, they can be distinguished with a provided tag. Therefore the listener body can distinguish between the different commands that cause their invocation. Calling the execute() method kicks this off.

Author:
Ashley Williams

Constructor Summary
ScriptSession(java.io.File shellScript)
          See ScriptSession.
 
Method Summary
 void addCommand(java.lang.String command)
          Convenience call when not interested in receiving a call to a listener when the command has completed.
 void addCommand(java.lang.String command, ArgRunnable<ScriptSession> listener, java.lang.String tag)
          Queue the given command ready to be executed.
 void execute()
          This method executes all of the accumulated commands, calling back the listener after each one.
 java.lang.String getCurrentCommand()
          The name of the most recently executed command.
 CommandTask getCurrentExec()
          The command object resulting from the most recent command execution, containing useful information such as stdout.
 java.lang.String getCurrentTag()
          The tag associated with the most recently executed command.
 java.io.File getShellScript()
          The script that the commands are sent to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptSession

public ScriptSession(java.io.File shellScript)
See ScriptSession.

Parameters:
shellScript -
Method Detail

addCommand

public void addCommand(java.lang.String command)
Convenience call when not interested in receiving a call to a listener when the command has completed.

Parameters:
command -

addCommand

public void addCommand(java.lang.String command,
                       ArgRunnable<ScriptSession> listener,
                       java.lang.String tag)
Queue the given command ready to be executed.

Parameters:
command - the command to be executed
listener - the listener to call when the command has completed, can be null
tag - the tag to be associated with the command when it executes, can be null

execute

public void execute()
This method executes all of the accumulated commands, calling back the listener after each one. All the properties are updated so that the listener is able to examine them as desired.


getShellScript

public java.io.File getShellScript()
The script that the commands are sent to.

Returns:

getCurrentExec

public CommandTask getCurrentExec()
The command object resulting from the most recent command execution, containing useful information such as stdout.

Returns:

getCurrentCommand

public java.lang.String getCurrentCommand()
The name of the most recently executed command.

Returns:

getCurrentTag

public java.lang.String getCurrentTag()
The tag associated with the most recently executed command. Useful if there are added two commands of the same name that share the same listener, and so can be used to distinguish between them.

Returns: