Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

MoveTopicPermissionsTest #61

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.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);
}

@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);
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 createQuestion(Question question, User user) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. as I've mentioned - content is already present in Topic


public QA() {
}

public QA(String title, String content) {
this.withTitle(title);
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}