Table of Contents
Another extension mechanism (besides plug-ins, see Chapter 9, Plug-ins , and filters, see Chapter 11, Filters ) of PETA are data types. A data type provides the facility for strict
checking of assertion values and for the definition of their inherent order for
comparison operators. It is realized as a java class implementing the
de.verit.peta.engine.datatype.Datatype. interface.
The following, demonstrates the usage of a data type. The name of a lecturer can be specified in two formats:
Therefore, the both lecturer specifications in the test data ( Mustermann, Georg, Prof. Dr. and Prof. Dr. Georg Mustermann) are valid and refer to the same person. But comparing both values as normal strings would give the result that they are not equal. Therefore, the data type String can not be used to compare the lecturer's names. To handle this, PETA allows the specification of custom data types, which is explained in this chapter.
![]() | Further information |
|---|---|
|
Detailed information about PETA data types can be found in the PETA-Core Reference Manual. |
To create a new data type for lecturer's names, press the New
datatype
button in the toolbar. In the wizard, set the source folder of
the data type's java file to
TutorialProject/src and enter a package name. Enter
Name as the class name and press the Next
button. Enter a description for this data type on the second page and press the
Finish button to create a java file in the specified package
and open it in the editor.
The following code example shows the implementation of the Name data type. The name is internally stored as title forename surname and compared using this internal format.
Example 10.1. Implementation of the Name data type
package de.verit.peta.tutorial.datatype;
import de.verit.peta.engine.datatype.Datatype;
/**
* Implementation of a peta datatype for the name of persons.
* A name can be specified as 'title forename surname' or as
* 'surname, forename, title'.
*/
public class Name implements Datatype {
/** The embedded value. */
private String value = null;
/**
* @see de.verit.peta.engine.Datatype#init(java.lang.String)
*/
public final void init(final java.lang.String initValue) {
String[] splitted = initValue.split(",");
value = splitted[0].trim();
for (int i = 1; i < splitted.length; i++) {
value = splitted[i].trim() + " " + value;
}
}
/**
* @see de.verit.peta.engine.Datatype#compareTo(Datatype)
*/
public final int compareTo(final Datatype other) {
return value.compareTo(((Name) other).value);
}
}
The new data type can be used in the test cases now. In the tutorial example, it is used to assert, that both lecturers are the same person.
Open the PETA editor with the test case
requestCourseList and expand the last event (the client's
second event). Drag'n'drop the Add Assertion symbol over
the last assertion. In the wizard, enter
both courses lectured by the same lecturer as the name, set the
operator to
== and set the data type to
Name . This assertion shall compare the two names received in the
document. Therefore, press the left Add document button,
press the left Add Constant… button, and enter
courseList/course[1]/lecturer . Then, press the Add
document and after that the right Add Constant…
button, and enter
courseList/course[2]/lecturer . Finally, press the
OK button to add this assertion.