summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/mavlushechka/a1qa/constants/Attachment.java7
-rw-r--r--src/main/java/com/mavlushechka/a1qa/constants/Method.java14
-rw-r--r--src/main/java/com/mavlushechka/a1qa/models/Attachment.java10
-rw-r--r--src/main/java/com/mavlushechka/a1qa/models/Comment.java4
-rw-r--r--src/main/java/com/mavlushechka/a1qa/models/Liker.java22
-rw-r--r--src/main/java/com/mavlushechka/a1qa/models/Post.java4
-rw-r--r--src/main/java/com/mavlushechka/a1qa/models/User.java44
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/CommentForm.java28
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/CommentsForm.java32
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/FeedPage.java19
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/HomePage.java25
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/PostForm.java67
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/ProfilePage.java41
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/ProfileWallForm.java43
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/SideBarForm.java20
-rw-r--r--src/main/java/com/mavlushechka/a1qa/pages/SignInPage.java30
-rw-r--r--src/main/java/com/mavlushechka/a1qa/utils/Database.java88
-rw-r--r--src/main/java/com/mavlushechka/a1qa/utils/VkApiUtils.java62
18 files changed, 89 insertions, 471 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/constants/Attachment.java b/src/main/java/com/mavlushechka/a1qa/constants/Attachment.java
deleted file mode 100644
index a011430..0000000
--- a/src/main/java/com/mavlushechka/a1qa/constants/Attachment.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.mavlushechka.a1qa.constants;
-
-public enum Attachment {
-
- PHOTO
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/constants/Method.java b/src/main/java/com/mavlushechka/a1qa/constants/Method.java
deleted file mode 100644
index 221f98b..0000000
--- a/src/main/java/com/mavlushechka/a1qa/constants/Method.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.mavlushechka.a1qa.constants;
-
-public enum Method {
-
- WALL_GET_LIKES("wall.getLikes"), WALL_POST("wall.post"), WALL_EDIT("wall.edit"), WALL_DELETE("wall.delete"),
- WALL_CREATE_COMMENT("wall.createComment"), USERS_GET("users.get");
-
- public final String name;
-
- Method(String name) {
- this.name = name;
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/models/Attachment.java b/src/main/java/com/mavlushechka/a1qa/models/Attachment.java
deleted file mode 100644
index a05ee71..0000000
--- a/src/main/java/com/mavlushechka/a1qa/models/Attachment.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.mavlushechka.a1qa.models;
-
-public record Attachment(com.mavlushechka.a1qa.constants.Attachment attachment, int ownerId, int mediaId) {
-
- @Override
- public String toString() {
- return attachment.name().toLowerCase() + ownerId + "_" + mediaId;
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/models/Comment.java b/src/main/java/com/mavlushechka/a1qa/models/Comment.java
deleted file mode 100644
index b8de1e0..0000000
--- a/src/main/java/com/mavlushechka/a1qa/models/Comment.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.mavlushechka.a1qa.models;
-
-public record Comment(int id, User user, Post post, String message) {
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/models/Liker.java b/src/main/java/com/mavlushechka/a1qa/models/Liker.java
deleted file mode 100644
index 045852f..0000000
--- a/src/main/java/com/mavlushechka/a1qa/models/Liker.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.mavlushechka.a1qa.models;
-
-public class Liker {
-
- private final int uid;
- private final int copied;
-
-
- public Liker(int uid, int copied) {
- this.uid = uid;
- this.copied = copied;
- }
-
- public int getUid() {
- return uid;
- }
-
- public int getCopied() {
- return copied;
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/models/Post.java b/src/main/java/com/mavlushechka/a1qa/models/Post.java
deleted file mode 100644
index 9cf8474..0000000
--- a/src/main/java/com/mavlushechka/a1qa/models/Post.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.mavlushechka.a1qa.models;
-
-public record Post(int id, User owner, String message, Attachment attachment) {
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/models/User.java b/src/main/java/com/mavlushechka/a1qa/models/User.java
index c9bb3ff..2370371 100644
--- a/src/main/java/com/mavlushechka/a1qa/models/User.java
+++ b/src/main/java/com/mavlushechka/a1qa/models/User.java
@@ -1,46 +1,4 @@
package com.mavlushechka.a1qa.models;
-import com.google.gson.annotations.SerializedName;
-
-public class User {
-
- private final int id;
- @SerializedName("first_name")
- private final String firstName;
- @SerializedName("last_name")
- private final String lastName;
- @SerializedName("can_access_closed")
- private final boolean canAccessClosed;
- @SerializedName("is_closed")
- private final boolean isClosed;
-
-
- public User(int id, String firstName, String lastName, boolean canAccessClosed, boolean isClosed) {
- this.id = id;
- this.firstName = firstName;
- this.lastName = lastName;
- this.canAccessClosed = canAccessClosed;
- this.isClosed = isClosed;
- }
-
- public int getId() {
- return id;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public boolean isCanAccessClosed() {
- return canAccessClosed;
- }
-
- public boolean isClosed() {
- return isClosed;
- }
-
+public record User(String name, String password) {
}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/CommentForm.java b/src/main/java/com/mavlushechka/a1qa/pages/CommentForm.java
deleted file mode 100644
index d087336..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/CommentForm.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import aquality.selenium.elements.interfaces.ILabel;
-import com.mavlushechka.a1qa.models.Comment;
-import org.openqa.selenium.By;
-
-import java.util.Objects;
-
-public class CommentForm extends BaseForm {
-
- private final ILabel commentLabel;
- private final ILabel commentText;
-
-
- public CommentForm(Comment comment) {
- super(AqualityServices.getElementFactory().getLabel(By.id("post" + comment.user().getId() + "_" + comment.id()), "Comment"), "Comment form");
- String commentXpath = "//*[@id='" + "post" + comment.user().getId() + "_" + comment.id() + "']";
- commentLabel = AqualityServices.getElementFactory().getLabel(By.xpath(commentXpath), "Comment");
- commentText = AqualityServices.getElementFactory().getLabel(By.xpath(commentXpath + "//*[contains(@class, 'wall_reply_text')]"), "Comment");
- }
-
- public boolean contains(Comment comment) {
- return Objects.equals(Integer.parseInt(commentLabel.getAttribute("data-answering-id")), comment.user().getId())
- && Objects.equals(commentText.getText(), comment.message());
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/CommentsForm.java b/src/main/java/com/mavlushechka/a1qa/pages/CommentsForm.java
deleted file mode 100644
index 4ae6a01..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/CommentsForm.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import aquality.selenium.elements.interfaces.IButton;
-import com.mavlushechka.a1qa.models.Comment;
-import com.mavlushechka.a1qa.models.Post;
-import org.openqa.selenium.By;
-
-public class CommentsForm extends BaseForm {
-
- private final IButton nextCommentsButton;
-
-
- public CommentsForm(Post post) {
- super(AqualityServices.getElementFactory().getLabel(By.id("replies_wrap" + post.owner().getId() + "_" + post.id()), "Comments"),
- "Comments form");
- nextCommentsButton = AqualityServices.getElementFactory().getButton(
- By.xpath("//*[@id='" + "replies_wrap" + post.owner().getId() + "_" + post.id() + "']//*[contains(@class, 'replies_next')]"),
- "Next comments"
- );
- }
-
- public boolean contains(Comment comment) {
- CommentForm commentForm = new CommentForm(comment);
-
- if (nextCommentsButton.getElement().isDisplayed()) {
- nextCommentsButton.click();
- }
- return commentForm.contains(comment);
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/FeedPage.java b/src/main/java/com/mavlushechka/a1qa/pages/FeedPage.java
deleted file mode 100644
index bebecc1..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/FeedPage.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import org.openqa.selenium.By;
-
-public class FeedPage extends BaseForm {
-
- private final SideBarForm sideBarForm = new SideBarForm();
-
-
- public FeedPage() {
- super(AqualityServices.getElementFactory().getLabel(By.id("main_feed"), "Main feed"), "Feed");
- }
-
- public void clickMyProfileButton() {
- sideBarForm.clickMyProfileButton();
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/HomePage.java b/src/main/java/com/mavlushechka/a1qa/pages/HomePage.java
deleted file mode 100644
index 20339f8..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/HomePage.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import aquality.selenium.elements.interfaces.IButton;
-import aquality.selenium.elements.interfaces.ITextBox;
-import org.openqa.selenium.By;
-
-public class HomePage extends BaseForm {
-
- private final ITextBox phoneOrEmailTextBox = AqualityServices.getElementFactory().getTextBox(By.id("index_email"), "Phone or email");
- private final IButton signInButton = AqualityServices.getElementFactory().getButton(
- By.xpath("//button[contains(@class, 'VkIdForm__signInButton')]"),"Sign in"
- );
-
-
- public HomePage() {
- super(AqualityServices.getElementFactory().getLabel(By.xpath("//*[contains(@class, 'IndexPageContent')]"), "Index page content"), "Home");
- }
-
- public void performAuthorization(String phoneOrEmail) {
- phoneOrEmailTextBox.clearAndType(phoneOrEmail);
- signInButton.click();
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/PostForm.java b/src/main/java/com/mavlushechka/a1qa/pages/PostForm.java
deleted file mode 100644
index dc5f8b0..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/PostForm.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import aquality.selenium.elements.interfaces.IButton;
-import aquality.selenium.elements.interfaces.ILabel;
-import com.mavlushechka.a1qa.models.Comment;
-import com.mavlushechka.a1qa.models.Post;
-import org.openqa.selenium.By;
-
-import java.util.Objects;
-
-public class PostForm extends BaseForm {
-
- private final ILabel authorLabel;
- private final ILabel textLabel;
- private final ILabel imageLabel;
- private final IButton likeButton;
-
-
- public PostForm(Post post) {
- super(AqualityServices.getElementFactory().getLabel(By.id("post" + post.owner().getId() + "_" + post.id()), "Post"), "Post form");
- String postXpath = "//*[@id='" + "post" + post.owner().getId() + "_" + post.id() + "']";
- authorLabel = AqualityServices.getElementFactory().getLabel(
- By.xpath(postXpath + "//*[contains(@class, 'post_author')]//a[contains(@class, 'author')]"), "Post author"
- );
- textLabel = AqualityServices.getElementFactory().getLabel(By.xpath(postXpath + "//*[contains(@class, 'wall_post_text')]"), "Post text");
- imageLabel = AqualityServices.getElementFactory().getLabel(
- By.xpath(postXpath + "//*[contains(@class, 'page_post_thumb_wrap')]"), "Post image"
- );
- likeButton = AqualityServices.getElementFactory().getButton(By.xpath(postXpath + "//*[@data-reaction-set-id='reactions']"), "Like");
- }
-
- public boolean contains(Post post) {
- boolean containsPost = Objects.equals(authorLabel.getText(), post.owner().getFirstName() + " " + post.owner().getLastName())
- && Objects.equals(textLabel.getText(), post.message());
-
- if (post.attachment() != null) {
- containsPost &= Objects.equals(post.attachment().toString(), imageLabel.getAttribute("href").split("vk.com/")[1]);
- } else {
- containsPost &= !imageLabel.state().isDisplayed();
- }
-
- return containsPost;
- }
-
- public boolean contains(Comment comment) {
- return new CommentsForm(comment.post()).contains(comment);
- }
-
- public void clickLikeButton() {
- likeButton.getElement().click();
- }
-
- public void waitForUpdate() {
- String text = textLabel.getText();
- AqualityServices.getConditionalWait().waitFor(() -> !Objects.equals(textLabel.getText(), text));
- }
-
- public void waitForDelete() {
- AqualityServices.getConditionalWait().waitFor(this::notExists);
- }
-
- public boolean notExists() {
- return !authorLabel.state().isDisplayed();
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/ProfilePage.java b/src/main/java/com/mavlushechka/a1qa/pages/ProfilePage.java
deleted file mode 100644
index 816517d..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/ProfilePage.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import com.mavlushechka.a1qa.models.Comment;
-import com.mavlushechka.a1qa.models.Post;
-import org.openqa.selenium.By;
-
-public class ProfilePage extends BaseForm {
-
- private final ProfileWallForm profileWallForm = new ProfileWallForm();
-
-
- public ProfilePage() {
- super(AqualityServices.getElementFactory().getLabel(By.id("profile"), "Profile"), "Profile");
- }
-
- public boolean contains(Post post) {
- return profileWallForm.contains(post);
- }
-
- public boolean contains(Comment comment) {
- return profileWallForm.contains(comment);
- }
-
- public boolean notContains(Post post) {
- return profileWallForm.notContains(post);
- }
-
- public void clickPostLikeButton(Post post) {
- profileWallForm.clickPostLikeButton(post);
- }
-
- public void waitForPostUpdate(Post post) {
- profileWallForm.waitForPostUpdate(post);
- }
-
- public void waitForPostDelete(Post post) {
- profileWallForm.waitForPostDelete(post);
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/ProfileWallForm.java b/src/main/java/com/mavlushechka/a1qa/pages/ProfileWallForm.java
deleted file mode 100644
index d8ddc37..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/ProfileWallForm.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import com.mavlushechka.a1qa.models.Comment;
-import com.mavlushechka.a1qa.models.Post;
-import org.openqa.selenium.By;
-
-public class ProfileWallForm extends BaseForm {
-
- public ProfileWallForm() {
- super(AqualityServices.getElementFactory().getLabel(By.id("profile_wall"), "Profile wall"), "Profile wall form");
- }
-
- public boolean contains(Post post) {
- PostForm postForm = new PostForm(post);
-
- if (!postForm.isOpened()) {
- return false;
- }
- return postForm.contains(post);
- }
-
- public boolean notContains(Post post) {
- return new PostForm(post).notExists();
- }
-
- public boolean contains(Comment comment) {
- return new PostForm(comment.post()).contains(comment);
- }
-
- public void clickPostLikeButton(Post post) {
- new PostForm(post).clickLikeButton();
- }
-
- public void waitForPostUpdate(Post post) {
- new PostForm(post).waitForUpdate();
- }
-
- public void waitForPostDelete(Post post) {
- new PostForm(post).waitForDelete();
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/SideBarForm.java b/src/main/java/com/mavlushechka/a1qa/pages/SideBarForm.java
deleted file mode 100644
index 8df8c3d..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/SideBarForm.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import aquality.selenium.elements.interfaces.IButton;
-import org.openqa.selenium.By;
-
-public class SideBarForm extends BaseForm {
-
- private final IButton myProfileButton = AqualityServices.getElementFactory().getButton(By.id("l_pr"), "My profile");
-
-
- public SideBarForm() {
- super(AqualityServices.getElementFactory().getLabel(By.id("side_bar"), "Side bar"), "Side bar form");
- }
-
- public void clickMyProfileButton() {
- myProfileButton.click();
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/pages/SignInPage.java b/src/main/java/com/mavlushechka/a1qa/pages/SignInPage.java
deleted file mode 100644
index 56c16e7..0000000
--- a/src/main/java/com/mavlushechka/a1qa/pages/SignInPage.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.mavlushechka.a1qa.pages;
-
-import aquality.selenium.browser.AqualityServices;
-import aquality.selenium.elements.interfaces.IButton;
-import aquality.selenium.elements.interfaces.ITextBox;
-import org.openqa.selenium.By;
-
-public class SignInPage extends BaseForm {
-
- private final ITextBox passwordTextBox = AqualityServices.getElementFactory().getTextBox(
- By.xpath("//input[contains(@name, 'password')]"), "Password"
- );
- private final IButton continueButton = AqualityServices.getElementFactory().getButton(
- By.xpath("//*[contains(@class, 'vkc__EnterPasswordNoUserInfo__buttonWrap')]//button[contains(@class, 'vkuiButton')]"), "Continue"
- );
-
-
- public SignInPage() {
- super(
- AqualityServices.getElementFactory().getLabel(By.xpath("//form[contains(@class, 'vkc__EnterPasswordNoUserInfo__content')]"),
- "Password form"), "Sign in"
- );
- }
-
- public void performAuthorization(String password) {
- passwordTextBox.clearAndType(password);
- continueButton.click();
- }
-
-}
diff --git a/src/main/java/com/mavlushechka/a1qa/utils/Database.java b/src/main/java/com/mavlushechka/a1qa/utils/Database.java
new file mode 100644
index 0000000..1926618
--- /dev/null
+++ b/src/main/java/com/mavlushechka/a1qa/utils/Database.java
@@ -0,0 +1,88 @@
+package com.mavlushechka.a1qa.utils;
+
+import com.mavlushechka.a1qa.models.User;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class Database {
+
+ private static final String name = JsonParser.parseData("config", "database.name");
+ private static final Connection connection;
+ private static final User user = new User(JsonParser.parseData("config", "database.user.name"),
+ JsonParser.parseData("config", "database.user.password"));
+
+
+ static {
+ try {
+ Class.forName(JsonParser.parseData("config", "database.driver"));
+ connection = DriverManager.getConnection(JsonParser.parseData("config", "database.url") + "/" + name, user.name(), user.password());
+ } catch (SQLException | ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ private Database() {
+ }
+
+ public static List<String> getTests() {
+ return executeQuery("SELECT project.name, test.name, TIMESTAMPDIFF(MICROSECOND, test.start_time, test.end_time) as min_working_time"
+ + " FROM project INNER JOIN test ON project.id = test.project_id ORDER BY project.name, test.name;",
+ Map.of("project.name", String.class,"test.name", String.class,"min_working_time", Long.class));
+ }
+
+ public static List<String> getTestsCount() {
+ return executeQuery("SELECT project.name, (SELECT COUNT(*) FROM test WHERE test.project_id = project.id) AS `tests_count` FROM project;",
+ Map.of("project.name", String.class, "tests_count", Long.class));
+ }
+
+ public static List<String> getTestsByLowerDate(LocalDate localDate) {
+ return executeQuery("SELECT project.name, test.name, test.start_time FROM project JOIN test ON project.id = test.project_id"
+ + " WHERE test.start_time >= '%s' ORDER BY project.name, test.name;".formatted(localDate),
+ Map.of("project.name", String.class, "test.name", String.class, "start_time", LocalDate.class));
+ }
+
+ public static List<String> getBrowserTestsCount() {
+ return executeQuery("SELECT test.browser, COUNT(*) as count FROM test WHERE test.browser = 'firefox'"
+ + " UNION"
+ + " SELECT test.browser, COUNT(*) as count FROM test WHERE test.browser = 'chrome';",
+ Map.of("browser", String.class, "count", Long.class));
+ }
+
+ private static List<String> executeQuery(String sql, Map<String, Class<?>> expectedData) {
+ ArrayList<String> foundData = new ArrayList<>();
+
+ try (PreparedStatement preparedStatement = connection.prepareStatement(sql);
+ ResultSet resultSet = preparedStatement.executeQuery()) {
+ while (resultSet.next()) {
+ StringBuilder dataStringRepresentationBuilder = new StringBuilder();
+
+ dataStringRepresentationBuilder.append("{");
+ for (String expectedDataKey : expectedData.keySet()) {
+ dataStringRepresentationBuilder
+ .append(expectedDataKey)
+ .append("=")
+ .append(resultSet.getObject(expectedDataKey, expectedData.get(expectedDataKey)))
+ .append(",");
+ }
+ dataStringRepresentationBuilder.deleteCharAt(dataStringRepresentationBuilder.toString().length() - 1);
+ dataStringRepresentationBuilder.append("}");
+
+ foundData.add(dataStringRepresentationBuilder.toString());
+ }
+ } catch (SQLException sqlException) {
+ sqlException.printStackTrace();
+ }
+
+ return foundData;
+ }
+
+}
diff --git a/src/main/java/com/mavlushechka/a1qa/utils/VkApiUtils.java b/src/main/java/com/mavlushechka/a1qa/utils/VkApiUtils.java
deleted file mode 100644
index 845ecc7..0000000
--- a/src/main/java/com/mavlushechka/a1qa/utils/VkApiUtils.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.mavlushechka.a1qa.utils;
-
-import com.mavlushechka.a1qa.constants.Method;
-import com.mavlushechka.a1qa.models.Liker;
-import com.mavlushechka.a1qa.models.Post;
-import com.mavlushechka.a1qa.models.User;
-import org.json.JSONObject;
-
-import java.io.IOException;
-
-public class VkApiUtils {
-
- private final static double apiVersion = 5.131;
- private final static String url = "https://api.vk.com/method/%s?v=" + apiVersion + "&%s&access_token=" + JsonParser.parseData("testData", "vkontakte.account.token");
-
-
- public static User getCurrentUser() throws IOException {
- return JsonParser.convertToObject(
- new JSONObject(UrlConnectionManager.get(url.formatted(Method.USERS_GET.name, "")))
- .getJSONArray("response").get(0).toString(), User.class
- );
- }
-
- public static int createPost(String message) throws IOException {
- return new JSONObject(UrlConnectionManager.get(url.formatted(Method.WALL_POST.name, "message=" + message)))
- .getJSONObject("response").getInt("post_id");
- }
-
- public static void editPost(Post post, Post editedPost) throws IOException {
- UrlConnectionManager.get(
- url.formatted(
- Method.WALL_EDIT.name,
- "post_id=" + post.id() + "&message=" + editedPost.message() + "&attachments=" + editedPost.attachment()
- )
- );
- }
-
- public static void deletePost(Post post) throws IOException {
- UrlConnectionManager.get(url.formatted(Method.WALL_DELETE.name, "post_id=" + post.id()));
- }
-
- public static int createComment(int postId, String message) throws IOException {
- return new JSONObject(UrlConnectionManager.get(url.formatted(Method.WALL_CREATE_COMMENT.name, "post_id=" + postId + "&message=" + message)))
- .getJSONObject("response").getInt("comment_id");
- }
-
- public static boolean containsLike(Post post, User user) throws IOException {
- Object[] users = JsonParser.convertArray(new JSONObject(UrlConnectionManager.get(
- url.formatted(Method.WALL_GET_LIKES.name, "post_id=" + post.id())
- )).getJSONObject("response").getJSONArray("users").toString(),
- Liker.class
- );
-
- for (Object userObject : users) {
- if (((Liker) userObject).getUid() == user.getId()) {
- return true;
- }
- }
- return false;
- }
-
-}