Implementing data correlation for test generation

To implement data correlation for test generation, become familiar with these classes: com.ibm.rational.test.lt.datacorrelation.testgen.proto.IProtoElementAdapter, com.ibm.rational.test.lt.datacorrelation.testgen.DataCorrelator, and com.ibm.rational.test.lt.datacorrelation.testgen.IDCStringLocator.

To implement data correlation for test generation and script editing, your model elements must extend com.ibm.rational.test.lt.models.behavior.data.DataSource and com.ibm.rational.test.lt.models.behavior.data.Substituter so that you can associate data sources and substituters with your model elements. Also, when you extend those classes, make sure you implement the code to make Substituters and DataSources persist in your model. For more information, refer to the model documentation.

You need to create your own data correlation plug-in to extend the extension point DCTestgenProto, which is defined in the plug-in com.ibm.rational.test.lt.datacorrelation.testgen. To extend the extension point, your code must implement the interface IProtoElementAdapter which is defined in com.ibm.rational.test.lt.datacorrelation.testgen.proto. Then, when you extend the DCTestgenProto extension point, use the following items:
  • ID - This is the unique ID of your extension.
  • Name - The name that is meaningful for you.
  • Point - com.ibm.rational.test.lt.datacorrelation.testgen.DCTestgenProto extension point
.
The other element details are:
  • class - This is the full name of the class (including plug-in name) that implements IProtoElementAdapter.
  • protoType - The type of model element that this plug-in handles, for example, in HTTP, the model element that is handled is com.ibm.rational.test.lt.models.behavior.http.HTTPRequest.
  • generic - This is a boolean that can be true or false. If it is true, this means that if there are other plug-ins that handle the same protoType, this plug-in will be called last.
  • uniqueID - This ID is unique among all data correlators.

After you have extended the data correlation extension point, the main data correlation engine will call your code with all the elements of the model type that you defined.

There are two parts to data correlation at testgen time. The first part is automatic data correlation which happens at testgen time. This will happen through a call to DataCorrelator.CorrelateAll(). When this method is called automatically by testgen, it will in turn call two main methods in your plugin. Those methods are IProtoAdapter.findSubs() and IProtoAdapter.findReference(). The findSubs() method should return a list of substituters that are found for the current element that is passed into your method, and null if there were no substituters found. The findReference() method should try to find a reference for the substituter passed into it. You start looking for references at the element before the substituter and keep working backwards in the testsuite until you find a suitable reference. If no reference is found, return null. CorrelateAll is used to find all correlations that you can so that the user does not have to manually find them at test editing time.

The other parts of the IProtoAdapter class are called at test editing time when a user wants to create a substitution site, a reference, or make a correlation between a substitution site and a reference. If you are creating your own type of Substituters or DataSources, your makeDataSource() and makeSub() methods will be used for that. You will be passed the DCStringLocator class with all the information about offsets and text that you need. Use this DCStringLocator to determine what substituter or data source you want to create and then call back into IDataCorrelator. Correlations, substituters, and data sources are created in the model for you. Read the documentation on the IDataCorrelator class to learn which methods are right for your purposes.