Array Generator DPL (Test Scenario, Functional Test)
To run Java code with array arguments in Appvance, use the Array Generator DPL. To execute Java code that has a main method in Scenario Builder, select the Array Generator DPL type and String[] from the Actions dropdown. Add the argument name and pass a value by clicking the Add Val link.
The main method receives the array from the generator.
With the Array Generator DPL, you can send an array of values as a single parameter containing multiple entries, for example a String array:
[ "string1", "string2", "string3" ]
This allows you to provide an input parameter for a method that requires an array-like parameter:
public void myMethod(String[] args) {
}
You can also use Object arrays. Example:
[
{ name: 'Honda', models: [
{ name: 'Accord', features: ['2dr', '4dr'] },
{ name: 'CRV', features: ['2dr', 'Hatchback'] },
{ name: 'Pilot', features: ['base', 'superDuper'] }
] },
{ name: 'Toyota', models: [
{ name: 'Prius', features: ['green', 'superGreen'] },
{ name: 'Camry', features: ['sporty', 'square'] },
{ name: 'Corolla', features: ['cheap', 'superFly'] }
] }
]
Types available for arrays: Object, String, Integer, int, Byte, byte, Double, double, Short, short, Float, float, Character, Boolean.
Sample Java Code with an int Array
package com.package1;
import java.util.Arrays;
public class Array {
public static void main(String[] args) throws Exception {
}
public void printArray(String message, int array[]) {
Arrays.sort(array);
System.out.println(message + ": [length: " + array.length + "]");
for (int i = 0; i < array.length; i++) {
if (i != 0) {
System.out.print(", ");
}
System.out.print(array[i]);
}
System.out.println();
int index = Arrays.binarySearch(array, 2);
System.out.println("Found 2 @ " + index);
}
}
Create a .jar file from the Java code above. Go to Scenario Builder and select the Functional Test test type. Add a test case using the Java Test type and browse to the .jar file you created. The code above takes two arguments: the first is a String, and the second is an int array. Pass the arguments in the same order in Appvance so the scenario runs successfully.
Two arguments using array generator
Set the log level to 100% in the Options panel. Save and play the scenario in a Controller window.
Output:
Two arguments using array generator
If you have any feedback on this topic, please contact us at documentation@appvance.ai