Search in sources :

Example 11 with Question

use of org.mamute.model.Question in project mamute by caelum.

the class AnswerTest method return_true_if_answer_has_pending_edits.

@Test
public void return_true_if_answer_has_pending_edits() throws Exception {
    Question myQuestion = question.withTitle("question title").withDescription("description").withAuthor(author).build();
    Answer answer = answer("blablablab", myQuestion, author);
    assertFalse(answer.hasPendingEdits());
    AnswerInformation approved = new AnswerInformation(notMarked("blablabalblab"), new LoggedUser(editUser, null), answer, "");
    answer.enqueueChange(approved, PENDING);
    assertTrue(answer.hasPendingEdits());
}
Also used : Answer(org.mamute.model.Answer) Question(org.mamute.model.Question) LoggedUser(org.mamute.model.LoggedUser) AnswerInformation(org.mamute.model.AnswerInformation) Test(org.junit.Test)

Example 12 with Question

use of org.mamute.model.Question in project mamute by caelum.

the class AnswerTest method should_mark_question_as_solved.

@Test
public void should_mark_question_as_solved() {
    Question canILiveForever = question.build();
    Answer yes = answer("Yes", canILiveForever, null);
    assertEquals(null, canILiveForever.getSolution());
    yes.markAsSolution();
    assertEquals(yes, canILiveForever.getSolution());
}
Also used : Answer(org.mamute.model.Answer) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 13 with Question

use of org.mamute.model.Question in project mamute by caelum.

the class FlagController method topFlagged.

@CustomBrutauthRules(ModeratorOnlyRule.class)
@Get
public void topFlagged() {
    List<FlaggableAndFlagCount> flaggedQuestions = flaggables.flaggedButVisible(Question.class);
    List<FlaggableAndFlagCount> flaggedAnswers = flaggables.flaggedButVisible(Answer.class);
    List<FlaggableAndFlagCount> flaggedComments = flaggables.flaggedButVisible(Comment.class);
    List<Question> commentQuestions = new ArrayList<>();
    Iterator<FlaggableAndFlagCount> iterator = flaggedComments.iterator();
    while (iterator.hasNext()) {
        Comment comment = (Comment) iterator.next().getFlaggable();
        Question q = questions.fromCommentId(comment.getId());
        if (q != null) {
            commentQuestions.add(q);
            continue;
        }
        Answer answerFromComment = answers.fromCommentId(comment.getId());
        if (answerFromComment != null) {
            commentQuestions.add(answerFromComment.getQuestion());
            continue;
        }
        // some flags may be related to news (not questions nor answers)
        iterator.remove();
    }
    result.include("questions", flaggedQuestions);
    result.include("answers", flaggedAnswers);
    result.include("comments", flaggedComments);
    result.include("commentQuestions", commentQuestions);
}
Also used : Comment(org.mamute.model.Comment) Answer(org.mamute.model.Answer) FlaggableAndFlagCount(org.mamute.dto.FlaggableAndFlagCount) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) CustomBrutauthRules(br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules) Get(br.com.caelum.vraptor.Get)

Example 14 with Question

use of org.mamute.model.Question in project mamute by caelum.

the class VoteUpDownTest method login.

@Before
public void login() {
    DaoManager manager = new DaoManager();
    User author = manager.randomUser();
    Question question = manager.createQuestion(author);
    manager.answerQuestion(author, question);
    loginWithALotOfKarma();
    questionPage = home().toFirstQuestionPage();
}
Also used : User(org.mamute.model.User) Question(org.mamute.model.Question) DaoManager(org.mamute.integration.util.DaoManager) Before(org.junit.Before)

Example 15 with Question

use of org.mamute.model.Question in project mamute by caelum.

the class CommentAnswerTest method should_comment_answer_after_login.

@Test
public void should_comment_answer_after_login() throws Exception {
    User moderator = moderator();
    Question question = createQuestionWithDao(moderator, "Should comment answer after login", "Yeah, definitely should, who're you to say otherwise?", tag("java"));
    Answer answer = answerQuestionWithDao(karmaNigga(), question, "I'm de guy with lots of karma, nigga! So get over here!", false);
    String comment = "Oh, right, then I can't do a thing about it.";
    UserFlow navigation = login(navigate(), moderator.getEmail());
    navigation = commentWithFlow(navigation, answer, comment, false);
    VRaptorTestResult commentResult = navigation.followRedirect().execute();
    // COULD NOT COMPILE JSP
    commentResult.wasStatus(200).isValid();
    navigation = login(navigate(), moderator.getEmail());
    navigation = goToQuestionPage(navigation, question);
    VRaptorTestResult commentedAnswer = navigation.followRedirect().execute();
    commentedAnswer.wasStatus(200).isValid();
    Elements commentElement = getElementsByClass(commentedAnswer.getResponseBody(), "comment-container");
    Elements commentSpan = getElementsByTag(commentElement.html(), "span");
    Elements commentParagraph = getElementsByTag(commentSpan.html(), "p");
    assertEquals(comment, commentParagraph.html());
}
Also used : Answer(org.mamute.model.Answer) User(org.mamute.model.User) UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) Question(org.mamute.model.Question) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Aggregations

Question (org.mamute.model.Question)96 Test (org.junit.Test)74 User (org.mamute.model.User)28 Answer (org.mamute.model.Answer)24 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)15 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)15 Tag (org.mamute.model.Tag)9 ArrayList (java.util.ArrayList)8 QuestionBuilder (org.mamute.builder.QuestionBuilder)7 QuestionInformation (org.mamute.model.QuestionInformation)7 DateTime (org.joda.time.DateTime)6 LoggedUser (org.mamute.model.LoggedUser)5 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)5 Elements (org.jsoup.select.Elements)4 AnswerAndVotes (org.mamute.model.AnswerAndVotes)4 Comment (org.mamute.model.Comment)4 Get (br.com.caelum.vraptor.Get)3 Before (org.junit.Before)3 DaoManager (org.mamute.integration.util.DaoManager)3 AnswerInformation (org.mamute.model.AnswerInformation)3