Service Virtualization

 View Only
  • 1.  Java Script In CA LISA

    Posted Aug 30, 2017 09:28 AM

    Hi All,

     

    Am new to CA LISA, am not able to run all the JAVA Script commands in CA LISA.

    Kindly assist me in  using JAVA Scritp in CA LISA.

     

    * Am currently using a fuction "testExec.getStateValue("PropertyName").equals",I need functions to compare 2 values (Greater than, lesser than, Greater than Equal to, ect)

    * I need script to write my own function and call the same in my script.

    * Can i use switch Case? Pls share the script for the same.

     

    Thanks,

    Jude Joseph



  • 2.  Re: Java Script In CA LISA

    Posted Aug 30, 2017 10:32 AM

    import com.itko.lisa.vse.stateful.model.TransientResponse;
    import java.util.List;

    String variable_1,variable_2;

    variable_1=testExec.getStateValue("PropertyName");

    testExec.setStateValue("variable_1", variable_1);

    variable_2=testExec.getStateValue("PropertyName");

    testExec.setStateValue("variable_2", variable_2);

    if(variable_1.equals(variable_2){

    //To_Do statements

    }

     



  • 3.  Re: Java Script In CA LISA
    Best Answer

    Posted Aug 30, 2017 02:11 PM

    Jude Joseph,

     

    Perhaps a switch statement isn't the right approach in this case as your comparisons are based on logical operators (less than, greater than). Although you may be able to use a switch statement it will be easier to read and maintain the logic using if/else statements.

     

    Can you confirm if your property values are numbers or characters? If they are characters then would one value be greater than another value based on the LENGTH of the string?

     

    In case the values are numerical you need to first cast them into either Integers or Floats/Doubles before comparing the values. For example:

     

    // assign propertyValueStr the value of property "PropertyName"

    String propertyValueStr = testExec.getStateValue("PropertyName");

    // cast the string value of propertyValueStr to a double and assign it to propertyValueNum

    double propertyValueNum = Double.parseDouble(propertyValueStr);

    if (propertyValueNum > 2.0) {

      // do something if it's greater than 2.0

    } else if (propertyValueNum < 2.0) {

      // do something if propertyValueNum is less than 2.0

    } else {

      // default...assumes propertyValueNum == 2.0

      // do something

    }

     

    In case it is a string value and you are comparing the length of the string then your code will look something like this:

     

    // assign propertyValueStr the value of property "PropertyName"

    String propertyValueStr = testExec.getStateValue("PropertyName");

    String propertyValueStrLength = propertyValueStr.length();

    if (propertyValueStrLength > 2) {

      // do something if the length is greater than 2

    } else if (propertyValueStrLength < 2) {

      // do something if length is less than 2

    } else {

      // default...assumes length == 2

      // do something

    }