com.bitmechanic.maxq.generator
Class JavaCodeGenerator

java.lang.Object
  extended by com.bitmechanic.maxq.generator.AbstractCodeGenerator
      extended by com.bitmechanic.maxq.generator.JavaCodeGenerator
All Implemented Interfaces:
IScriptGenerator, ProxyServer.Observer, java.lang.Runnable

public class JavaCodeGenerator
extends AbstractCodeGenerator

Generate a java JUnit test case. Take a look at the CodeGenerator Interface to see how to specify which one you want. The important information is that this class generates Java code.

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

Field Summary
 
Fields inherited from class com.bitmechanic.maxq.generator.AbstractCodeGenerator
assertNumber, END_STATEMENT, headersExist, jtidyConfigFile
 
Fields inherited from interface com.bitmechanic.maxq.generator.IScriptGenerator
EOL
 
Constructor Summary
JavaCodeGenerator(IScriptAdapter adapter)
           
 
Method Summary
protected  java.lang.String createStatement(java.lang.String text)
          Returns the supplied string left padded
 void doAssertResponse(java.lang.String respCode)
           
 void doBodyParameterList(Param[] params)
           
 void doCallUrl(java.lang.String url, java.lang.String method, java.lang.String data, java.lang.String contentLength)
           
 void doEndTransaction()
          Called after all other calls for a particular transaction (request + response).
 void doHeaders(HeaderValue[] headers)
           
 void doLoad()
          Called after a new script has been loaded from file.
 void doNew()
          Called when a new script needs to be begun.
 void doParameterList(Param[] params)
          Implementer must add script code for the parameters provided.
 void doQueryStringParameterList(Param[] params)
           
 void doResponseForFile()
           
 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.
 void doSetCharset(java.lang.String cs)
          Called when the character set for POST requests changes.
 void doSetData(java.lang.String data)
           
 void doStartRecording()
          Called before any processRequest() calls.
 void doStopRecording()
          Called after the last processResponse() call, but may be followed by another doStartRecording() to start the process over again.
 void doTestUrlMessage(java.lang.String url)
           
 void doTidyCode(java.lang.String url)
           
 java.lang.String[] getValidFileExtensions()
          Returns an array of valid file extensions for the type of code generator in use.
 java.lang.String parseTestName()
          Parses the name of the test out of the script.
 void setStruts(boolean struts)
          Called if the processResponse find that the response contains the Struts token
 
Methods inherited from class com.bitmechanic.maxq.generator.AbstractCodeGenerator
close, getDefaultTestName, getScript, getScriptAdapter, getTestName, getTestPath, getTimeElapsedSinceLastestRequest, insert, isCpRspToFile, isCpRspToStdout, isFirstRequest, processRequest, processResponse, run, setDefaultTestName, setTestName, setTestPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaCodeGenerator

public JavaCodeGenerator(IScriptAdapter adapter)
Method Detail

setStruts

public void setStruts(boolean struts)
Description copied from class: AbstractCodeGenerator
Called if the processResponse find that the response contains the Struts token

Specified by:
setStruts in class AbstractCodeGenerator

getValidFileExtensions

public java.lang.String[] getValidFileExtensions()
Description copied from interface: IScriptGenerator
Returns an array of valid file extensions for the type of code generator in use.

Returns:
array of valid file extentions

doNew

public void doNew()
Description copied from interface: IScriptGenerator
Called when a new script needs to be begun. This will not be called when an existing script is loaded from file.

The script should output its full class name during this call to ensure that its generator can be recognised if it is saved and reloaded.


doCallUrl

public void doCallUrl(java.lang.String url,
                      java.lang.String method,
                      java.lang.String data,
                      java.lang.String contentLength)
               throws Utils.UserException
Specified by:
doCallUrl in class AbstractCodeGenerator
Throws:
Utils.UserException

doAssertResponse

public void doAssertResponse(java.lang.String respCode)
                      throws Utils.UserException
Specified by:
doAssertResponse in class AbstractCodeGenerator
Throws:
Utils.UserException

doParameterList

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

Specified by:
doParameterList in class AbstractCodeGenerator
Parameters:
params - Query string and body parameters, without distinction.
Throws:
Utils.UserException

doTestUrlMessage

public void doTestUrlMessage(java.lang.String url)
                      throws Utils.UserException
Specified by:
doTestUrlMessage in class AbstractCodeGenerator
Throws:
Utils.UserException

doSetData

public void doSetData(java.lang.String data)
               throws Utils.UserException
Specified by:
doSetData in class AbstractCodeGenerator
Throws:
Utils.UserException

doTidyCode

public void doTidyCode(java.lang.String url)
                throws Utils.UserException
Specified by:
doTidyCode in class AbstractCodeGenerator
Throws:
Utils.UserException

doResponseForStdOut

public void doResponseForStdOut(java.lang.String url)
                         throws Utils.UserException
Specified by:
doResponseForStdOut in class AbstractCodeGenerator
Throws:
Utils.UserException

doResponseForFile

public void doResponseForFile()
                       throws Utils.UserException
Specified by:
doResponseForFile in class AbstractCodeGenerator
Throws:
Utils.UserException

doSetCharset

public void doSetCharset(java.lang.String cs)
                  throws Utils.UserException
Description copied from class: AbstractCodeGenerator
Called when the character set for POST requests changes.

Specified by:
doSetCharset in class AbstractCodeGenerator
Throws:
Utils.UserException

doStartRecording

public void doStartRecording()
Description copied from interface: IScriptGenerator
Called before any processRequest() calls.


doStopRecording

public void doStopRecording()
Description copied from interface: IScriptGenerator
Called after the last processResponse() call, but may be followed by another doStartRecording() to start the process over again.


doSave

public void doSave(java.lang.String path,
                   java.lang.String fileName)
Description copied from class: AbstractCodeGenerator
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
Overrides:
doSave in class AbstractCodeGenerator

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
Overrides:
doLoad in class AbstractCodeGenerator

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
Overrides:
parseTestName in class AbstractCodeGenerator
Returns:
test name if test has been loaded or saved. Empty otherwise.

doHeaders

public void doHeaders(HeaderValue[] headers)
Specified by:
doHeaders in class AbstractCodeGenerator

createStatement

protected java.lang.String createStatement(java.lang.String text)
Returns the supplied string left padded

Parameters:
text -

doEndTransaction

public void doEndTransaction()
Description copied from class: AbstractCodeGenerator
Called after all other calls for a particular transaction (request + response).

Specified by:
doEndTransaction in class AbstractCodeGenerator

doQueryStringParameterList

public void doQueryStringParameterList(Param[] params)
                                throws Utils.UserException
Specified by:
doQueryStringParameterList in class AbstractCodeGenerator
Parameters:
params - Query string parameters.
Throws:
Utils.UserException

doBodyParameterList

public void doBodyParameterList(Param[] params)
                         throws Utils.UserException
Specified by:
doBodyParameterList in class AbstractCodeGenerator
Parameters:
params - Body parameters.
Throws:
Utils.UserException