diff options
-rw-r--r-- | src/main/java/com/mavlushechka/a1qa/constants/Status.java | 13 | ||||
-rw-r--r-- | src/main/resources/testData.json | 8 | ||||
-rw-r--r-- | src/test/java/com/mavlushechka/a1qa/TestCase1.java | 13 |
3 files changed, 21 insertions, 13 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/constants/Status.java b/src/main/java/com/mavlushechka/a1qa/constants/Status.java new file mode 100644 index 0000000..a319f39 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/constants/Status.java @@ -0,0 +1,13 @@ +package com.mavlushechka.a1qa.constants; + +public enum Status { + + OK(200), CREATED(201), NOT_FOUND(404); + + public final int code; + + Status(int code) { + this.code = code; + } + +} diff --git a/src/main/resources/testData.json b/src/main/resources/testData.json index f3fc4ca..6403d5b 100644 --- a/src/main/resources/testData.json +++ b/src/main/resources/testData.json @@ -3,12 +3,10 @@ { "steps": [ { - "requestMethod": "GET", - "responseCode": "200" + "requestMethod": "GET" }, { "requestMethod": "GET", - "responseCode": "200", "post": { "id": "99", "userId": "10", @@ -18,7 +16,6 @@ }, { "requestMethod": "GET", - "responseCode": "404", "isResponseBodyEmpty": "true", "post": { "id": "150" @@ -26,14 +23,12 @@ }, { "requestMethod": "POST", - "responseCode": "201", "post": { "userId": "1" } }, { "requestMethod": "GET", - "responseCode": "200", "user": { "id": "5", "name": "Chelsey Dietrich", @@ -60,7 +55,6 @@ }, { "requestMethod": "GET", - "responseCode": "200", "user": { "id": "5" } diff --git a/src/test/java/com/mavlushechka/a1qa/TestCase1.java b/src/test/java/com/mavlushechka/a1qa/TestCase1.java index 1bb4590..65c0c17 100644 --- a/src/test/java/com/mavlushechka/a1qa/TestCase1.java +++ b/src/test/java/com/mavlushechka/a1qa/TestCase1.java @@ -1,6 +1,7 @@ package com.mavlushechka.a1qa; import com.mavlushechka.a1qa.constants.Endpoint; +import com.mavlushechka.a1qa.constants.Status; import com.mavlushechka.a1qa.models.Post; import com.mavlushechka.a1qa.models.User; import com.mavlushechka.a1qa.utils.*; @@ -16,7 +17,7 @@ public class TestCase1 extends BaseTest { public void test1() throws IOException { String postsRequestMethod = JSONParser.parseData("testData", "testCases[0].steps[0].requestMethod"); int postsResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(postsRequestMethod); - Assert.assertEquals(postsResponseCode, Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[0].responseCode")), "Response code is not correct."); + Assert.assertEquals(postsResponseCode, Status.OK.code, "Response code is not correct."); LoggerUtils.step("Send GET Request to get all posts (/posts)."); String postsJson = URLConnectionManager.get(Endpoint.POSTS.spec); Assert.assertTrue(JSONParser.isJson(postsJson), "Response is not json."); @@ -26,7 +27,7 @@ public class TestCase1 extends BaseTest { int post99Id = Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[1].post.id")); String post99RequestMethod = JSONParser.parseData("testData", "testCases[0].steps[1].requestMethod"); int post99ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(post99Id, post99RequestMethod); - Assert.assertEquals(post99ResponseCode, Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[1].responseCode")), "Response code is not correct."); + Assert.assertEquals(post99ResponseCode, Status.OK.code, "Response code is not correct."); LoggerUtils.step("Send GET request to get post with id=99 (/posts/99)."); Post post99 = JSONPlaceholderAPIManager.getPost(post99Id); Assert.assertEquals(post99.id, JSONParser.parseData("testData", "testCases[0].steps[1].post.id"), "Post id is not correct."); @@ -37,7 +38,7 @@ public class TestCase1 extends BaseTest { int post150Id = Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[2].post.id")); String post150RequestMethod = JSONParser.parseData("testData", "testCases[0].steps[2].requestMethod"); int post150ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(post150Id, post150RequestMethod); - Assert.assertEquals(post150ResponseCode, Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[2].responseCode")), "Response code is not correct."); + Assert.assertEquals(post150ResponseCode, Status.NOT_FOUND.code, "Response code is not correct."); LoggerUtils.step("Send GET request to get post with id=150 (/posts/150)."); String post150Json; try { @@ -58,13 +59,13 @@ public class TestCase1 extends BaseTest { JSONParser.parseData("testData", "testCases[0].steps[3].post.userId") ); int postResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(postRequestMethod); - Assert.assertEquals(postResponseCode, Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[3].responseCode")), "Response code is not correct."); + Assert.assertEquals(postResponseCode, Status.CREATED.code, "Response code is not correct."); LoggerUtils.step("Send POST request to create post with userId=1 and random body and random title (/posts)."); Assert.assertEquals(post, JSONPlaceholderAPIManager.postPost(post), "Post information is not correct."); String usersRequestMethod = JSONParser.parseData("testData", "testCases[0].steps[4].requestMethod"); int usersResponseCode = JSONPlaceholderAPIManager.getUsersResponseCode(usersRequestMethod); - Assert.assertEquals(usersResponseCode, Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[4].responseCode")), "Response code is not correct."); + Assert.assertEquals(usersResponseCode, Status.OK.code, "Response code is not correct."); LoggerUtils.step("Send GET request to get users (/users)."); List<User> users = JSONPlaceholderAPIManager.getUsers(); User user = null; @@ -79,7 +80,7 @@ public class TestCase1 extends BaseTest { int user5Id = Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[5].user.id")); String user5RequestMethod = JSONParser.parseData("testData", "testCases[0].steps[5].requestMethod"); int user5ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(user5Id, user5RequestMethod); - Assert.assertEquals(user5ResponseCode, Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[5].responseCode")), "Response code is not correct."); + Assert.assertEquals(user5ResponseCode, Status.OK.code, "Response code is not correct."); LoggerUtils.step("Send GET request to get user with id=5 (/users/5)."); User user5 = JSONPlaceholderAPIManager.getUser(Integer.parseInt(JSONParser.parseData("testData", "testCases[0].steps[5].user.id"))); Assert.assertEquals(user, user5, "User information is not correct."); |