Search in sources :

Example 31 with Question

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

the class TestCase method question.

protected Question question(User author, Tag... tags) {
    ArrayList<Tag> tagsList = new ArrayList<>(Arrays.asList(tags));
    if (tagsList.isEmpty())
        tagsList.add(tag("teste"));
    Question question = questionBuilder.withAuthor(author).withTags(tagsList).build();
    return question;
}
Also used : ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag)

Example 32 with Question

use of org.mamute.model.Question 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 33 with Question

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

Example 34 with Question

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

the class PostViewCounterTest method should_increase_count_only_first_time.

@Test
public void should_increase_count_only_first_time() {
    Question question = new QuestionBuilder().withId(1l).build();
    questionViewCounter.ping(question);
    mockQuestionVisited(question);
    assertEquals(1l, question.getViews());
    questionViewCounter.ping(question);
    assertEquals(1l, question.getViews());
}
Also used : QuestionBuilder(org.mamute.builder.QuestionBuilder) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 35 with Question

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

the class PostViewCounterTest method should_increase_count_only_the_news_counter.

@Test
public void should_increase_count_only_the_news_counter() {
    Question question = new QuestionBuilder().withId(1l).build();
    News news = new NewsBuilder().withId(1l).build();
    questionViewCounter.ping(question);
    mockQuestionVisited(question);
    questionViewCounter.ping(news);
    assertEquals(1l, question.getViews());
    assertEquals(1l, news.getViews());
}
Also used : NewsBuilder(org.mamute.builder.NewsBuilder) QuestionBuilder(org.mamute.builder.QuestionBuilder) News(org.mamute.model.News) Question(org.mamute.model.Question) 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