Search in sources :

Example 1 with Answer

use of org.mamute.model.Answer 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 2 with Answer

use of org.mamute.model.Answer 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)

Example 3 with Answer

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

the class ReputationEventDAOTest method should_return_tag_answerer_summary.

@Test
public void should_return_tag_answerer_summary() {
    User solutionAuthor = user("solutionAuthor", "solution@x.com");
    User otherAnswerAuthor = user("answerAuthor", "other@x.com");
    Tag tag = tag("teste");
    Question question1 = question(author, tag);
    Answer answer1 = answer("BLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLA", question1, solutionAuthor);
    Answer answer2 = answer("BLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLA", question1, otherAnswerAuthor);
    Question question2 = question(author, tag);
    Answer answer3 = answer("BLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLABLA", question2, solutionAuthor);
    ReputationEvent answer3Upvote = new ReputationEvent(EventType.ANSWER_UPVOTE, question2, solutionAuthor);
    for (int i = 0; i < 30; i++) {
        ReputationEvent questionUpvote = new ReputationEvent(EventType.QUESTION_UPVOTE, question1, author);
        session.save(questionUpvote);
    }
    ReputationEvent answerIsSolution = new ReputationEvent(EventType.SOLVED_QUESTION, question1, solutionAuthor);
    ReputationEvent solutionUpvote = new ReputationEvent(EventType.ANSWER_UPVOTE, question1, solutionAuthor);
    long karmaRewardForSolution = SOLVED_QUESTION.reward().longValue() + ANSWER_UPVOTE.reward().longValue() * 2;
    ReputationEvent answer2Upvote = new ReputationEvent(EventType.ANSWER_UPVOTE, question1, otherAnswerAuthor);
    ReputationEvent answer2Upvote2 = new ReputationEvent(EventType.ANSWER_UPVOTE, question1, otherAnswerAuthor);
    long karmaRewardForOtherAnswer = ANSWER_UPVOTE.reward().longValue() * 2;
    session.save(tag);
    session.save(question1);
    session.save(question2);
    session.save(otherAnswerAuthor);
    session.save(solutionAuthor);
    session.save(answer1);
    session.save(answer2);
    session.save(answer3);
    session.save(answerIsSolution);
    session.save(solutionUpvote);
    session.save(answer2Upvote);
    session.save(answer2Upvote2);
    session.save(answer3Upvote);
    List<UserSummaryForTag> summaryForTag = reputationEvents.getTopAnswerersSummaryAllTime(tag);
    assertEquals(2, summaryForTag.size());
    assertEquals(karmaRewardForSolution, summaryForTag.get(0).getKarmaReward().longValue());
    assertEquals(solutionAuthor, summaryForTag.get(0).getUser());
    assertEquals(2l, summaryForTag.get(0).getCount().longValue());
    assertEquals(karmaRewardForOtherAnswer, summaryForTag.get(1).getKarmaReward().longValue());
    assertEquals(otherAnswerAuthor, summaryForTag.get(1).getUser());
    assertEquals(1l, summaryForTag.get(1).getCount().longValue());
}
Also used : Answer(org.mamute.model.Answer) UserSummaryForTag(org.mamute.dto.UserSummaryForTag) User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag) UserSummaryForTag(org.mamute.dto.UserSummaryForTag) ReputationEvent(org.mamute.model.ReputationEvent) Test(org.junit.Test)

Example 4 with Answer

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

the class VoteDAOTest method should_return_right_comments_and_currentUser_votes_map.

@Test
public void should_return_right_comments_and_currentUser_votes_map() {
    Question question = question(currentUser, tags);
    Answer answer = answer("blablablablablablablablablablbalblabla", question, currentUser);
    Comment answerComment1 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(1));
    Comment answerComment2 = comment(currentUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(2));
    Comment answerComment3 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(3));
    answer.add(answerComment1);
    answer.add(answerComment2);
    answer.add(answerComment3);
    Comment questionComment1 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(4));
    Comment questionComment2 = comment(currentUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(5));
    Comment questionComment3 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(6));
    question.add(questionComment1);
    question.add(questionComment2);
    question.add(questionComment3);
    Vote currentUserUpVote1 = upvote(answerComment1, currentUser);
    Vote currentUserUpVote2 = upvote(questionComment1, currentUser);
    upvote(answerComment2, otherUser);
    upvote(questionComment2, otherUser);
    session.save(question);
    session.save(answer);
    session.save(answerComment1);
    session.save(answerComment2);
    session.save(answerComment3);
    CommentsAndVotes commentsAndVotes = votes.previousVotesForComments(question, currentUser);
    assertEquals(currentUserUpVote1, commentsAndVotes.getVotes(answerComment1));
    assertEquals(currentUserUpVote2, commentsAndVotes.getVotes(questionComment1));
    assertEquals(null, commentsAndVotes.getVotes(questionComment2));
    assertEquals(null, commentsAndVotes.getVotes(answerComment2));
    assertEquals(null, commentsAndVotes.getVotes(questionComment3));
    assertEquals(null, commentsAndVotes.getVotes(answerComment3));
}
Also used : Answer(org.mamute.model.Answer) Comment(org.mamute.model.Comment) CommentsAndVotes(org.mamute.model.CommentsAndVotes) Vote(org.mamute.model.Vote) MassiveVote(org.mamute.model.vote.MassiveVote) SuspectMassiveVote(org.mamute.dto.SuspectMassiveVote) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 5 with Answer

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

the class VoteDAOTest method testName.

@Test
public void testName() throws Exception {
    Question question = question(currentUser, tags);
    Answer answer = answer("answer answer answer answer answer", question, currentUser);
    Question question2 = question(currentUser, tags);
    Answer answer2 = answer("answer answer answer answer answer", question2, currentUser);
    Question question3 = question(currentUser, tags);
    Answer answer3 = answer("answer answer answer answer answer", question3, currentUser);
    session.save(question);
    session.save(question2);
    session.save(question3);
    session.save(answer);
    session.save(answer2);
    session.save(answer3);
    upvote(answer, otherUser);
    upvote(answer2, otherUser);
    upvote(answer3, otherUser);
    List<SuspectMassiveVote> answers = votes.suspectMassiveVote(VoteType.UP, new DateTime().minusHours(1), new DateTime());
    assertEquals(otherUser, answers.get(0).getVoteAuthor());
    assertEquals(currentUser, answers.get(0).getAnswerAuthor());
    assertEquals(3l, answers.get(0).getMassiveVoteCount().longValue());
}
Also used : Answer(org.mamute.model.Answer) SuspectMassiveVote(org.mamute.dto.SuspectMassiveVote) Question(org.mamute.model.Question) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

Answer (org.mamute.model.Answer)31 Test (org.junit.Test)27 Question (org.mamute.model.Question)24 User (org.mamute.model.User)9 ArrayList (java.util.ArrayList)6 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)5 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)5 LoggedUser (org.mamute.model.LoggedUser)5 AnswerAndVotes (org.mamute.model.AnswerAndVotes)4 AnswerInformation (org.mamute.model.AnswerInformation)4 Comment (org.mamute.model.Comment)3 Tag (org.mamute.model.Tag)3 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)2 Information (org.mamute.model.Information)2 Vote (org.mamute.model.Vote)2 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 Nullable (javax.annotation.Nullable)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 DateTime (org.joda.time.DateTime)1