Service Virtualization

 View Only
  • 1.  SV as Code: Just the testing of a VS or creation as well?

    Posted Jul 25, 2017 04:33 AM

    I am trying to use SV as code feature, however I looking at the code snippets provided, I have a question listed below:

     

    Is it just for VS unit testing, since it was using JUnit (provided in the code snippets)? If we could create VS through this, then where is the deployment going to be done(as we use to do in case of work station to a VSE) and how about the endpoint for VS.



  • 2.  Re: SV as Code: Just the testing of a VS or creation as well?

    Posted Jul 25, 2017 10:33 AM

    There is no deployment to a VSE as you would experience from DevTest.  The SVasCode VSE runs in memory.  This is for concise unit testing within the code



  • 3.  Re: SV as Code: Just the testing of a VS or creation as well?

    Posted Jul 26, 2017 01:19 AM

    Thank you markellebie62133831 for clear my doubt, however, there is one thing which I would like to know. In the code below, we are doing unit testing for the VS, if I am not wrong, then how are we going to create the VS(generating the endpoint) using SVasCode (what is this URL about)?

     

    Code:

    private static final String URL = "http://www.ca.com/portfolio";

     

    private static String RESPONSE_BODY_GET = "Response body from virtualized service.";
    private static int CUSTOM_STATUS_CODE = 258;

     

    @Rule
    public VirtualServerRule vs = new VirtualServerRule();

     

    @Test
    public void testSimpleHttpGetWithResponseCodeAndStringBody() throws IOException {
      forGet(URL).doReturn(
          aMessage(CUSTOM_STATUS_CODE)
              .withStringBody(RESPONSE_BODY)
      );

     

      HttpGet httpGet = new HttpGet(URL);
      HttpClient httpClient = HttpClientBuilder.create().build();
      HttpResponse httpResponse = httpClient.execute(httpGet);

     

      assertEquals(CUSTOM_STATUS_CODE, httpResponse.getStatusLine().getStatusCode());

     

      BufferedReader in = new BufferedReader(
          new InputStreamReader(httpResponse.getEntity().getContent()));
      String inputLine;
      StringBuffer response = new StringBuffer();

     

      while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
      }
      in.close();

     

      assertEquals(response.toString(), RESPONSE_BODY);
    }



  • 4.  Re: SV as Code: Just the testing of a VS or creation as well?
    Best Answer

    Posted Jul 26, 2017 09:30 AM

    forGet(URL).doReturn(       aMessage(CUSTOM_STATUS_CODE)           .withStringBody(RESPONSE_BODY)   );

     

    this is the actual stand-in virtualization call to the url ... w/response.  This is all in memory, no actual VS like DevTest.  You set headers, response content ...etc as you see fit for your testing.