sir.mts.generators
Class BourneShellScriptGenerator

java.lang.Object
  extended by sir.mts.generators.BourneShellScriptGenerator
All Implemented Interfaces:
TestScriptGenerator

public class BourneShellScriptGenerator
extends java.lang.Object
implements TestScriptGenerator

Generates a Bourne shell script from the contents of a STImpL file.

Version:
05/01/2006
Author:
Alex Kinneer

Constructor Summary
BourneShellScriptGenerator(Configuration config)
           
 
Method Summary
 int addComment(java.lang.String comment)
          Adds a comment to the generated script.
 int addExternalFinishScript(java.lang.String scriptName, java.util.List params)
          Adds a script invocation to be executed after invocation of the test case.
 int addExternalSetupScript(java.lang.String scriptName, java.util.List params)
          Adds a script invocation to be executed prior to invocation of the test case.
 int addInlineFinishScript(java.lang.String scriptName, java.util.Map params)
          Inlines a script to executed after invocation of the test case.
 int addInlineSetupScript(java.lang.String scriptName, java.util.Map params)
          Inlines a script to executed prior to invocation of the test case.
 int addInputFile(java.lang.String file)
          Adds a file redirection to the standard input stream of the current test case.
 int addMoveFile(java.lang.String srcFile, java.lang.String destFile)
          Adds a command to move an output file to another location after execution of the test case.
 int addOutputFile(java.lang.String file)
          Adds a redirection to file of the standard output and error streams of the current test case.
 int addParameter(java.lang.String param)
          Adds a command line parameter to the current test case.
 int addTestDriver(java.lang.String testDriver)
          Adds a test driver to be used to invoke the test case.
 void addVariableAssign(java.lang.String var, java.lang.String val, boolean unsetFirst)
          Inserts a statement in the script to assign a value to a named variable.
 void addVerbatim(java.lang.String text)
          Copies text verbatim to the generated script.
 int endScript()
          Indicates the end of the script.
 int endTest()
          Indicates the end of the current test implementation specification.
 java.lang.String getEscapedQuote()
          Gets the escape sequence to generate a single quote character (").
 void newTest(int testNum)
          Indicates the start of a new test implementation specification.
 int setRunInBackground(boolean flagged)
          Instructs the script generator to cause the test case to be executed as a background job.
 void startScript()
          Indicates the start of a new script.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BourneShellScriptGenerator

public BourneShellScriptGenerator(Configuration config)
Method Detail

startScript

public void startScript()
                 throws ScriptGenException
Description copied from interface: TestScriptGenerator
Indicates the start of a new script.

This is most useful for inserting content at the start of the script.

Specified by:
startScript in interface TestScriptGenerator
Throws:
ScriptGenException - If the script generator fails to generate content associated with this event.

endScript

public int endScript()
              throws ScriptGenException
Description copied from interface: TestScriptGenerator
Indicates the end of the script.

This is most useful for inserting content at the end of the script.

Specified by:
endScript in interface TestScriptGenerator
Returns:
The number of test cases in the generated script.
Throws:
ScriptGenException - If the script generator fails to generate content associated with this event.

addVerbatim

public void addVerbatim(java.lang.String text)
                 throws ScriptGenException
Description copied from interface: TestScriptGenerator
Copies text verbatim to the generated script.

Note: There is currently no STImpL syntax associated with this event, and it is not called by the parser. It is reserved for future use.

Specified by:
addVerbatim in interface TestScriptGenerator
Parameters:
text - Text to be copied unchanged to the generated script.
Throws:
ScriptGenException - If the script generator fails to copy the specified text to the script.

addVariableAssign

public void addVariableAssign(java.lang.String var,
                              java.lang.String val,
                              boolean unsetFirst)
                       throws ScriptGenException
Description copied from interface: TestScriptGenerator
Inserts a statement in the script to assign a value to a named variable.

Variables are considered to exist in the global scope. Thus all test cases subsequent to a variable assignment should have access to the variable value.

Specified by:
addVariableAssign in interface TestScriptGenerator
Parameters:
var - Name of the variable to be assigned.
val - Value to be assigned to the variable.
unsetFirst - boolean Flag indicating whether a statement to explicitly unset the specified variable should be inserted before the assignment statement, if such a capability exists in the target language.
Throws:
ScriptGenException - If the script generator is unable to insert a variable assignment statement.

newTest

public void newTest(int testNum)
             throws ScriptGenException
Description copied from interface: TestScriptGenerator
Indicates the start of a new test implementation specification.

Specified by:
newTest in interface TestScriptGenerator
Parameters:
testNum - The test number of this test in the script.
Throws:
ScriptGenException - If the script generator is unable to generate a new test.

endTest

public int endTest()
            throws ScriptGenException
Description copied from interface: TestScriptGenerator
Indicates the end of the current test implementation specification.

Specified by:
endTest in interface TestScriptGenerator
Returns:
The number of tests added to the script so far.
Throws:
ScriptGenException - If the script generator fails to generate content associated with this event.

addParameter

public int addParameter(java.lang.String param)
                 throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a command line parameter to the current test case.

Specified by:
addParameter in interface TestScriptGenerator
Parameters:
param - Command line parameter string to be added to the invocation command for the current test case.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to add the parameter string to the test case invocation.

addInputFile

public int addInputFile(java.lang.String file)
                 throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a file redirection to the standard input stream of the current test case.

Specified by:
addInputFile in interface TestScriptGenerator
Parameters:
file - Name of the file that should be redirected to the test case on the standard input stream.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to add the input file redirection to the test case invocation.

addOutputFile

public int addOutputFile(java.lang.String file)
                  throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a redirection to file of the standard output and error streams of the current test case.

Specified by:
addOutputFile in interface TestScriptGenerator
Parameters:
file - Name of the file to which the standard output and error streams of the test case should be redirected.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to add the output redirection to the test case invocation.

addMoveFile

public int addMoveFile(java.lang.String srcFile,
                       java.lang.String destFile)
                throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a command to move an output file to another location after execution of the test case.

Specified by:
addMoveFile in interface TestScriptGenerator
Parameters:
srcFile - Name of the output file to be moved.
destFile - Path and file name to which the output file should be moved.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to add a command to move the specified output file.

addExternalSetupScript

public int addExternalSetupScript(java.lang.String scriptName,
                                  java.util.List params)
                           throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a script invocation to be executed prior to invocation of the test case.

By historical convention, script invocations should be added in the order received (that is, the order in which they are requested by calls to this method), and should be inserted before any inlined startup scripts.

Specified by:
addExternalSetupScript in interface TestScriptGenerator
Parameters:
scriptName - Name of the script to be invoked prior to the test case.
params - List of parameters to be passed to the invoked script.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to add the invocation of a startup script.

addInlineSetupScript

public int addInlineSetupScript(java.lang.String scriptName,
                                java.util.Map params)
                         throws ScriptGenException
Description copied from interface: TestScriptGenerator
Inlines a script to executed prior to invocation of the test case.

By historical convention, scripts should be inlined in the order received (that is, the order in which they are requested by calls to this method), and they should always appear after the invocations of non-inlined startup scripts.

The parameters argument can be used to request that the script generator insert appropriate variable assignment statements at the head of the inlined script to simulate parameters. Note however that these variables are not cleared at the end of the inlined script, and thus they may remain in scope and available to subsequent test cases. This may be useful for maintaining state in the script.

Specified by:
addInlineSetupScript in interface TestScriptGenerator
Parameters:
scriptName - Name of the script to be inlined into the generated script prior to execution of the test case.
params - Map A Map<String,String> that contains pairings of variable names to values that should be assigned to those variables at the beginning of the script, simulating parameters to the script.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to inline the requested startup script.

addExternalFinishScript

public int addExternalFinishScript(java.lang.String scriptName,
                                   java.util.List params)
                            throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a script invocation to be executed after invocation of the test case.

By historical convention, script invocations should be added in the order received (that is, the order in which they are requested by calls to this method), and should be inserted after any inlined finishing scripts.

Specified by:
addExternalFinishScript in interface TestScriptGenerator
Parameters:
scriptName - Name of the script to be invoked after the test case.
params - List of parameters to be passed to the invoked script.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to add the invocation of a finishing script.

addInlineFinishScript

public int addInlineFinishScript(java.lang.String scriptName,
                                 java.util.Map params)
                          throws ScriptGenException
Description copied from interface: TestScriptGenerator
Inlines a script to executed after invocation of the test case.

By historical convention, scripts should be inlined in the order received (that is, the order in which they are requested by calls to this method), and they should always appear before the invocations of non-inlined finishing scripts.

The parameters argument can be used to request that the script generator insert appropriate variable assignment statements at the head of the inlined script to simulate parameters. Note however that these variables are not cleared at the end of the inlined script, and thus they may remain in scope and available to subsequent test cases. This may be useful for maintaining state in the script.

Specified by:
addInlineFinishScript in interface TestScriptGenerator
Parameters:
scriptName - Name of the script to be inlined into the generated script after execution of the test case.
params - Map A Map<String,String> that contains pairings of variable names to values that should be assigned to those variables at the beginning of the script, simulating parameters to the script.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to inline the requested finishing script.

addComment

public int addComment(java.lang.String comment)
               throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a comment to the generated script.

Comment text is supplied verbatim, including unmodified whitespace.

Specified by:
addComment in interface TestScriptGenerator
Parameters:
comment - Comment text to be added.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to add the comment text.

addTestDriver

public int addTestDriver(java.lang.String testDriver)
                  throws ScriptGenException
Description copied from interface: TestScriptGenerator
Adds a test driver to be used to invoke the test case.

Specified by:
addTestDriver in interface TestScriptGenerator
Parameters:
testDriver - Name of the test driver program to be used to invoke the program under test.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator is unable to insert the use of a test driver to invoke the test case.

setRunInBackground

public int setRunInBackground(boolean flagged)
                       throws ScriptGenException
Description copied from interface: TestScriptGenerator
Instructs the script generator to cause the test case to be executed as a background job.

Specified by:
setRunInBackground in interface TestScriptGenerator
Parameters:
flagged - true if the test case should be run in the background, false if it should be run as a normal process.
Returns:
The number of STImpL test specification commands received so far for the current test case.
Throws:
ScriptGenException - If the script generator cannot cause the test case to be executed as a background job.

getEscapedQuote

public java.lang.String getEscapedQuote()
Description copied from interface: TestScriptGenerator
Gets the escape sequence to generate a single quote character (").

Specified by:
getEscapedQuote in interface TestScriptGenerator
Returns:
The escape sequence required to safely produce a quote character in the target script language.