Generating test code

During the initialization phase of a code generation request, an object extending the LTTestExtensionPreferences class is created by calling all plug-ins implementing the com.ibm.rational.test.lt.codegen.core.codegenProtocolExtension extension point through their supportFeatures() method.

About this task

The supportFeatures()method gets the feature list of the test model object, and if it determines that it supports these features, it returns the appropriate LTTestExtensionPreferences object. The returned object implements the com.ibm.rational.test.lt.codegen.core.config.IExtensionPreferences interface, which is the public part of the LTTestExtensionPreferences class.

The code generation is controlled by the com.ibm.rational.test.lt.codegen.core.CodeGenerator class. This class uses an EclipseCodegenConfiguration object that stores the hash maps for translators, the model element adapters and the templates that are determined by language element types. The container test elements, data pools, and some other independent protocol-specific elements have their own translators defined. Elements that cannot exist on their own are translated as children of their containing elements by calling the translateChildren() method of the translator.

The code generator determines the proper translator and calls its getTranslationFor() method for the given model element.

The ElementAdapter class with its getAdapterForType() method determines the proper code generation model element for the given Behavior Model element.

Procedure

The translation of test elements involves the following steps:

  1. The test elements are read from the behavior model, and the appropriate translator is determined for each of them.
  2. The language element object is created for the element and its template is determined.
  3. The element attributes are read from the model and their corresponding parameters are substituted in the template.

Results

The generation of the code language elements is recursive and generates the language element tree containing all levels of the execution model test elements, each with the template object instantiated and containing all the requested test substitutions. The tree is implemented by using the language element containers as its nodes. The template substitutions for the language element containers for parameters defining multiple elements are processed by the LangElemCollectionValue class.