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);
}
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());
}
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());
}
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));
}
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());
}
Aggregations