Commit ebde3823 authored by Arpita Shrivastava's avatar Arpita Shrivastava

Updated Post with random generated name

parent 13b3488e
......@@ -19,11 +19,8 @@ public class Employee_post_steps {
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+)$")
......
package com.qa.utilities;
public class Employee {
String name;
String age;
String salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSalary() {
return salary;
}
public void setSalary(String salary) {
this.salary = salary;
}
}
......@@ -7,9 +7,15 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;
import com.google.common.base.Charsets;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
......@@ -73,34 +79,28 @@ public class RestUtil {
request.given().body(file);
}
public static void setreqPayloadAddRandomName(File file) {
public static void setreqPayloadAddRandomName(File file) throws JsonProcessingException, IOException {
//String with random generated name
String randomName = "Test Post call "+ Math.random();
//read the Json Payload from file
String JSONObjectStr = readLineByLineJava8(file.getPath());
//String JSONObjectStr = FileUtils.readFileToString(file.getPath());
ObjectMapper mapper = new ObjectMapper();
Employee emp = null;
try {
emp = mapper.readValue(JSONObjectStr, Employee.class);
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
emp.setName("Name "+ Math.random());
//JsonNode will have deserialized Json
JsonNode actualObj = mapper.readTree(JSONObjectStr);
ObjectNode jsonObjectNode = (ObjectNode) actualObj;
try {
String jsonInString = mapper.writeValueAsString(emp);
request.given().body(jsonInString);
System.out.println(jsonInString);
} catch (IOException e) {
e.printStackTrace();
}
//put the random value in jsonObjectNode
jsonObjectNode.put("name", randomName);
// write jsonObjectNode as strings
String jsonInString = mapper.writeValueAsString(jsonObjectNode);
request.given().body(jsonInString);
}
private static String readLineByLineJava8(String filePath)
{
StringBuilder contentBuilder = new StringBuilder();
......
......@@ -5,6 +5,9 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.codehaus.jackson.JsonProcessingException;
import io.restassured.response.Response;
public class Util {
......@@ -22,7 +25,7 @@ public class Util {
public File convertJsonFiletoFile(String loc) {
return new File(loc);
}
public Response post_employee(File file) {
public Response post_employee(File file) throws JsonProcessingException, IOException {
RestUtil.setreqPayloadAddRandomName(file);
RestUtil.setContentType(getValue("content_JSON_type"));
Response response = RestUtil.setPostwebserviceUrl(getValue("employee_base_uri"), getValue("employee_service_resurce_POST"));
......
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