From b4fe282a4587c7f0bb41983b4bac4d4c8181d9a8 Mon Sep 17 00:00:00 2001 From: timisoreana Date: Wed, 29 Apr 2015 22:55:12 +0300 Subject: [PATCH 1/4] MoveTopicPermissionsTest --- .../jcommune/MoveTopicsPermissionTest.java | 115 ++++++++++++++++++ .../jcommune/webdriver/action/Topics.java | 50 ++------ .../jcommune/webdriver/action/Users.java | 2 + .../jcommune/webdriver/entity/topic/QA.java | 26 ++++ 4 files changed, 150 insertions(+), 43 deletions(-) create mode 100644 functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java create mode 100644 jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java diff --git a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java new file mode 100644 index 00000000..e95b6995 --- /dev/null +++ b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java @@ -0,0 +1,115 @@ +package org.jtalks.tests.jcommune; + +import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig; +import org.jtalks.tests.jcommune.webdriver.action.Branches; +import org.jtalks.tests.jcommune.webdriver.action.Notifications; +import org.jtalks.tests.jcommune.webdriver.action.Topics; +import org.jtalks.tests.jcommune.webdriver.action.Users; +import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; +import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReview; +import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReviewComment; +import org.jtalks.tests.jcommune.webdriver.entity.topic.QA; +import org.jtalks.tests.jcommune.webdriver.entity.topic.Topic; +import org.jtalks.tests.jcommune.webdriver.entity.user.User; +import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException; +import org.jtalks.tests.jcommune.webdriver.page.TopicPage; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; +import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.driver; +import static org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig.getAppUrl; +import static org.jtalks.tests.jcommune.webdriver.page.Pages.mainPage; +/** + * @author timisoreana 23.03.2015 + */ +public class MoveTopicsPermissionTest { + + + @BeforeMethod(alwaysRun = false) + @Parameters({"appUrl"}) + public void setupCase(String appUrl) throws ValidationException { + driver.get(appUrl); + mainPage.logOutIfLoggedIn(driver); + } + + @Test + public void moveTopicToOtherBranch_ShouldPass() throws Exception { + User user = Users.signUpAndSignIn(); + Topic topic = Topics.createTopic(new Topic().withTopicStarter(user)).withBranch("Micro level"); + Users.logout(); + + User userTopicMover = new User(); + Users.signIn(userTopicMover); + + Topics.moveTopic(topic, "Classical Mechanics"); + Assert.assertEquals("Classical Mechanics", topic.getBranch().getTitle()); + } + + @Test + public void userWithoutMoveTopicsPermissionAndWithVewTopic_MoveTopic_ShouldFail() throws Exception { + User user = Users.signUpAndSignIn(); + Topic topic = Topics.createTopic(new Topic().withTopicStarter(user)); + + User userWithoutMoveAndWithViewTopicPerm = Users.signUpAndSignIn(); + Topics.moveByUser(topic, userWithoutMoveAndWithViewTopicPerm); + } + + + + @Test + public void userWithMoveTopicsAndWithoutViewTopic_MoveTopic_ShouldFail() throws Exception { + User user = Users.signUpAndSignIn(); + Topic topic = Topics.createTopic(new Topic().withTopicStarter(user)); + + User userWithMoveAndWithoutPerm = Users.signUpAndSignIn(); + Topics.moveByUser(topic, userWithMoveAndWithoutPerm); + } + + + @Test + public void userWithoutMoveTopicsAndWithoutViewTopic_MoveTopic_ShouldFail() throws Exception { + + User user = Users.signUpAndSignIn(); + Topic topic = Topics.createTopic(new Topic().withTopicStarter(user)); + + User userWithoutMoveAndWithoutPerm = Users.signUpAndSignIn(); + Topics.moveByUser(topic, userWithoutMoveAndWithoutPerm); + } + + + @Test + public void anonymousUser_MoveTopic_ShouldFail() throws Exception { + User user = Users.signUpAndSignIn(); + Topic topic = Topics.createTopic(new Topic().withTopicStarter(user)); + Users.logout(); + + Topics.moveByUser(topic, user); + } + + @Test + public void user_MoveCodeReviewTopic_ShouldPass() throws Exception { + Users.signUpAndSignIn(); + CodeReview codeReview = new CodeReview(); + Topics.createCodeReview(codeReview); + + User user = Users.signUpAndSignIn(); + Topics.moveByUser(codeReview, user); + } + + @Test + public void user_MoveQATopic_ShouldPass() throws Exception { + User user = Users.signUpAndSignIn(); + QA qa = new QA(); + Topics.createQA(qa, user); + Users.logout(); + + User mover = Users.signUpAndSignIn(); + Topics.moveByUser(qa, mover); + } + +} + + diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java index b625256b..7eec4baf 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java @@ -18,10 +18,7 @@ import org.jtalks.tests.jcommune.assertion.Existence; import org.jtalks.tests.jcommune.webdriver.JCommuneSeleniumConfig; import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; -import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReview; -import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReviewComment; -import org.jtalks.tests.jcommune.webdriver.entity.topic.Post; -import org.jtalks.tests.jcommune.webdriver.entity.topic.Topic; +import org.jtalks.tests.jcommune.webdriver.entity.topic.*; import org.jtalks.tests.jcommune.webdriver.entity.user.User; import org.jtalks.tests.jcommune.webdriver.exceptions.CouldNotOpenPageException; import org.jtalks.tests.jcommune.webdriver.exceptions.PermissionsDeniedException; @@ -244,44 +241,29 @@ public static boolean isCreated(Topic topic) { return actualTitle.equals(expectedTitle); } - public static void editPost (Topic topic, Integer indexNumberOfPostInTopic) { - throw new UnsupportedOperationException(); - } - public static void deleteByUser(Topic topic, User user) { throw new UnsupportedOperationException(); } - public static void deleteTopic(Topic topic) { + public static void subscribe(Topic topic, User user) { throw new UnsupportedOperationException(); } - public static void moveTopic(Topic topic, String branchTitleWhereTopicMoves) { - throw new UnsupportedOperationException(); - } - public static void subscribe(Topic topic) { - throw new UnsupportedOperationException(); - } - - public static void unsubscribe(Topic topic) { + public static void moveByUser(Topic topic, User user) { throw new UnsupportedOperationException(); } - - public static void moveByUser(Topic topic, User user) { + public static void moveTopic(Topic topic, String branchTitleWhereTopicMoves) { throw new UnsupportedOperationException(); } public static void deleteAnswer(Topic topic, Post selectedPost) { - throw new UnsupportedOperationException(); } public static void assertHasNewMessages(Topic newTopic, User userThatWantsToSeeNewMessages) { - throw new UnsupportedOperationException(); } public static void assertHasNoNewMessages(Topic newTopic, User userThatWantsToSeeNewMessages) { - throw new UnsupportedOperationException(); } // Code review methods @@ -307,32 +289,14 @@ public static CodeReview createCodeReview(CodeReview codeReview) return codeReview; } - public static void leaveCodeReviewComment(CodeReview codeReview, CodeReviewComment codeReviewComment) + public static void leaveCodeReviewComment(CodeReviewComment codeReviewComment) throws PermissionsDeniedException, ValidationException { topicPage.clickLineInCodeReviewForComment(codeReviewComment.getCommentedLineNumber()); topicPage.fillCodeReviewCommentBody(codeReviewComment); topicPage.clickAddCommentToCodeReviewButton(); assertCodeReviewFormValid(); } - - public static void assertIsSubscribed(Topic topic){ - throw new UnsupportedOperationException("To be implemented"); - } - - public static void editCodeReviewComment(CodeReview codeReview, CodeReviewComment codeReviewComment){ - throw new UnsupportedOperationException("To be implemented"); - } - - public static void leaveCodeReviewComment(CodeReview codeReview){ - throw new UnsupportedOperationException("To be implemented"); - } - - //overloaded method below was added to avoid compilation errors - public static void leaveCodeReviewComment(CodeReviewComment codeReviewComment){ - throw new UnsupportedOperationException("To be implemented"); - } - - public static void deleteCodeReviewComment(CodeReview codeReview, CodeReviewComment codeReviewComment){ - throw new UnsupportedOperationException("To be implemented"); + public static void createQA(QA qa, User user) { + throw new UnsupportedOperationException(); } } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java index ea52346e..d830a2fc 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java @@ -47,6 +47,7 @@ */ public class Users { private static final Logger LOGGER = LoggerFactory.getLogger(Users.class); + private static User user; /** * Sign in user by dialog. Action can by started from any page of JCommune. @@ -56,6 +57,7 @@ public class Users { */ @Step public static void signIn(User user) throws ValidationException { + Users.user = user; info("Sign in a User: " + user); openAndFillSignInDialog(user); checkFormValidation(signInPage.getErrorFormElements()); diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java new file mode 100644 index 00000000..f74f0de8 --- /dev/null +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java @@ -0,0 +1,26 @@ +package org.jtalks.tests.jcommune.webdriver.entity.topic; + + +import com.google.common.base.Splitter; +import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; +import org.apache.commons.lang3.StringUtils; +import java.util.List; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; + + +/** + * JCommune QA representation + */ + +public class QA extends Topic { + private String content = randomAlphanumeric(50); + + public QA() { + } + + public QA(String title, String content) { + this.withTitle(title); + this.content = content; + } +} From 96f9bbcaad2c5fe443a68030819828c6a576d140 Mon Sep 17 00:00:00 2001 From: timisoreana Date: Mon, 4 May 2015 10:35:06 +0300 Subject: [PATCH 2/4] Change QA to Question --- .../jcommune/MoveTopicsPermissionTest.java | 8 +++--- .../jcommune/webdriver/action/Topics.java | 2 +- .../jcommune/webdriver/action/Users.java | 2 -- .../webdriver/entity/topic/Question.java | 26 +++++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java diff --git a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java index e95b6995..ea895156 100644 --- a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java +++ b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java @@ -8,7 +8,7 @@ import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReview; import org.jtalks.tests.jcommune.webdriver.entity.topic.CodeReviewComment; -import org.jtalks.tests.jcommune.webdriver.entity.topic.QA; +import org.jtalks.tests.jcommune.webdriver.entity.topic.Question; import org.jtalks.tests.jcommune.webdriver.entity.topic.Topic; import org.jtalks.tests.jcommune.webdriver.entity.user.User; import org.jtalks.tests.jcommune.webdriver.exceptions.ValidationException; @@ -102,12 +102,12 @@ public void user_MoveCodeReviewTopic_ShouldPass() throws Exception { @Test public void user_MoveQATopic_ShouldPass() throws Exception { User user = Users.signUpAndSignIn(); - QA qa = new QA(); - Topics.createQA(qa, user); + Question question = new Question(); + Topics.createQuestion(question, user); Users.logout(); User mover = Users.signUpAndSignIn(); - Topics.moveByUser(qa, mover); + Topics.moveByUser(question, mover); } } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java index 7eec4baf..39248787 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java @@ -296,7 +296,7 @@ public static void leaveCodeReviewComment(CodeReviewComment codeReviewComment) topicPage.clickAddCommentToCodeReviewButton(); assertCodeReviewFormValid(); } - public static void createQA(QA qa, User user) { + public static void createQuestion(Question question, User user) { throw new UnsupportedOperationException(); } } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java index d830a2fc..ea52346e 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Users.java @@ -47,7 +47,6 @@ */ public class Users { private static final Logger LOGGER = LoggerFactory.getLogger(Users.class); - private static User user; /** * Sign in user by dialog. Action can by started from any page of JCommune. @@ -57,7 +56,6 @@ public class Users { */ @Step public static void signIn(User user) throws ValidationException { - Users.user = user; info("Sign in a User: " + user); openAndFillSignInDialog(user); checkFormValidation(signInPage.getErrorFormElements()); diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java new file mode 100644 index 00000000..ad80842b --- /dev/null +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java @@ -0,0 +1,26 @@ +package org.jtalks.tests.jcommune.webdriver.entity.topic; + + +import com.google.common.base.Splitter; +import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; +import org.apache.commons.lang3.StringUtils; +import java.util.List; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; + + +/** + * JCommune QA representation + */ + +public class Question extends Topic { + private String content = randomAlphanumeric(50); + + public Question() { + } + + public Question(String title, String content) { + this.withTitle(title); + this.content = content; + } +} From 57c1b009219ae932dffc565c96d07cf90164acc9 Mon Sep 17 00:00:00 2001 From: timisoreana Date: Sun, 10 May 2015 19:17:15 +0300 Subject: [PATCH 3/4] Question(QA) deleted --- .../jcommune/MoveTopicsPermissionTest.java | 11 -------- .../jcommune/webdriver/action/Topics.java | 5 +--- .../jcommune/webdriver/entity/topic/QA.java | 26 ------------------- .../webdriver/entity/topic/Question.java | 26 ------------------- 4 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java delete mode 100644 jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java diff --git a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java index ea895156..2bb5aa3a 100644 --- a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java +++ b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java @@ -99,17 +99,6 @@ public void user_MoveCodeReviewTopic_ShouldPass() throws Exception { Topics.moveByUser(codeReview, user); } - @Test - public void user_MoveQATopic_ShouldPass() throws Exception { - User user = Users.signUpAndSignIn(); - Question question = new Question(); - Topics.createQuestion(question, user); - Users.logout(); - - User mover = Users.signUpAndSignIn(); - Topics.moveByUser(question, mover); - } - } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java index 39248787..26732e89 100644 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java +++ b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/action/Topics.java @@ -249,7 +249,6 @@ public static void subscribe(Topic topic, User user) { throw new UnsupportedOperationException(); } - public static void moveByUser(Topic topic, User user) { throw new UnsupportedOperationException(); } @@ -296,7 +295,5 @@ public static void leaveCodeReviewComment(CodeReviewComment codeReviewComment) topicPage.clickAddCommentToCodeReviewButton(); assertCodeReviewFormValid(); } - public static void createQuestion(Question question, User user) { - throw new UnsupportedOperationException(); - } + } diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java deleted file mode 100644 index f74f0de8..00000000 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/QA.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.jtalks.tests.jcommune.webdriver.entity.topic; - - -import com.google.common.base.Splitter; -import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; -import org.apache.commons.lang3.StringUtils; -import java.util.List; - -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; - - -/** - * JCommune QA representation - */ - -public class QA extends Topic { - private String content = randomAlphanumeric(50); - - public QA() { - } - - public QA(String title, String content) { - this.withTitle(title); - this.content = content; - } -} diff --git a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java b/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java deleted file mode 100644 index ad80842b..00000000 --- a/jcommune-webdriver/src/main/java/org/jtalks/tests/jcommune/webdriver/entity/topic/Question.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.jtalks.tests.jcommune.webdriver.entity.topic; - - -import com.google.common.base.Splitter; -import org.jtalks.tests.jcommune.webdriver.entity.branch.Branch; -import org.apache.commons.lang3.StringUtils; -import java.util.List; - -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; - - -/** - * JCommune QA representation - */ - -public class Question extends Topic { - private String content = randomAlphanumeric(50); - - public Question() { - } - - public Question(String title, String content) { - this.withTitle(title); - this.content = content; - } -} From 52b5fcf2dabad6252b6d4f0e1435a2cedd497977 Mon Sep 17 00:00:00 2001 From: timisoreana Date: Tue, 19 May 2015 12:01:01 +0300 Subject: [PATCH 4/4] Check messages when all fields are empty --- .../src/test/java/org/jtalks/tests/jcommune/SignUpTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/SignUpTest.java b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/SignUpTest.java index 34e7262a..9ef91541 100644 --- a/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/SignUpTest.java +++ b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/SignUpTest.java @@ -51,7 +51,8 @@ public void registrationValid_shouldPass() throws Exception { Users.signUp(user); } - @Test(expectedExceptions = ValidationException.class) + @Test(groups = "ui-tests", expectedExceptions = ValidationException.class, + expectedExceptionsMessageRegExp = SignUpPage.EMPTY_LOGIN_ERROR + SignUpPage.EMPTY_EMAIL_ERROR + SignUpPage.EMPTY_PASSWORD_ERROR ) public void dataEmpty_shouldFail() throws Exception { UserForRegistration user = new UserForRegistration(); user.setUsername("");