Getting the properties of a dataset

When a test asset is associated with a dataset, you can get the properties of a dataset through a custom code. You can also insert a new row into the dataset.

The properties that you can get through a custom code are as follows:

  • Total number of rows

  • Total number of columns

  • Name of the columns

  • The value that is set for the Open mode option

  • The value that is set for the Access mode option

After the test run is complete, you can view the properties of the dataset in test logs. See Viewing test logs.

The following sample custom code provides the properties of the dataset in test logs:

package datasets;

import java.awt.list;

/**
 * @author IBM Custom Code Samples
 */

public class myds implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {

    public myds() {
    }
    public String exec(ITestExecutionServices tes, String[] args) {
         // the name of the dataset is the same as what is shown in the test.
         //The dataset must be added to the test in order to get a controller for it.
        IDataSetController control = tes.getDataSetController("/testproj/myds.csv");
        try
        {
             tes.getTestLogManager().alwaysReportMessage(" Total Rows in DS "+(Integer.toString(control.getTotalRows())));
             control.getAccessMode();
             tes.getTestLogManager().reportMessage(" DS Access Mode is "+(control.getAccessMode()));
             tes.getTestLogManager().reportMessage("DS Open Mode is "+(control.getOpenMode()));
             tes.getTestLogManager().alwaysReportMessage("Column headers in DS "+control.getColumnHeaders().toString());
             control.writeRow(-1, Arrays.asList("a","b","c"), false);
             tes.getTestLogManager().alwaysReportMessage("Total Rows after adding new row in DS "+Integer.toString(control.getTotalRows()));
        }
        
        catch (Exception e)
        {
            tes.getTestLogManager().alwaysReportMessage( e.toString());
// TODO Auto-generated catch block
e.printStackTrace();
}