Skip to content

Commit dad419d

Browse files
committed
Updated Schema Validation Tests and testng.runner
1 parent 9c3dd6a commit dad419d

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
allure-results/
22
test-output/
33
/settings
4+
/reports
45
application.log
56
##############################
67
## Java
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
package com.qa.api.testcases;
22

3+
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
4+
35
import org.testng.annotations.BeforeMethod;
6+
import org.testng.annotations.Test;
47

8+
import com.qa.api.Utilities.StringUtils;
59
import com.qa.api.base.BaseTest;
610
import com.qa.api.client.restClient;
11+
import com.qa.api.pojo.UserPOJO;
12+
13+
public class APISchemaValidationTest extends BaseTest {
714

8-
public class APISchemaValidationTest extends BaseTest {
9-
1015
@BeforeMethod
1116
public void getUserSetup() {
1217
rc = new restClient(prop, baseURI);
1318
}
1419

20+
@Test
21+
public void createUserTestSchemaValidation() {
22+
UserPOJO user = new UserPOJO("Tom", StringUtils.getRandomEmailGenerator(), "male", "active");
23+
24+
rc.postMethod(GOREST_ENDPOINT, user, "JSON", false, true).then().log().all().assertThat()
25+
.body(matchesJsonSchemaInClasspath("gorestcreateuserschema.json"));
26+
}
27+
1528
}

Diff for: src/test/java/com/qa/api/testcases/GetFlightBookingTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class GetFlightBookingTest extends BaseTest {
2222
@BeforeMethod
2323
public void getFlightAPISetup(String baseURI, String grantType, String client_id, String client_secret) {
2424
rc = new restClient(prop, baseURI);
25-
accessToken = rc.getAccessTokenViaOAuth2(AMADEUS_TOKEN_ENDPOINT, grantType, client_id, client_secret);
25+
accessToken = rc.getAccessTokenViaOAuth2(AMADEUS_TOKEN_ENDPOINT, grantType, client_id, client_secret);
2626
}
2727

2828
@Test

Diff for: src/test/resources/gorestcreateuserschema.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Generated schema for Root",
4+
"type": "object",
5+
"properties": {
6+
"id": {
7+
"type": "number"
8+
},
9+
"name": {
10+
"type": "string"
11+
},
12+
"email": {
13+
"type": "string"
14+
},
15+
"gender": {
16+
"type": "string"
17+
},
18+
"status": {
19+
"type": "string"
20+
}
21+
},
22+
"required": [
23+
"id",
24+
"name",
25+
"email",
26+
"gender",
27+
"status"
28+
]
29+
}

Diff for: src/test/resources/testRunners/testng_runner.xml

+6
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@
4242
<class name="com.qa.api.testcases.GetFlightBookingTest" />
4343
</classes>
4444
</test>
45+
<test name="GoRest Schema Validation Test">
46+
<parameter name="baseURI" value="https://gorest.co.in" />
47+
<classes>
48+
<class name="com.qa.api.testcases.APISchemaValidationTest" />
49+
</classes>
50+
</test>
4551
</suite>

0 commit comments

Comments
 (0)