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
9757d267
Commit
9757d267
authored
Jun 20, 2019
by
Gowtham Mullapudi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contract test updates
parent
703bcfe4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
43 deletions
+97
-43
pom.xml
pom.xml
+38
-10
Drivers_get_steps.java
src/test/java/com/qa/stepdefinition/Drivers_get_steps.java
+34
-29
Util.java
src/test/java/com/qa/utilities/Util.java
+0
-2
driverData.json
src/test/resources/driverData.json
+23
-0
Drivers.feature
src/test/resources/features/Drivers.feature
+2
-2
No files found.
pom.xml
View file @
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
src/test/java/com/qa/stepdefinition/Drivers_get_steps.java
View file @
9757d267
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
);
}
}
src/test/java/com/qa/utilities/Util.java
View file @
9757d267
...
...
@@ -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
{
...
...
src/test/resources/driverData.json
0 → 100644
View file @
9757d267
{
"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
src/test/resources/features/Drivers.feature
View file @
9757d267
...
...
@@ -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
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