Service Virtualization

  • 1.  How to search and map the request and response parameters in an excel sheet

    Posted Feb 20, 2017 06:24 AM

    Does anyone know the java script to search for the request parameters of a dynamic request in an excel sheet and return the corresponding response parameters from the same row?

    For Eg:

    Consider the calculator WSDL with request parameters X and Y for the Addition operation.I have an excel sheet with three columns X,Y and Z, where X and Y are request parameters and Z is the response parameter.When I pass a request X=5 and Y=6 in my virtual service request,the service has to search for the row where X=5 and Y=6 and return the corresponding 'Z value' in the response.

     

    Could anyone help with the java script for this? I tried the following:

     

     

    var excel = new ActiveXObject("Excel.Application");
    var wb = excel.Workbooks.Open("D:/LISA/MISC/XYZ.xlsx");
    var ws = wb.Sheet1;
    var cell = ws.Cells.Find("10");
    return(cell.Row);
    //excel.Quit();

     

    But it gave error saying:   Unknown class: ActiveXObject : at Line: 1 :...............



  • 2.  Re: How to search and map the request and response parameters in an excel sheet
    Best Answer

    Broadcom Employee
    Posted Feb 20, 2017 07:06 AM

    For a simple matching requirement like this, there's no need to externalise the data. Just have a specific transaction that matches on X = 5 and Y = 6, and make the response Z value equal to whatever you like. It could be a calculation (something like {{=request_X + request_Y}}), or it could be a hard-coded value.

     

    If you want to use scripting to interact with an external Excel document, this will slow the virtual service to the speed of the extra network calls to your Z: drive, the opening, reading and closing of the document. If you still want to do it, don't use ActiveX. Instead, use Apache POI, which is what DevTest uses internally for interacting with MS Office format documents.

    POI API Documentation 



  • 3.  Re: How to search and map the request and response parameters in an excel sheet

    Posted Feb 23, 2017 12:13 AM

    Thank you Rick.Could you please help me with the code if possible?



  • 4.  Re: How to search and map the request and response parameters in an excel sheet

    Broadcom Employee
    Posted Feb 23, 2017 06:45 PM

    What are your reasons behind not using the built-in functionality for matching and responding? I would like to see if I can persuade you that this is usually the best way of creating multiple responses. If I can't persuade you, you might want to read a blog post:

    So you want to keep count in a virtual service? 

     

    If I still can't persuade you with any of the above, there are hundreds of examples on the Internet for POI usage. You could start here:

    Read / Write Excel file (.xls or .xlsx) using Apache POI · GitHub