Service Virtualization

Expand all | Collapse all

Trying to invoke a class through Custom Test Step Execution Step which will update values into a database from response xml.

  • 1.  Trying to invoke a class through Custom Test Step Execution Step which will update values into a database from response xml.

    Posted Oct 25, 2017 03:59 AM

    I have a java class which will read a xml from a defined location and store it into a database.

    I have implemented the CustJavaNodeInterface class from lisa core jar.

    Please find below my java class:

     

    public class ParseXmlResponse implements CustJavaNodeInterface{
    final static Logger LOGGER = Logger.getLogger(ParseXmlResponse.class);

    @Override
    public Object executeNodeLogic(TestExec arg0, @SuppressWarnings("rawtypes") Map params)
    throws TestRunException {
    String xmlLocation = (String)params.get("XMLLocation");
    parseResponse(xmlLocation);
    return null;
    }
    @Override
    public ParameterList getParameters() {
    ParameterList pl = new ParameterList("XMLLocation=");
    return pl;
    }
    @Override
    public void initialize(TestCase arg0, Element arg1) throws TestDefException {
    }

    public void parseResponse(String filePath){

    //read xml and store in database

    }

     

    I am not sure on what I should return in the executeNodeLogic() method.

    I am just returning a null value after the execution. Is there any particular which I have to return in this case?

     

    The problem which i am facing here I am able to successfully parse the xml and store into databse only for the first time,for the next consecutive times it is adding entries more then once or repeating the entries.

     

    Can someone help out?



  • 2.  Re: Trying to invoke a class through Custom Test Step Execution Step which will update values into a database from response xml.
    Best Answer

    Posted Oct 25, 2017 08:54 PM

    Hi Venkat,

     

    I'm typically a big proponent for creating DevTest extensions, but based on the description of your use case it doesn't sound like creating a custom test step is necessary. If you're only trying to invoke a Java class method, which will do the XML parsing and DB queries, then you can invoke it directly by writing the code in the Execute script (JSR-223) step (you can find this step under Custom Extensions). Also keep in mind that when you execute your test case with a remote Simulator, you have to make sure the location of the XML file is in the same path on the remote Simulator.

     

    But to answer your original question, that particular method, executeNodeLogic, should implement the logic for parsing the XML file and updating the DB. Since all you're doing is parsing and updating an external DB, then it's fine to return null. On the other hand, if the Java class you're invoking is returning an object, then you could return that object in the method as well.

     

    My opinion is that there's a lot of overhead in creating a custom step for this use case and I recommend you explore the Execute script step for an easier and more portable solution.



  • 3.  Re: Trying to invoke a class through Custom Test Step Execution Step which will update values into a database from response xml.

    Posted Oct 26, 2017 01:41 AM

    Hi Truong, 

    Thanks for your swift response.

    I was initially writing code in execute script method only, but the xml structure consists of several tags which will vary in number for each response.

    That was the main reason why I have written external java code which will be easier in reading the xml and inserting in DB.

     

    The exact problem which I am facing here is, when the logic is executed through a java main class the xml parsing works perfectly, i.e. for each run one instance of xml is being parsed. But when I execute through dev test the xml parsing happens correctly for the first time, but on consecutive run, the xml parsing happens one plus the last execution.

    For each xml execution, 4 rows of DB will be updated.

    so for the first execution, 4 rows will be updated and for the second it will be 8, and so on.

    But when I run from Devtest, for the first run 4 rows are updated in db, for the second run 12 rows are updated, for the third run 24 rows are updated.

    This means for every consecutive execution it is executing 1 plus time the previous execution.