Service Virtualization

Expand all | Collapse all

Not able to run Junit test case in SV as a Code

Jump to Best Answer
  • 1.  Not able to run Junit test case in SV as a Code

    Posted 09-08-2017 02:07 AM

    1. I am not able to run the junit test case in the project which I have taken from GitHub.

    2. Created junit test case and added all the required libraries there is no error in the script but while running getting below error

     

    log4j:WARN No appenders could be found for logger (com.ca.svcode.engine.junit4.VirtualServerRule).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

     

     Can anyone help on this?



  • 2.  Re: Not able to run Junit test case in SV as a Code

    Posted 09-08-2017 09:54 AM

    Can you please share the list of libraries that you have referenced in the project.

     

    Thanks,

    Surya.



  • 3.  Re: Not able to run Junit test case in SV as a Code

    Posted 09-18-2017 11:22 AM

    Venkat,

    Can you share the list of libraries that you have referenced in the project?



  • 4.  Re: Not able to run Junit test case in SV as a Code

    Posted 09-18-2017 11:27 AM

    Hello Reid,

                I have assisted Venkat offline on this issue and this is resolved. 

    Thanks,

    Surya.



  • 5.  Re: Not able to run Junit test case in SV as a Code

    Posted 09-19-2017 06:19 AM

    Hi Reid/Surya,

     

    We have resolved the issues with the help of Surya. Now we are trying to implement,

    Import and export Request/Response (RR) pairs to reuse.

     

    Best Regards,

    Venkat Yedida



  • 6.  Re: Not able to run Junit test case in SV as a Code
    Best Answer

    Posted 09-19-2017 10:07 AM

    Hello Venkat,

     

               For RR pair usage, please find the information below. Hope this helps. 

     

    1. For Request matching using the request file, please use the below

     

    forGet(URL)
    .matchesBodyFromFile(filePath) --> This will look up request file contents for request body to match
    .doReturn(

     

    More information on matching below

    Matching · CA-DevTest/SV-as-Code Wiki · GitHub 

     

    2. For Response from response file, please use the below

     

    forGet(URL)
    .doReturn(
    okMessage()
    .withBodyFile(filePath) --> This will look up response file and send back the response

     

    3. To export the request and response as RR pair, you need to do the below.

    You need to set set system property svcode.export, the value being the target path that will have the exported files. You can do this, by adding that property in the VM Arguments in Run Configuration. 

    Please find more information below. 

    Exporting Created Services · CA-DevTest/SV-as-Code Wiki · GitHub 

     

    Thanks,

    Surya.



  • 7.  Re: Not able to run Junit test case in SV as a Code

    Posted 09-26-2017 10:59 AM

    Thanks Surya,

     

    I have followed the procedure as you mentioned and it is working as expected. If I have multiple request and response pairs how can I make it work in a single junit test case.

     

    Regards,

    Venkat Yedida



  • 8.  Re: Not able to run Junit test case in SV as a Code

    Posted 09-29-2017 09:34 AM

    Hello Venkat,

              I have sent you a note on this. I am also posting the information here below.

    You can implement multiple virtual services in a single junit test case (using different rr pair) based on either the match clause or an if clause. Example is shown below.

     

    In below case, we have two Post virtual services, each with different match criteria (in this case, match request based on the request file). It can also be match based on a certain request parameter (using either matchesBodyPayload or matchesQuery or matchesHeader or a combination)

    .

    @Test

    public void exampleTest() {

     

    forPost(Application.URL)

                  .matchesHeader("X-Custom-Header","TEST")

                  .matchesBodyFromFile("Request.txt")

                  .doReturn(

                            okMessage().withBodyFile("Response.txt")

                                            

                  );

              

               forPost(Application.URL)

                  .matchesHeader("X-Custom-Header","TEST")

                  .matchesBodyFromFile("Request1.txt")

                  .doReturn(

                            okMessage().withBodyFile("Response1.txt")

                                            

                  );

    }



  • 9.  Re: Not able to run Junit test case in SV as a Code

    Posted 10-17-2017 10:59 AM

    Thanks for the note.

     

    i am able to use this code in my class but i am  able to capture only one response either from first post method or second, is there any possible way to capture both the responses in a single class if both  are satisfied in matching criteria. please advise. 

     

    Best Regards,

    Venkat Yedida  



  • 10.  Re: Not able to run Junit test case in SV as a Code

    Posted 10-17-2017 11:54 AM

    Hello Venkat,

     

               In the above example, the matching criteria is different for both and based on the match, once of the responses will be sent. The scenario that you have mentioned, do you want two responses to be sent for a single request? Please let us know.

     

    Thanks,

    Surya.