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..2bb5aa3a --- /dev/null +++ b/functional-tests-jcommune/src/test/java/org/jtalks/tests/jcommune/MoveTopicsPermissionTest.java @@ -0,0 +1,104 @@ +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.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; +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); + } + +} + + 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(""); 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..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 @@ -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,28 @@ 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) { - throw new UnsupportedOperationException(); - } - - public static void moveTopic(Topic topic, String branchTitleWhereTopicMoves) { + public static void subscribe(Topic topic, User user) { 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,7 +288,7 @@ 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); @@ -315,24 +296,4 @@ public static void leaveCodeReviewComment(CodeReview codeReview, CodeReviewComme 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"); - } }