Table of Contents
The PETA test description language has been developed with two aspects in mind:
Keep it simple to be easily learned, and make it extendable to enable adaption to user's
demands. A plug-in extends PETA 's build-in functionality, e.g. to create or
transform data like timestamps, message IDs, or some values that have to be calculated
from other values. It is realized as a Java class that implements the
de.verit.peta.engine.plugin.Plugin interface.
Until now, the implemented test case requestCourseList sends a fixed timestamp in the client's request. Of course, the test case would fail if the server checks this timestamp and declines the request if it does not match a time criterion, for example if the timestamp has to be 'near' the current timestamp. In this case, a timestamp for the current time has to be inserted into the request message. PETA offers the extension mechanism of plug-ins to handle such a situation. In this chapter, a plug-in named Timestamp will be implemented, that returns a timestamp of a specified format. Then, this plug-in will be used in the test case to insert the current timestamp into the request.
![]() | Further information |
|---|---|
|
Detailed information about PETA plug-ins can be found in the PETA Core Reference Manual. |
To create a new PETA plug-in that creates a timestamp, press the
Create a new plug-in
button in the toolbar. In the wizard, set the source folder of the
plug-in's java file to
TutorialProject/src and enter a package name. Enter
Timestamp as the class name and press the Next
button.
Enter a description for this plug-in on the second page, for example
Creates a timestamp in specified format using the current time., and
press the Next button to reach the last page.
To specify the plug-in's argument, press the Add
button, enter
format as the name and activate the Required
checkbox. Keep the other two checkboxes ( Multiple allowed
and Requires key ) unselected and press
OK.
Finally, to leave the wizard, press the Finish
button. A java file will be created in the specified package and opened in the editor.
The following example shows the implementation of the Timestamp plug-in.
Example 9.1. Implementation of the Timestamp plug-in
package de.verit.peta.tutorial.plugin;
import java.text.SimpleDateFormat;
import java.util.Date;
import de.verit.peta.engine.plugin.Plugin;
import de.verit.peta.modules.Arguments;
/**
* Implementation of a peta plugin that creates a timestamp from
* current time.
* The format of the timestamp must be specified by argument
* 'format'.
*/
public class Timestamp implements Plugin {
/**
* Constructor.
*/
public Timestamp() {
super();
}
/**
* @see Plugin#process(de.verit.peta.modules.Arguments)
*/
public String process(Arguments arguments)
throws Exception {
// create formatter from argument
String format = arguments.get("format");
SimpleDateFormat formatter =
new SimpleDateFormat(format);
// get current date
Date currentDate = new Date();
return formatter.format(currentDate);
}
}
The plug-in is now ready for use in the test case. To insert the current timestamp
into the request, expand the operation of the first event, select the template and
open the wizard (right-click, select Properties ). Press
the Add Substitution button and enter
/request/timestamp as the Constant Path
that shall be substituted. To use the plug-in, press the Add
Plug-in button and select Timestamp from the
list of available plug-ins. Timestamp should now appear in
the lower left window. Expand it, select its argument format
and specify the argument's value by pressing Add Constant
and entering the format string yyyy-MM-dd HH:mm:ss.
When the test case is executed now, the current timestamp is sent with the client's request.