Service Virtualization

Expand all | Collapse all

how to get vsi response match in script

Jump to Best Answer
  • 1.  how to get vsi response match in script

    Posted 03-16-2018 09:07 AM

    Hi ,

     

    I am writing a script in which i want to store match result in one property and depending on that i want to apply  assertion.

     

    when a request comes to vsm it checks that request in vsi and respond accordingly either it will find excat match,signature or no match.

     

    i want to know how i can know this. is there any property for this



  • 2.  Re: how to get vsi response match in script
    Best Answer

    Posted 03-16-2018 11:12 AM

    I do not know with certainty that the below still works.  No guarantees the code fragment is accurate -- untested.

    You might try the following in a Scripted Assertion or JSR step after the VSI Selection Step:

    String str = lisa_vse_response.get(0).getBodyAsString();

    if ( str.contains( "<head><title>404 Not Found</title></head") )

    {  // the standard Service Image response as seen in the VSI contains HTML

        _logger.info( "The VSI selected a Service Image Not Found response" )

        match = "SI NOT Found";

    else if ( testExec.getStateObject("lisa.vse.matched.transaction") instanceof com.itko.lisa.vse.stateful.model.TransactionNode) 

    {    // the VSI selected a META response

        _logger.info( "The VSI selected a META txn response" );

        match = "META";

    }

    else

    {  // The VSI selected a specific transaction

        _logger.info( "The VSI selected a specific txn response" );

        match = "Specific";
    }

     

    // if Scripted Assertion, return true and set the IF False, Fail the Test setting

    // this way if the script has an error it will fail, only success returns true

    return true;

    // if JSR step, you could return a value for example 'match'

    return "The VSI selection was: " + match;

     

    - Start the service in ITR mode.

    - Send a request to the service.

    - Step through the service and let the SI Selection Step execute

    - After this step executes, look at the ITR Events for the logger displays

    - Verify the response against the Events

    - If you deploy this code fragment without removing _logger.info(... the output will be dumped into the vse.log everytime this service is executed so take care if you take this approach as you could fill up your logs.



  • 3.  Re: how to get vsi response match in script

    Posted 03-16-2018 12:08 PM

    ok. let me try.

     

    i was using below script

    import com.itko.lisa.vse.stateful.model.MatchTolerance;
    import com.itko.lisa.vse.stateful.model.Request;
    import com.itko.lisa.vse.stateful.modelTransactionNode;
    Request r=testExec.getStateObject("lisa.vse.request");
    MatchTolerance match=r.getMatchTolerance();
    String j=match.toString();
    String m=match.getCodeText();
    testExec.setStateValue("Match code",m);
    testExec.setStateValue("Match String",j);

     

    issue is i am getting value as exact even if signature and no match are there.



  • 4.  Re: how to get vsi response match in script

    Posted 03-16-2018 12:16 PM

    Understood.  I do not know the specific answer.

    Using match tolerance off the Request object may not work. My code fragment tries to make the determination by looking at the actual Response object that was selected. But, as I said, I don't know for certain that my code works. I did not have time to play with it to see if it works. 



  • 5.  Re: how to get vsi response match in script

    Posted 03-16-2018 12:25 PM

    lisa.vse.request contains the incoming request & does not contain information about which transaction in the VSI it matched against.

     

    As J_NeSmith mentioned lisa.vse.matched.transaction is the property which contains the matched transaction & would have information about which type of match was returned from VSI.



  • 6.  Re: how to get vsi response match in script

    Posted 03-16-2018 12:37 PM

    Hi Prem,

     

    lisa.vse.matched.transaction is of type com.itko.lisa.vse.stateful.model.TransactionNode and i couldnt find any function in class TransactionNode which can give me info about type of match.

     

    If you know then please help me with this.



  • 7.  Re: how to get vsi response match in script

    Posted 03-16-2018 01:15 PM

    The code fragment is not firing any functions / methods on the TransactionNode class. 

    When a matched transaction is an instance of type TransactionNode, this by itself is an indicator that the response is a META (and maybe an SI) response. The script rules out the SI response by checking the SI Not Found response body first then the instanceof check. 

     

    I executed a quick test of the above script on a simple use case on DT 10.2, and I was able to successfully trap all three scenarios (Not Found, META, and specific). 

     

    There is a missing ";" in the script at the end of line 4. Fix that, add the script as a JSR step (after removing the return true Assertion logic), execute a test in ITR mode, and review the response from the JSR step. 

     

    It sounds like you are trying to peek into the actual response transaction for some other information beyond the general information. If you are trying to get to the exact specific response in the model, you can see that from the Match information in Portal's Inspection Viewer.



  • 8.  Re: how to get vsi response match in script

    Posted 03-16-2018 01:24 PM

    so when a matched transaction is Exact is not instanceof TransactionNode?



  • 9.  Re: how to get vsi response match in script

    Posted 03-16-2018 01:31 PM

    I believe you are correct.  However, I do not know what type of instance the SI Not Found response belongs to. I did not look closely, but I suspect an SI Not Found is also an instance of TransactionNode. This is the reason I checked SI Not Found response body before simply checking for instance of.



  • 10.  Re: how to get vsi response match in script

    Posted 03-16-2018 01:33 PM

    Thanks. this info will help me.