Commit 26e23354 authored by Arpita Shrivastava's avatar Arpita Shrivastava

Merge branch 'feature/poc_updates' into 'master'

Add wiremock test

See merge request !3
parents c3548564 02f8f5ef
package com.qa.utilities; package com.qa.utilities;
import com.github.tomakehurst.wiremock.WireMockServer; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import org.testng.annotations.Test;
import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.qa.utilities.Util;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.testng.annotations.Test;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
public class WireMockTest { public class WireMockTest {
String MOCKED_URL = "http://localhost:8089/api/f1/drivers.json";
String driverId;
Util util = new Util();
@Test @Test
public void wireMockTest() { public void wireMockTest() {
WireMockServer wireMockServer = new WireMockServer(options().port(8089)); WireMockServer wireMockServer = new WireMockServer(options().port(8089));
wireMockServer.start(); wireMockServer.start();
// checking mock server started
Response response = RestAssured.get(MOCKED_URL);
// status code should be 404 as mock server not started
int mockStatusCode = response.getStatusCode();
System.out.println("Mock status code is : " + mockStatusCode);
// call method to mock response
sync();
} }
public Response sync() {
// to get response from real url
// Response responseFromRealUrl =
// RestAssured.get("BASE_URL/api/f1/drivers.json");
Response responseFromRealUrl = util.get_driver(driverId);
int statuscodeFromRealUrl = responseFromRealUrl.getStatusCode();
// System.out.println(statuscodeFromRealUrl);
String dataFromRealUrl = responseFromRealUrl.getBody().asString();
configureFor("localhost", 8089);
stubFor(get(urlEqualTo("/api/f1/drivers.json"))
.willReturn(aResponse().withStatus(statuscodeFromRealUrl).withBody(dataFromRealUrl)));
WireMock.saveAllMappings();
return RestAssured.get(MOCKED_URL);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment