Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NisumPoc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arpita Shrivastava
NisumPoc
Commits
9bc77244
Commit
9bc77244
authored
Jun 25, 2019
by
Arpita Shrivastava
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updating post call
parent
b554c037
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
162 additions
and
69 deletions
+162
-69
Employee_post_steps.java
src/test/java/com/qa/stepdefinition/Employee_post_steps.java
+3
-1
Employee.java
src/test/java/com/qa/utilities/Employee.java
+29
-0
RestUtil.java
src/test/java/com/qa/utilities/RestUtil.java
+122
-61
Util.java
src/test/java/com/qa/utilities/Util.java
+7
-6
application.properties
src/test/resources/config/application.properties
+1
-1
No files found.
src/test/java/com/qa/stepdefinition/Employee_post_steps.java
View file @
9bc77244
...
...
@@ -21,7 +21,9 @@ public class Employee_post_steps {
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+)$"
)
...
...
@@ -46,7 +48,7 @@ public class Employee_post_steps {
@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"
));
//
json.body(containsString("Integrity constraint violation"));
}
...
...
src/test/java/com/qa/utilities/Employee.java
0 → 100644
View file @
9bc77244
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
;
}
}
src/test/java/com/qa/utilities/RestUtil.java
View file @
9bc77244
package
com
.
qa
.
utilities
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.stream.Stream
;
import
org.codehaus.jackson.JsonParseException
;
import
org.codehaus.jackson.map.JsonMappingException
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
io.restassured.RestAssured
;
import
io.restassured.http.ContentType
;
...
...
@@ -10,67 +19,119 @@ 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
);
}
public
static
Response
setGETEndPoint
(
String
baseuri
,
String
resourceuri
,
String
driverId
)
{
return
request
.
when
().
baseUri
(
baseuri
).
get
(
resourceuri
+
"/"
+
driverId
+
".json"
);
// 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
void
setreqPayloadAddRandomName
(
File
file
)
{
String
JSONObjectStr
=
readLineByLineJava8
(
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
();
}
public
static
void
setpathParams
(
String
driverId
)
{
request
.
pathParams
(
"driverId"
,
driverId
+
".json"
);
emp
.
setName
(
"Name "
+
Math
.
random
());
try
{
String
jsonInString
=
mapper
.
writeValueAsString
(
emp
);
request
.
given
().
body
(
jsonInString
);
System
.
out
.
println
(
jsonInString
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
static
String
readLineByLineJava8
(
String
filePath
)
{
StringBuilder
contentBuilder
=
new
StringBuilder
();
try
(
Stream
<
String
>
stream
=
Files
.
lines
(
Paths
.
get
(
filePath
),
StandardCharsets
.
UTF_8
))
{
stream
.
forEach
(
s
->
contentBuilder
.
append
(
s
).
append
(
"\n"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
contentBuilder
.
toString
();
}
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
);
}
public
static
Response
setGETEndPoint
(
String
baseuri
,
String
resourceuri
,
String
driverId
)
{
return
request
.
when
().
baseUri
(
baseuri
).
get
(
resourceuri
+
"/"
+
driverId
+
".json"
);
}
public
static
void
setpathParams
(
String
driverId
)
{
request
.
pathParams
(
"driverId"
,
driverId
+
".json"
);
}
}
src/test/java/com/qa/utilities/Util.java
View file @
9bc77244
...
...
@@ -23,10 +23,11 @@ public class Util {
return
new
File
(
loc
);
}
public
Response
post_employee
(
File
file
)
{
RestUtil
.
setreqPayload
(
file
);
RestUtil
.
setreqPayload
AddRandomName
(
file
);
RestUtil
.
setContentType
(
getValue
(
"content_JSON_type"
));
Response
response
=
RestUtil
.
setPostwebserviceUrl
(
getValue
(
"employee_base_uri"
),
getValue
(
"employee_service_resurce_POST"
));
return
response
;
}
public
Response
get_driver
(
String
driverId
)
{
...
...
@@ -36,15 +37,15 @@ public class Util {
}
public
Response
post_XMLData_employee
(
File
file
)
{
RestUtil
.
setreqPayload
(
file
);
RestUtil
.
setContentType
(
getValue
(
"content_XML_type"
));
Response
response
=
RestUtil
.
setPostwebserviceUrl
(
getValue
(
"employee_base_uri"
),
getValue
(
"employee_service_resurce_POST"
));
return
response
;
}
}
src/test/resources/config/application.properties
View file @
9bc77244
...
...
@@ -7,5 +7,5 @@ employee_service_resurce_GET = /api/v1/employees
employee_service_resurce_POST
=
/api/v1/create
driver_base_uri
=
http://ergast.com/
driver_resources_uri
=
api/f1/drivers
employee_XML_correct_req_payload_loc
=
/
com-nisum-
poc/src/test/resources/sample.xml
employee_XML_correct_req_payload_loc
=
/
Users/ashrivastava/Documents/nisum
poc/src/test/resources/sample.xml
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment