Search in sources :

Example 1 with CommentsAndVotes

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

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

the class VoteDAO method previousVotesForComments.

@SuppressWarnings("unchecked")
public CommentsAndVotes previousVotesForComments(Question question, User currentUser) {
    Query answerQuery = session.createQuery("select c,v from Question as q join q.answers as a join a.comments.comments as c join c.votes as v where v.author = :author and q = :question and c.deleted = false");
    answerQuery.setParameter("author", currentUser);
    answerQuery.setParameter("question", question);
    List commentsAndVotesList = previousVotesForComments(Question.class, currentUser, question);
    commentsAndVotesList.addAll(answerQuery.list());
    return new CommentsAndVotes(commentsAndVotesList);
}
Also used : CommentsAndVotes(org.mamute.model.CommentsAndVotes) Query(org.hibernate.Query) List(java.util.List)

Aggregations

CommentsAndVotes (org.mamute.model.CommentsAndVotes)2 List (java.util.List)1 Query (org.hibernate.Query)1 Test (org.junit.Test)1 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)1 Answer (org.mamute.model.Answer)1 Comment (org.mamute.model.Comment)1 Question (org.mamute.model.Question)1 Vote (org.mamute.model.Vote)1 MassiveVote (org.mamute.model.vote.MassiveVote)1