Array Generator DPL
To run a javaJava code with array arguments in AppvanceAppvance, use the Array generatorGenerator DPL.DPL. In order toTo execute Java code withthat thehas a main method in Scenario Builder, you need to select anthe Array Generator DPL type and String[] from the actionsActions dropdown. Add the argument name and pass a value by clicking onthe Add Val link.
The main method usesreceives anthe array from the generator.
UsingWith ArrayGeneratorthe Array Generator DPL, you can send an array of values as a single parameter thatcontaining hasmultiple insideentries, manyfor entriesexample a String array:
[ "string1", "string2", "string3" ].
SoThis nowallows you canto provide an input parameter for a method that requires an array-like parameter:
public void myMethod(String[]) args) {
}
You can also haveuse Object arrays-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 arraysarrays: available:Object, Object,String, String,Integer, Integer,int, int,Byte, Byte,byte, byte,Double, Double,double, double,Short, Short,short, short,Float, Float,float, float,Character, Character, Boolean, Boolean.
Sample Java Code with an int array[]:Array
package com.package1;
import java.util.Arrays;
public class Array {
public static void main(StringString[] args[])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(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 forfrom the aboveJava javacode code.above. GotoGo to Scenario builderBuilder and select athe Functional Test test Test type. Add a test case withusing the Java Test type and browse to the above-created.jar jarfile file.you created. The code above java code consists oftakes two argumentsarguments: the first withis a String, and the second argumentwithis an int arrayarray. argument. You need to passPass the argumentarguments in the same order in Appvance to runso the scenario runs successfully.
Two arguments using array generator
EnterSet the log level to 100% logs in the Options panel. Save and play the scenario in a controllerController window.
Output:
Two arguments using array generator
Last updated: February 17, 2023
If you have any feedback on this topic, please contact us at documentation@appvance.ai