diff options
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/mavlushechka/a1qa/TestCase1.java | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/test/java/com/mavlushechka/a1qa/TestCase1.java b/src/test/java/com/mavlushechka/a1qa/TestCase1.java index 65c0c17..d641dc2 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.RequestMethod; import com.mavlushechka.a1qa.constants.Status; import com.mavlushechka.a1qa.models.Post; import com.mavlushechka.a1qa.models.User; @@ -15,8 +16,7 @@ public class TestCase1 extends BaseTest { @Test public void test1() throws IOException { - String postsRequestMethod = JSONParser.parseData("testData", "testCases[0].steps[0].requestMethod"); - int postsResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(postsRequestMethod); + int postsResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(RequestMethod.GET); 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); @@ -25,8 +25,7 @@ public class TestCase1 extends BaseTest { Assert.assertTrue(Posts.isPostsAscending(postsList), "Posts are not sorted ascending."); 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); + int post99ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(post99Id, RequestMethod.GET); 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); @@ -36,8 +35,7 @@ public class TestCase1 extends BaseTest { Assert.assertEquals(post99.body.isEmpty(), Boolean.parseBoolean(JSONParser.parseData("testData", "testCases[0].steps[1].post.isBodyEmpty")), "Post body is not correct."); 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); + int post150ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(post150Id, RequestMethod.GET); 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; @@ -48,7 +46,6 @@ public class TestCase1 extends BaseTest { } Assert.assertEquals(JSONParser.isBodyEmpty(post150Json), Boolean.parseBoolean(JSONParser.parseData("testData", "testCases[0].steps[2].isResponseBodyEmpty")), "Response body is not correct."); - String postRequestMethod = JSONParser.parseData("testData", "testCases[0].steps[3].requestMethod"); int randomTextLettersLowerBound = Integer.parseInt(JSONParser.parseData("config", "randomTextGenerator.lettersLowerBound")); int randomTextLettersUpperBound = Integer.parseInt(JSONParser.parseData("config", "randomTextGenerator.lettersUpperBound")); int randomTextLength = Integer.parseInt(JSONParser.parseData("config", "randomTextGenerator.length")); @@ -58,13 +55,12 @@ public class TestCase1 extends BaseTest { StringUtils.generateRandomText(randomTextLettersLowerBound, randomTextLettersUpperBound, randomTextLength), JSONParser.parseData("testData", "testCases[0].steps[3].post.userId") ); - int postResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(postRequestMethod); + int postResponseCode = JSONPlaceholderAPIManager.getPostsResponseCode(RequestMethod.POST); 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); + int usersResponseCode = JSONPlaceholderAPIManager.getUsersResponseCode(RequestMethod.GET); 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(); @@ -78,8 +74,7 @@ public class TestCase1 extends BaseTest { Assert.assertEquals(JSONParser.convertToObject(JSONParser.parseObject("testData", "testCases[0].steps[4].user"), User.class), user, "User information is not correct."); 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); + int user5ResponseCode = JSONPlaceholderAPIManager.getPostResponseCode(user5Id, RequestMethod.GET); 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"))); |