Commit c3548564 authored by Arpita Shrivastava's avatar Arpita Shrivastava

Merge branch 'feature/poc_updates' into 'master'

contract test updates

See merge request !2
parents 703bcfe4 9757d267
......@@ -85,5 +85,33 @@
<artifactId>joda-time</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-core</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.qa.stepdefinition;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.testng.Assert;
import com.qa.utilities.Util;
import cucumber.api.DataTable;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.module.jsv.JsonSchemaValidator;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import wiremock.com.fasterxml.jackson.databind.ObjectMapper;
public class Drivers_get_steps {
private RequestSpecification request;
// private RequestSpecification request;
private Response response;
private ValidatableResponse json;
private String ENDPOINT_GET_DRIVER = "http://ergast.com/api/f1/drivers";
// private String ENDPOINT_GET_DRIVER = "http://ergast.com/api/f1/drivers";
final static Logger logger = Logger.getLogger(Drivers_get_steps.class);
Util util =new Util();
Util util = new Util();
String driverId;
@Given("^a driver exists with driver id \"([^\"]*)\"$")
......@@ -44,8 +32,9 @@ public class Drivers_get_steps {
response = util.get_driver(driverId);
System.out.println("response: " + response.prettyPrint());
// System.out.println("response: " + response.prettyPrint());
}
@Then("^the status code is (\\d+)$")
public void the_status_code_is(int statusCode) throws Throwable {
json = response.then().statusCode(statusCode);
......@@ -53,15 +42,31 @@ public class Drivers_get_steps {
}
@Then("^response includes the following$")
public void response_includes_the_following(Map<String,String> responseFields) throws Throwable {
public void response_includes_the_following(Map<String, String> responseFields) throws Throwable {
for (Map.Entry<String, String> data : responseFields.entrySet()) {
if(StringUtils.isNumeric(data.getValue())){
if (StringUtils.isNumeric(data.getValue())) {
json.body(data.getKey(), containsInAnyOrder(Integer.parseInt(data.getValue())));
}
else{
} else {
json.body(data.getKey(), containsInAnyOrder(data.getValue()));
}
}
}
@And("^verify the fields in response for \"(.*)\"$")
public void verify_the_fields_in_response(String fileName) throws Throwable {
boolean isCheckOk = true;
try {
JsonSchemaValidator validator = JsonSchemaValidator.matchesJsonSchemaInClasspath(fileName);
System.out.println("file name is : " + fileName);
response.then().assertThat().body(validator);
System.out.println("json schema validation OK");
} catch (Exception oEx) {
isCheckOk = false;
System.out.println("json schema validation NOT OK");
System.out.println("fail BasicChecks - validateSchema >> validation schema failed. -- exception: "
+ oEx.getLocalizedMessage());
}
System.out.println("Schema validation : " + isCheckOk);
}
}
......@@ -5,8 +5,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import io.restassured.RestAssured;
import io.restassured.response.Response;
public class Util {
......
{
"MRData": {
"xmlns": "http://ergast.com/mrd/1.4",
"series": "f1",
"url": "http://ergast.com/api/f1/drivers/abecassis.json",
"limit": "30",
"offset": "0",
"total": "1",
"DriverTable": {
"driverId": "abecassis",
"Drivers": [
{
"driverId": "abecassis",
"url": "http://en.wikipedia.org/wiki/George_Abecassis",
"givenName": "George",
"familyName": "Abecassis",
"dateOfBirth": "1913-03-21",
"nationality": "British"
}
]
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ Scenario: Get details of drivers by driver id
Given a driver exists with driver id "abecassis"
When a driver details is retrieved by driver id
Then the status code is 200
And verify the fields in response for "driverData.json"
And response includes the following
|MRData.DriverTable.Drivers.driverId | abecassis |
|MRData.DriverTable.Drivers.url | http://en.wikipedia.org/wiki/George_Abecassis |
......@@ -15,4 +16,3 @@ And response includes the following
\ No newline at end of file
\ No newline at end of file
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