com.bitmechanic.maxq.generator
Class AbstractCodeGenerator

java.lang.Object
  extended by com.bitmechanic.maxq.generator.AbstractCodeGenerator
All Implemented Interfaces:
IScriptGenerator, ProxyServer.Observer, java.lang.Runnable
Direct Known Subclasses:
CompactGenerator, IsacCodeGenerator, JavaCodeGenerator, JythonCodeGenerator, SampleGenerator

public abstract class AbstractCodeGenerator
extends java.lang.Object
implements IScriptGenerator, ProxyServer.Observer, java.lang.Runnable

Abstract class providing general useful utility methods for code generation.

Author:
Robert Dawson robert@rojotek.com, Wayne Hearn wayne_hearn@dell.com

Field Summary
protected  long assertNumber
           
protected static java.lang.String END_STATEMENT
           
protected  boolean headersExist
           
protected static java.lang.String jtidyConfigFile
          jtidyConfigFile variable serves two purpose: one as a flag indicating we need spit out jtidy integration code, and as a variable indicating the location of jtidy.cfg file.
 
Fields inherited from interface com.bitmechanic.maxq.generator.IScriptGenerator
EOL
 
Constructor Summary
AbstractCodeGenerator(IScriptAdapter adapter, java.lang.String[] nameRegExps)
           
 
Method Summary
 void close()
          Necessary because the thread started in the constructor will otherwise never exit.
abstract  void doAssertResponse(java.lang.String respCode)
           
abstract  void doBodyParameterList(Param[] params)
           
abstract  void doCallUrl(java.lang.String url, java.lang.String method, java.lang.String data, java.lang.String contentLength)
           
abstract  void doEndTransaction()
          Called after all other calls for a particular transaction (request + response).
abstract  void doHeaders(HeaderValue[] headers)
           
 void doLoad()
          Called after a new script has been loaded from file.
abstract  void doParameterList(Param[] params)
          Implementer must add script code for the parameters provided.
abstract  void doQueryStringParameterList(Param[] params)
           
abstract  void doResponseForFile()
           
abstract  void doResponseForStdOut(java.lang.String url)
           
 void doSave(java.lang.String path, java.lang.String fileName)
          When a script is saved we update the name of the script embedded within it.
abstract  void doSetCharset(java.lang.String cs)
          Called when the character set for POST requests changes.
abstract  void doSetData(java.lang.String data)
           
abstract  void doTestUrlMessage(java.lang.String url)
           
abstract  void doTidyCode(java.lang.String url)
           
 java.lang.String getDefaultTestName()
           
protected  java.lang.String getScript()
          Returns the full script from the ScriptAdapter.
 IScriptAdapter getScriptAdapter()
           
 java.lang.String getTestName()
          Returns the name of the test.
 java.lang.String getTestPath()
          Returns the file path of the test.
 long getTimeElapsedSinceLastestRequest()
          Returns time elapsed since the latest request.
protected  void insert(java.lang.String s)
          Inserts new lines into the script.
static boolean isCpRspToFile()
           
static boolean isCpRspToStdout()
           
 boolean isFirstRequest()
           
 java.lang.String parseTestName()
          Parses the name of the test out of the script.
 void processRequest(HttpRequestHeader header, byte[] requestBody)
           
 void processResponse(HttpRequestHeader header, byte[] response)
          Processes the response and generates test events for the code generator implementation class.
 void run()
          A thread for performing insertions.
 void setDefaultTestName(java.lang.String defaultTestName)
           
abstract  void setStruts(boolean struts)
          Called if the processResponse find that the response contains the Struts token
 void setTestName(java.lang.String testName)
          Sets the name of the test class.
 void setTestPath(java.lang.String testPath)
          Sets the file path of the test
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bitmechanic.maxq.generator.IScriptGenerator
doNew, doStartRecording, doStopRecording, getValidFileExtensions
 

Field Detail

END_STATEMENT

protected static final java.lang.String END_STATEMENT

jtidyConfigFile

protected static java.lang.String jtidyConfigFile
jtidyConfigFile variable serves two purpose: one as a flag indicating we need spit out jtidy integration code, and as a variable indicating the location of jtidy.cfg file.


assertNumber

protected long assertNumber

headersExist

protected boolean headersExist
Constructor Detail

AbstractCodeGenerator

public AbstractCodeGenerator(IScriptAdapter adapter,
                             java.lang.String[] nameRegExps)
Parameters:
nameRegExps - A list of regular expressions. Each finds an instance of the script's name embedded in the script. This class will use the regular expressions to keep these names up-to-date when the user saves.
Method Detail

isCpRspToStdout

public static boolean isCpRspToStdout()

isCpRspToFile

public static boolean isCpRspToFile()

getDefaultTestName

public java.lang.String getDefaultTestName()

setDefaultTestName

public void setDefaultTestName(java.lang.String defaultTestName)

getScriptAdapter

public IScriptAdapter getScriptAdapter()

getTestName

public java.lang.String getTestName()
Returns the name of the test. Currently the same as the name of the file the test is stored in

Returns:
testName

setTestName

public void setTestName(java.lang.String testName)
Sets the name of the test class. Defaults to value set in maxq.properties under test.default_testname

Parameters:
testName -

getTestPath

public java.lang.String getTestPath()
Returns the file path of the test. Null if test is not previously saved.


setTestPath

public void setTestPath(java.lang.String testPath)
Sets the file path of the test

Parameters:
testPath -

getTimeElapsedSinceLastestRequest

public long getTimeElapsedSinceLastestRequest()
Returns time elapsed since the latest request.


isFirstRequest

public boolean isFirstRequest()

parseTestName

public java.lang.String parseTestName()
Description copied from interface: IScriptGenerator
Parses the name of the test out of the script.

Specified by:
parseTestName in interface IScriptGenerator
Returns:
test name if test has been loaded or saved. Empty otherwise.

doSave

public void doSave(java.lang.String path,
                   java.lang.String fileName)
When a script is saved we update the name of the script embedded within it. Usually this is the class name for the script.

Specified by:
doSave in interface IScriptGenerator

doLoad

public void doLoad()
Description copied from interface: IScriptGenerator
Called after a new script has been loaded from file.

Specified by:
doLoad in interface IScriptGenerator

close

public void close()
Necessary because the thread started in the constructor will otherwise never exit.

Specified by:
close in interface IScriptGenerator

processRequest

public void processRequest(HttpRequestHeader header,
                           byte[] requestBody)
                    throws java.lang.Exception
Specified by:
processRequest in interface ProxyServer.Observer
Parameters:
header -
requestBody -
Throws:
java.lang.Exception

processResponse

public void processResponse(HttpRequestHeader header,
                            byte[] response)
                     throws java.lang.Exception
Processes the response and generates test events for the code generator implementation class.

Specified by:
processResponse in interface ProxyServer.Observer
Parameters:
header -
response -
Throws:
java.lang.Exception

run

public void run()
A thread for performing insertions. Insertions can be slow when the file gets large, but this allows them to be grouped together.

Specified by:
run in interface java.lang.Runnable

doAssertResponse

public abstract void doAssertResponse(java.lang.String respCode)
                               throws Utils.UserException
Throws:
Utils.UserException

doCallUrl

public abstract void doCallUrl(java.lang.String url,
                               java.lang.String method,
                               java.lang.String data,
                               java.lang.String contentLength)
                        throws Utils.UserException
Throws:
Utils.UserException

doEndTransaction

public abstract void doEndTransaction()
                               throws Utils.UserException
Called after all other calls for a particular transaction (request + response).

Throws:
Utils.UserException

setStruts

public abstract void setStruts(boolean struts)
Called if the processResponse find that the response contains the Struts token


doSetCharset

public abstract void doSetCharset(java.lang.String cs)
                           throws Utils.UserException
Called when the character set for POST requests changes.

Throws:
Utils.UserException

doParameterList

public abstract void doParameterList(Param[] params)
                              throws Utils.UserException
Implementer must add script code for the parameters provided. This will only be called if there is at least one parameter.

Parameters:
params - Query string and body parameters, without distinction.
Throws:
Utils.UserException

doQueryStringParameterList

public abstract void doQueryStringParameterList(Param[] params)
                                         throws Utils.UserException
Parameters:
params - Query string parameters.
Throws:
Utils.UserException

doBodyParameterList

public abstract void doBodyParameterList(Param[] params)
                                  throws Utils.UserException
Parameters:
params - Body parameters.
Throws:
Utils.UserException

doResponseForFile

public abstract void doResponseForFile()
                                throws Utils.UserException
Throws:
Utils.UserException

doResponseForStdOut

public abstract void doResponseForStdOut(java.lang.String url)
                                  throws Utils.UserException
Throws:
Utils.UserException

doSetData

public abstract void doSetData(java.lang.String data)
                        throws Utils.UserException
Throws:
Utils.UserException

doTestUrlMessage

public abstract void doTestUrlMessage(java.lang.String url)
                               throws Utils.UserException
Throws:
Utils.UserException

doTidyCode

public abstract void doTidyCode(java.lang.String url)
                         throws Utils.UserException
Throws:
Utils.UserException

doHeaders

public abstract void doHeaders(HeaderValue[] headers)

getScript

protected java.lang.String getScript()
Returns the full script from the ScriptAdapter.


insert

protected void insert(java.lang.String s)
               throws Utils.UserException
Inserts new lines into the script. The lines are inserted before a special comment that is included in the output of doNew(). This means that recording can be stopped and restarted, even after the file has been saved and reloaded.

Throws:
Utils.UserException