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);
}