Reading and writing data from a dataset

When a test is associated with a dataset, you can extend the test either by reading or writing the dataset values from the custom code.

The data that you write into the dataset is saved only when you set Open mode to Shared (for all test executions) in the Edit Dataset window. In other open modes, the modified data is used only for the test run.

The following sample custom code reads and writes the data from the dataset:

package datasets;

import java.awt.list;

/**
* @author HCL 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 {
        // once you have the controller you can get a row
        DataSetRow row = control.getNextRow();
        // returns a string representation of the row
        row.getEntireRow();
        // alternatively you can get individual values by the column name
        row.getValue("Column1");

        // you can also write a new row to the dataset
        // -1 means append to the end
        // alternatively you can specify a row number and whether to overwrite that row or to insert a new row at the spot
        control.writeRow(-1, Arrays.asList("a", "b", "c"), false);
      } catch (Exception e) {
            tes.getTestLogManager().alwaysReportMessage( e.toString());
            // TODO Auto-generated catch block
            e.printStackTrace();
       }
        return null;
        // or whatever you want to return here
      }