Using additional data files

Use custom data providers to define the tests that you want to do.

When using custom data providers with test suites, you must start by generating a test data provider file (.tstx), that defines the tests that you want to do. In that file, you can define custom properties that appear as fields to fill in when defining a test suite.

If you want to go beyond these simple properties, you can actually attach a custom file to your test suite, and your custom data provider implementation has access to that file. This file can be of any type, and be stored and versioned within the test suite.

Customizing the test data provider file (.tstx)

After generating your test data provider file (.tstx), you must edit it to set your custom data provider. While doing so, you must define a property with the value #{jobParameters['execution.scenario.file.bytes']} and a custom name of your choosing that holds your additional data file.

For example, if the fully qualified name of your custom data provider implementation class is com.mycompany.mydecision.MyDataProvider and you want to set myDataFile as your property name, your custom data provider section looks as follows:
 <jsl:reader ref="com.mycompany.mydecision.MyDataProvider">
     <jsl:properties>
           <jsl:property name="myDataFile"
          value="#{jobParameters['execution.scenario.file.bytes']}"></jsl:property>     
     </jsl:properties>
 </jsl:reader>

The property name that you set is used in your custom data provider implementation to retrieve your data file.

Note: The additional data file can be used in combination with custom properties.

Retrieving the data file from your custom data provider implementation

The data file is made available by using the simple provided API :
com.ibm.rules.cdi.runtime.ext.DecisionRunnerContext#decodeResource(String resource, boolean uncompressData)

For example, if you named the property myDataFile, like in the example in the previous section, you can retrieve your data file as follows:

 import com.ibm.rules.cdi.runtime.ext.DecisionRunnerContext;
 import
        java.io.Serializable;
 import javax.batch.api.BatchProperty;
 import
        javax.batch.api.chunk.AbstractItemReader;
 import javax.inject.Inject;

 public class MyDataProvider extends AbstractItemReader {
   @Inject
   @BatchProperty(name = "myDataFile")
   String dataFile;

   DecisionRunnerContext decisionRunnerContext;

   public void open(Serializable checkpoint) throws
        Exception {
      // creating an instance of
        DecisionRunnerContext to use the API
      this.decisionRunnerContext = new DecisionRunnerContext();
      // using the API to retrieve the data file content
      byte[] dataFileContent =
        (byte[])this.decisionRunnerContext.decodeResource(this.dataFile, false);
   }

   public Object readItem() throws Exception {
      // do something with the file content
   }
 }

Defining the test suite

When you define your test suite in Decision Center, select Test Data Provider (.tstx) with additional data instead of Test Data Provider (.tstx). You must then attach your custom data file in addition to the .tstx file.