Service Virtualization

 View Only
Expand all | Collapse all

CA Lisa Web service Virtualization -How to access the deployed virtual web service?

  • 1.  CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Dec 28, 2016 01:30 AM

    Hi ,

    I am Using CA Lisa DevTest 9.1.
    I have similar doubt in visualizing my Get rest web service and tried what is mentioned here "https://communities.ca.com/message/241943476?commentID=241943476#comment-241943476 ". I am able to create and deploy virtual service, but not able to( or don't know how to) access the running virtual service. Can you please help in my case?

    //============================================================

    Here is my Request-req.txt file content,

    //============================================================
    GET /WebService/rest/Sample/method/5 HTTP/1.1
    Accept: application/json
    Content-Type: application/json
    Host: ServerIP:Port # in which my original webservice is hosted
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1.1 (java 1.7)
    Accept-Encoding: gzip,deflate

    //============================================================

    And my Response-rsp.txt file content,

    HTTP/1.1 200
    {'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']}

    //============================================================

    My Original web service url is http://localhost:8080/WebService/rest/Sample/method/5 , 
    When I try this url in my browser, Iam getting this result 

    {'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']}

     

    But When I access the same one as the virtual service from my browser,

    http://localhost:VirtualServicePortNO/WebService/rest/Sample/method/5 , 

    I am getting a blank page. On F12 I am getting response code as 200, but failed to load response data.

    Please refer the attached error images.

     

    Thanks in advance.



  • 2.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Broadcom Employee
    Posted Dec 28, 2016 09:23 AM

    Is the Virtual Service Environment service running on localhost?  

    http://localhost:VirtualServicePortNO/WebService/rest/Sample/method/5

     

    The <host name > should be the host where VSE is running.  Click on  Server Console from the Main Menu in the Workstation ,  that should tell you where VSE is . 

    If VSE is on the same box  ( localhost) then you could try to use  IP address. 

     

    Thanks

     

    Shiney.



  • 3.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Dec 29, 2016 07:47 AM

    Hi Shiney Abraham,
    yes, VSE is running in my localhost. I also tried with IP address. Its same. But when i try with this rsp.txt file,

    //============================================================

    Response-rsp.txt file content,
    {'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']}   

    //============================================================

    (diff bw prev and this is - I removed this "HTTP/1.1 200" line)

    I am getting the same response what I have mentioned in the file.  But I don't know how to get response based on input param.
    Please help me with this.
    Thanks in advance.



  • 4.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Broadcom Employee
    Posted Dec 29, 2016 09:15 AM

    Can you attach your  VSM/VSI  ? 

     

    Thanks

     

    Shiney.



  • 5.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Broadcom Employee
    Posted Dec 29, 2016 10:09 AM

    It looks like your JSON response is not valid.   I ran this http://jsonlint.com/   and got an error. 

     

    HTTP/1.1 200
    {'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']}

     

    http://jsonapi.org/examples/



  • 6.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Dec 30, 2016 12:04 AM

    {'friends': ['Michael', 'Tom', 'Daniel', 'John', 'Nick']} this json is just hard coded output of my web service.
    This is valid only, In  http://jsonlint.comits expecting double quotes instead of single quotes. 
    So when i changed it, its validating. 

    Instead I want to create request response pairs for a simple get rest web service, that will take 2 input parameters and give the sum of it.  web service I have written. But I am not able to write response and request files for that case.

    How should I write the response text file for that case?? 
    Can u pls help me with that. 



  • 7.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Dec 29, 2016 04:21 AM

    Have you tried loading the Portal Dashboard and see if there is a match for the request?



  • 8.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Dec 30, 2016 12:19 AM

    I am not familiar with portal dashboard. So not sure how to check it.



  • 9.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Broadcom Employee
    Posted Dec 30, 2016 03:49 PM

    Please open a ticket with CA Support.  We can do a webex to look at your requirement.



  • 10.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Jan 02, 2017 01:07 AM

    Sorry I was not able to raise ticket/case. I ll share my files. Can u please guide me how to write request response for this web service.

     

    //==============================WebService========================

    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.QueryParam;
    import javax.ws.rs.core.MediaType;

     

    @Path("/Sample")

    public class WebServiceServer {
       @GET
       @Path("/method")
       @Produces(MediaType.TEXT_HTML)

       public String sampleMethod (@QueryParam("a") int a,@QueryParam("b") int b)
       {
          String output=null;
          try {
                System.out.println("Entered webservice for the values ::: ---a--"+a+" and b--"+b);
                int result=a+b;
                output="Sum of 2 numbers ::: "+a+" + "+b+" = "+result;
            }
            catch (Exception e) {
                   e.printStackTrace();
             }
             return "<html> " + "<title>" + "Result" + "</title>"+ "<body><h1>" +output+ "</body></h1>" + "</html> ";
       }   

    }
    //==================================================================

    This is my web.xml

     

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>Student</display-name>
    <welcome-file-list>
    <welcome-file>home.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>webpack</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    </web-app>

    //=================================================================

    This is home.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>Sum of Two Numbers !!!</h1>
    <form action="http://localhost:8080/WebService/rest/Sample/method" method="GET">
    <label>First number:<br></label>
    <input type="text" name="a"><br>
    <label>Second number:<br> </label>
    <input type="text" name="b">
    <input type="submit" value="Submit">
    </form>
    </body>
    </html>

    //===============================================================

    The url is http:localhost:8080/WebService/
    When I run this web service -> I am getting the homepage and if I give 2 numbers and submit, its returning the sum.

    //===============================================================

     

    When I try this through create virtual service by recording --> 
    I was getting correct responses from the virtual service for the input given during recording time. But after stop recording and deploying it as service, and access the same virtual service, I am getting correct answers for the request parameters(input numbers) which I gave during recording. If i give some different numbers then its not working correctly. I don't know where I made mistake.

     

    Also I want to know, how to write request response pair files for this web Service. If u want me to share any other files for understanding, pls let me know. Please guide me in solving this.

    Thanks in advance.



  • 11.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?
    Best Answer

    Broadcom Employee
    Posted Jan 02, 2017 09:22 AM

    You need to edit the response. In it, you have a hard-coded "result" value. You should find that it responds with this value every time. You need to change the value to something like:

    {{=request_a+request_b;}}

    assuming that the names "a" and "b" are being passed through as tags to your web service request.

     

    Your entire output line would be something like this:

    Sum of 2 numbers ::: {{=request_a;}} + {{=request_b;}} = {{=request_a+request_b;}}

     

    What is your reason for wanting to place logic in a virtual service? In general, it's the wrong thing to do. Even in your trivial example, you need the tester to work out for themselves what the response should be. With the default behaviour, we KNOW what the response is going to be for a valid request, and we can respond in lots of interesting ways for other input combinations (errors, timeouts, etc).



  • 12.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Jan 03, 2017 01:10 AM

    Finally it worked. Thank you so much. I am able to get dynamic response this way.
    Actually I wanted to do a simple poc to show that the original service is replaced by the virtual service. So tried with a simple add logic. 
    Can u pls explain me why logic should not be used in virtual service? If not for logic, what else should be done in virtual service. Since I am new to virtual service, I am not able to understand your point.. 



  • 13.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Posted Jan 03, 2017 08:19 AM

    Hi sindhuget.1, I believe Rick's recommendation is that developers should attempt to make virtual assets as data driven as possible.  This means that a given request has a known (or expected) response.  This approach aids the testing team or developer because they control the scenario based on the data sent to the virtual service and know what the expected response will be.  

     

    The idea of your scenario summing two numbers and returning the result in the response is something that we tend to think of as business logic.  One reason we recommend against the approach of adding business logic is that business logic can add complexity and has the potential to result in increased maintenance because logic is captured, exposed, and maintained in more than one place (i.e., your service and your live service). 

     

    For example, the scenario above sums two values and responds with the result.  This is a reasonably simple amount of business logic.  However, what happens if the business introduces a new requirement such as sum the two numbers, multiply by 1.75, and divide by 2 only when the product code is 12345?  The result is the introduction of a new set of business logic which equates to a modification in both the live service and the virtual service. And, what happens when new requirements are added such as the introduction of a requirement "when the date is Thursday afternoon and any product code other than 12345, then the two input values should be summed with no multiplication or division."  Each of these requirements adds to the original set of business requirements causing the virtual service to quietly expand its logic to provide calculations rather than responses.   

     

    So at the risk of speaking on Rick's behalf, the goal is to reduce as much business logic as possible and only introduce it when there is no other way around the requirement.  The notion of adding business logic to the service starts to deviate from the concept of the service being "built for a purpose" into a concept of the service having all of the behaviors of the live system.  Having said this, there are valid cases where adding business logic to a virtual asset is unavoidable.  The goal is to isolate and minimize those cases as much as possible.  

     

    In your POC model, you might consider that the service is built for a specific purpose which is to respond to one of five (5) input data scenarios. Four specific requests are set up with accurate responses and a META transaction is designed to catch and return a generic response for all other requests sent to the service.

    If val1 = 2 and val2 = 4, response is 6

    if val1 = 1 and val2 = 5, response is 6

    if val1 = 0 and val2 = 0, response is 0

    if val1 = 7 and val2 = 14, response is 21

    All other responses receive META response of 14.

    In the above, the developers are not really sending random values.  They sending actual request data that has a specific desired response.  For example, if the request val1 = 2 and val2 = 4, the Live Service is expected to return 6.  Any request that does not match one of the above specific requests gets a value of 14.  The META satisfies the need for the interface to remain in tact, but has the ability to "lie" about the response.  The result is that the service does not have to contain every possible combination of request/response characteristics to make it usable.  



  • 14.  Re: CA Lisa Web service Virtualization -How to access the deployed virtual web service?

    Broadcom Employee
    Posted Jan 03, 2017 08:36 AM

    When you use a virtual service, you are testing the thing that calls the virtual service. You are not testing any back-end logic. Your virtual service should therefore not be replicating any back-end logic (see Joel's response for a "better" explanation of this  ).

     

    Look at the panel of requests at the bottom-left of the Service Image window. You can see that it has two examples there. The first is called "META", which would be your usual response (either make it always work, or always fail, depending on the reason for your testing). The second is the name of your operation with the specific values for "a" and for "b" that you recorded. There is also a "+" button at the bottom of that panel, for you to add extra instances of the operation.

     

    For any extra responses that you add, you can do some great things, so go ahead and add an operation there. Highlight it, and then look at the information to the right. You want to expand the "Request" section, and change your "a" and "b" values. Make them both "99" for now. This response will be selected when you set both "a" and "b" to "99".

    Now expand the "Response" panel, and you can manipulate the response that you expect for the instance when you try to add 99 to 99. This could be anything you want to test. It might be that your "calculation" gives an invalid value (9999999999, "fish", true, etc), it could be that it gives a boundary condition (0, -1, 32767, 32768, 4294967295, 4294967296, etc), it could be that it uses invalid separators for your locale (1.234,00, etc).

    But remember that this is a service that will execute in a distributed platform, so there are other things that need to be tested. Look at the "metadata" tab for this response. It has a response code of "200". You should be testing that your client can cope with other response codes in an elegant manner, so get it to respond with a "404" (and change the response code text to "not found").

    Finally, how do you test what happens in your client application if you send the response at an unexpected time? You look at the bottom of the response panel, and change "think time" to an interesting value; perhaps 0, or 1 millisecond over your HTTP timeout value, or a few hours.

     

    So, for this one example of adding 99 to 99, I have given examples above of about 14 different incorrect responses, each of the incorrect responses designed to test a different thing in your client application. Your "correct calculation response" is only one response to add to that, and it's the least important one, because you could have an instance of your operation (add an instance of 99+98) that responds with 197.

     

    So, you add all 15 of these different response instances for your operation, each one having a different reason and testing a different thing, and you let your tester know about all the different negative tests they can use. Suddenly, their testing can encompass all the client error parsing logic, the code coverage of their tests is (more) complete, both risk-based testing and test-driven development are enhanced, and none of this enhanced functionality has needed a single line of scripting or coding.