summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java26
-rw-r--r--src/main/resources/testData.json11
2 files changed, 17 insertions, 20 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java b/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java
index 2a66576..aecf885 100644
--- a/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java
+++ b/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java
@@ -15,31 +15,35 @@ public class JSONPlaceholderAPIManager {
public static Post getPost(int id) throws IOException {
- return getObject(postsSpec + "/" + id, Post.class);
+ return JSONParser.convertToObject(URLConnectionManager.get(postsSpec + "/" + id), Post.class);
+ }
+
+ public static int getPostResponseCode(int id, String requestMethod) throws IOException {
+ return URLConnectionManager.getResponseCode(postsSpec + "/" + id, requestMethod);
}
public static List<Post> getPosts() throws IOException {
return getObjects(postsSpec, Post.class);
}
+ public static int getPostsResponseCode(String requestMethod) throws IOException {
+ return URLConnectionManager.getResponseCode(postsSpec, requestMethod);
+ }
+
public static Post postPost(Post post) throws IOException {
- return postObject(postsSpec, post, Post.class);
+ return JSONParser.convertToObject(URLConnectionManager.post(postsSpec, JSONParser.convertToJSON(post)), Post.class);
}
public static User getUser(int id) throws IOException {
- return getObject(usersSpec + "/" + id, User.class);
+ return JSONParser.convertToObject(URLConnectionManager.get(usersSpec + "/" + id), User.class);
}
public static List<User> getUsers() throws IOException {
return getObjects(usersSpec, User.class);
}
- public static User postUser(User user) throws IOException {
- return postObject(usersSpec, user, User.class);
- }
-
- private static <T> T getObject(String spec, Class<T> classOfObject) throws IOException {
- return JSONParser.convertToObject(URLConnectionManager.get(spec), classOfObject);
+ public static int getUsersResponseCode(String requestMethod) throws IOException {
+ return URLConnectionManager.getResponseCode(usersSpec, requestMethod);
}
private static <T> List<T> getObjects(String spec, Class<T> classOfObject) throws IOException {
@@ -52,8 +56,4 @@ public class JSONPlaceholderAPIManager {
return objectsArrayList.stream().toList();
}
- private static <T> T postObject(String spec, T object, Class<T> classOfObject) throws IOException {
- return JSONParser.convertToObject(URLConnectionManager.post(spec, JSONParser.convertToJSON(object)), classOfObject);
- }
-
}
diff --git a/src/main/resources/testData.json b/src/main/resources/testData.json
index 24ac764..f3fc4ca 100644
--- a/src/main/resources/testData.json
+++ b/src/main/resources/testData.json
@@ -3,12 +3,10 @@
{
"steps": [
{
- "spec": "/posts",
"requestMethod": "GET",
"responseCode": "200"
},
{
- "spec": "/posts/99",
"requestMethod": "GET",
"responseCode": "200",
"post": {
@@ -19,13 +17,14 @@
}
},
{
- "spec": "/posts/150",
"requestMethod": "GET",
"responseCode": "404",
- "isResponseBodyEmpty": "true"
+ "isResponseBodyEmpty": "true",
+ "post": {
+ "id": "150"
+ }
},
{
- "spec": "/posts",
"requestMethod": "POST",
"responseCode": "201",
"post": {
@@ -33,7 +32,6 @@
}
},
{
- "spec": "/users",
"requestMethod": "GET",
"responseCode": "200",
"user": {
@@ -61,7 +59,6 @@
}
},
{
- "spec": "/users/5",
"requestMethod": "GET",
"responseCode": "200",
"user": {