summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/a1qa/utils
diff options
context:
space:
mode:
authorMavlushechka <mavlushechka@gmail.com>2022-10-04 21:17:05 +0500
committerMavlushechka <mavlushechka@gmail.com>2022-10-04 21:17:05 +0500
commit4495c73482a9fb3bdb87a75816974602e833278e (patch)
treead73827470707ecb985b912755f8ab869d6e8abc /src/main/java/com/mavlushechka/a1qa/utils
parent50832a0a76f3b4d9c7022df699e212f9b1785262 (diff)
Create RequestMethod enum
Diffstat (limited to 'src/main/java/com/mavlushechka/a1qa/utils')
-rw-r--r--src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java7
-rw-r--r--src/main/java/com/mavlushechka/a1qa/utils/URLConnectionManager.java7
2 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java b/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java
index 464c1af..54df569 100644
--- a/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java
+++ b/src/main/java/com/mavlushechka/a1qa/utils/JSONPlaceholderAPIManager.java
@@ -1,6 +1,7 @@
package com.mavlushechka.a1qa.utils;
import com.mavlushechka.a1qa.constants.Endpoint;
+import com.mavlushechka.a1qa.constants.RequestMethod;
import com.mavlushechka.a1qa.models.Post;
import com.mavlushechka.a1qa.models.User;
@@ -18,7 +19,7 @@ public class JSONPlaceholderAPIManager {
return JSONParser.convertToObject(URLConnectionManager.get(postsSpec + "/" + id), Post.class);
}
- public static int getPostResponseCode(int id, String requestMethod) throws IOException {
+ public static int getPostResponseCode(int id, RequestMethod requestMethod) throws IOException {
return URLConnectionManager.getResponseCode(postsSpec + "/" + id, requestMethod);
}
@@ -26,7 +27,7 @@ public class JSONPlaceholderAPIManager {
return getObjects(postsSpec, Post.class);
}
- public static int getPostsResponseCode(String requestMethod) throws IOException {
+ public static int getPostsResponseCode(RequestMethod requestMethod) throws IOException {
return URLConnectionManager.getResponseCode(postsSpec, requestMethod);
}
@@ -42,7 +43,7 @@ public class JSONPlaceholderAPIManager {
return getObjects(usersSpec, User.class);
}
- public static int getUsersResponseCode(String requestMethod) throws IOException {
+ public static int getUsersResponseCode(RequestMethod requestMethod) throws IOException {
return URLConnectionManager.getResponseCode(usersSpec, requestMethod);
}
diff --git a/src/main/java/com/mavlushechka/a1qa/utils/URLConnectionManager.java b/src/main/java/com/mavlushechka/a1qa/utils/URLConnectionManager.java
index 286df12..c6c9fae 100644
--- a/src/main/java/com/mavlushechka/a1qa/utils/URLConnectionManager.java
+++ b/src/main/java/com/mavlushechka/a1qa/utils/URLConnectionManager.java
@@ -1,5 +1,6 @@
package com.mavlushechka.a1qa.utils;
+import com.mavlushechka.a1qa.constants.RequestMethod;
import com.mavlushechka.a1qa.driverUtils.HttpURLConnectionFactory;
import java.io.BufferedReader;
@@ -13,7 +14,7 @@ public class URLConnectionManager {
public static String get(String spec) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
- try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(HttpURLConnectionFactory.createHttpURLConnection(spec, "GET", false).getInputStream()))) {
+ try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(HttpURLConnectionFactory.createHttpURLConnection(spec, RequestMethod.GET, false).getInputStream()))) {
String inputLine;
while ((inputLine = bufferedReader.readLine()) != null) {
@@ -24,7 +25,7 @@ public class URLConnectionManager {
}
public static String post(String spec, String content) throws IOException {
- HttpURLConnection httpURLConnection = HttpURLConnectionFactory.createHttpURLConnection(spec, "POST", true);
+ HttpURLConnection httpURLConnection = HttpURLConnectionFactory.createHttpURLConnection(spec, RequestMethod.POST, true);
StringBuilder stringBuilder = new StringBuilder();
try (DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream())) {
@@ -41,7 +42,7 @@ public class URLConnectionManager {
return stringBuilder.toString();
}
- public static int getResponseCode(String spec, String requestMethod) throws IOException {
+ public static int getResponseCode(String spec, RequestMethod requestMethod) throws IOException {
return HttpURLConnectionFactory.createHttpURLConnection(spec, requestMethod, false).getResponseCode();
}