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
4f610df9
Commit
4f610df9
authored
Jun 18, 2019
by
Arpita Shrivastava
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ppatil_nisumpoc' into 'master'
Ppatil nisumpoc See merge request
!1
parents
5a803a3d
d625d064
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
185 additions
and
3 deletions
+185
-3
Employee_post_steps.java
src/test/java/com/qa/stepdefinition/Employee_post_steps.java
+53
-0
RestUtil.java
src/test/java/com/qa/utilities/RestUtil.java
+70
-0
Util.java
src/test/java/com/qa/utilities/Util.java
+34
-0
application.properties
src/test/resources/config/application.properties
+7
-0
Sample.feature
src/test/resources/features/Sample.feature
+11
-3
employee_post_req_payload.json
...es/requestPayload_employee/employee_post_req_payload.json
+5
-0
wrong_employee_post_req_payload.json
...uestPayload_employee/wrong_employee_post_req_payload.json
+5
-0
No files found.
src/test/java/com/qa/stepdefinition/Employee_post_steps.java
0 → 100644
View file @
4f610df9
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"
));
}
}
src/test/java/com/qa/utilities/RestUtil.java
0 → 100644
View file @
4f610df9
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
);
}
}
src/test/java/com/qa/utilities/Util.java
0 → 100644
View file @
4f610df9
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
;
}
}
src/test/resources/config/application.properties
View file @
4f610df9
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
src/test/resources/features/Sample.feature
View file @
4f610df9
...
@@ -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
src/test/resources/requestPayload_employee/employee_post_req_payload.json
0 → 100644
View file @
4f610df9
{
"name"
:
"testfrtysio"
,
"salary"
:
"23000"
,
"age"
:
"29"
}
\ No newline at end of file
src/test/resources/requestPayload_employee/wrong_employee_post_req_payload.json
0 → 100644
View file @
4f610df9
{
"name"
:
"testne1"
,
"salary"
:
23
,
"age"
:
"23"
}
\ No newline at end of file
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