This is an old revision of the document!
Writing a Java Handler
Java Handler is a java class you write for a specific model to perform the desired action when model executes, which is typically used to perform test automation, saving test steps (test sequence) into a file (either tab delimited file or automation script for external test automation tools) or visualize workflows.
Create Java Handler
The java handler class must implement com.webmbt.plugin.PluginHandlerIntf.
The easiest way to create the handler class is to let TestOptimal generate a skeleton code for you from your model. To do this, go to Model Property and click on “Generate” link next to “Java/Groovy Class” field.
The generated java code (skeleton code) should be displayed as a text file. Copy and paste the java code into your favorite java editor and add your implementation java code for each class method accordingly. See example java code generated.
You may need to add webmbt.jar and plugins.jar files to your class path in your IDE.
Deploy Java Handler
There are two ways to deploy the java handler class
- Java source code
- Compiled jar file
Deploy Java Source File
Copy your java handler source code (*.java) into one of the following locations:
- your model/ - preferred location so that your java handler code is stored within your model.
- script/ - common folder accessible to all models.
The source code file name must represent the full class path. For example, if you declare java handler class within a java package, for example com.abc.handler.myClass, then the java source code file must be named com.abc.handler.myClass.java and placed at the top level of your model folder - in another words, do not place your java source file in the nested folder com/abc/handler/.
Your java source code will be dynamically compiled - you do not need to restart TestOptimal server as required for Deploy Jar File option.
To use this option, you must have installed JDK in your system path and have tools.jar in your JDK lib/ folder.
Deploy Jar File
You may pre-compile your java handler class into a jar file and copy the jar file into lib/ folder. You must restart TestOptimal server each time you copy a newer version of the jar file.
Which Deployment Option Should I Use?
The advantage of Deploy Java Source Code is that you can make changes to the java source code and just re-run the model to test your changes.
However the disadvantage of this option is that all of the dependent java packages/classes your handler uses must have been added to TestOptimal server's classpath (lib/ folder) in the form of jar files.
The advantage of Deploy Jar File is that you can package up all java classes including your handler class into a nice jar file and deploy it. This option works the best if you have to create many java classes besides handler class necessary to perform the model actions.