Commit 4f610df9 authored by Arpita Shrivastava's avatar Arpita Shrivastava

Merge branch 'ppatil_nisumpoc' into 'master'

Ppatil nisumpoc

See merge request !1
parents 5a803a3d d625d064
package com.qa.stepdefinition;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.notNullValue;
import java.io.File;
import com.qa.utilities.Util;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
public class Employee_post_steps {
private Response response;
private ValidatableResponse json;
private Util util =new Util();
@When("^employee data is uploaded through webservice$")
public void employee_data_is_uploaded_through_webservice() throws Throwable {
//File reqPayload = util.convertJsonFiletoFile("src/test/resources/requestPayload_employee/employee_post_req_payload.json");
File reqPayload = new File(util.getValue("employee_correct_req_payload_loc"));
response = util.post_employee(reqPayload);
}
@Then("^verify the success status code (\\d+)$")
public void verify_the_success_status_code(int arg1) throws Throwable {
//Assertion for status code and initializing jsonresponse varialble
json = response.then().statusCode(arg1);
}
@Then("^verify employee_id is generated$")
public void verify_employee_id_is_generated() throws Throwable {
//Assertion to check employeeid present and not null value in response json hgfjbkjn
json.body(containsString("id"), notNullValue());
}
@When("^wrong employee data is uploaded through webservice$")
public void wrong_employee_data_is_uploaded_through_webservice() throws Throwable {
File reqPayload = util.convertJsonFiletoFile(util.getValue("employee_wrong_req_payload_loc"));
response = util.post_employee(reqPayload);
}
@Then("^verify error message is generated$")
public void verify_error_message_is_generated() throws Throwable {
//Assertion to check error message in response
json.body(containsString("Integrity constraint violation"));
}
}
package com.qa.utilities;
import java.io.File;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import static io.restassured.RestAssured.given;
public class RestUtil {
//Global Setup Variables
public static String path; //Rest request path
static RequestSpecification request= RestAssured.given();
/*
***Sets Base URI***
Before starting the test, we should set the RestAssured.baseURI
*/
public static void setBaseURI (String baseURI){
RestAssured.baseURI = baseURI;
}
/*
***Sets ContentType***
We should set content type as JSON or XML before starting the test
*/
public static void setContentType (String Type){
request.with().contentType(Type);
}
/*
***search query path of first example***
It is equal to "barack obama/videos.json?num_of_videos=4"
*/
public static String createSearchQueryPath(String searchTerm, String jsonPathTerm, String param, String paramValue) {
path = "?" + param + "=" + paramValue;
return path;
}
/*
***Returns response***
We send "path" as a parameter to the Rest Assured'a "get" method
and "get" method returns response of API
*/
public static Response getResponse() {
//System.out.print("path: " + path +"\n");
return RestAssured.get(path);
}
/*
***Returns JsonPath object***
* First convert the API's response to String type with "asString()" method.
* Then, send this String formatted json response to the JsonPath class and return the JsonPath
*/
public static JsonPath getJsonPath (Response res) {
String json = res.asString();
//System.out.print("returned json: " + json +"\n");
return new JsonPath(json);
}
public static void setreqPayload(File file) {
request.given().body(file);
}
public static Response setPostwebserviceUrl(String baseuri,String resourceuri) {
String url = baseuri.concat(resourceuri);
url= url.replaceAll("\"", "");
System.out.println(url);
return request.when().post(url);
}
public static void setGetResourceUri(String resourceuri) {
RestAssured.when().get(resourceuri);
}
}
package com.qa.utilities;
import java.io.File;
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 {
static Properties prop = new Properties();
public String getValue(String key) {
try {
prop.load(new FileInputStream("src/test/resources/config/application.properties"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return prop.getProperty(key);
}
public File convertJsonFiletoFile(String loc) {
return new File(loc);
}
public Response post_employee(File file) {
RestUtil.setreqPayload(file);
RestUtil.setContentType(getValue("content_JSON_type"));
Response response = RestUtil.setPostwebserviceUrl(getValue("employee_base_uri"), getValue("employee_service_resurce_POST"));
return response;
}
}
employee_base_uri= http://dummy.restapiexample.com
employee_correct_req_payload_loc= src/test/resources/requestPayload_employee/employee_post_req_payload.json
employee_wrong_req_payload_loc= src/test/resources/requestPayload_employee/wrong_employee_post_req_payload.json
content_JSON_type= application/json
content_xml_type= application/xml
employee_service_resurce_GET = /api/v1/employees
employee_service_resurce_POST = /api/v1/create
...@@ -2,6 +2,14 @@ Feature: get the location data by country and zip code ...@@ -2,6 +2,14 @@ Feature: get the location data by country and zip code
@sanity @sanity
Scenario: call api and get the location data of country US and zip code 90210 Scenario: call api and get the location data of country US and zip code 90210
Given The country and zip code is valid
When location data is retrieved by country code and zipcode. When employee data is uploaded through webservice
Then verify the status is successful Then verify the success status code 200
And verify employee_id is generated
@sanity
Scenario: call api and get the location data of country US and zip code 90210
When wrong employee data is uploaded through webservice
Then verify the success status code 200
And verify error message is generated
{
"name":"testfrtysio",
"salary":"23000",
"age":"29"
}
\ No newline at end of file
{
"name":"testne1",
"salary":23,
"age":"23"
}
\ 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