Search in sources :

Example 6 with Tag

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

the class ReputationEventDAOTest method should_return_tag_asker_summary.

@Test
public void should_return_tag_asker_summary() {
    User question1Author = user("solutionAuthor", "solution@x.com");
    User question3Author = user("answerAuthor", "other@x.com");
    session.save(question3Author);
    session.save(question1Author);
    Tag tag = tag("teste");
    session.save(tag);
    Question question1 = question(question1Author, tag);
    Question question2 = question(question1Author, tag);
    Question question3 = question(question3Author, tag);
    session.save(question1);
    session.save(question2);
    session.save(question3);
    for (int i = 0; i < 30; i++) {
        session.save(new ReputationEvent(EventType.QUESTION_UPVOTE, question1, question1Author));
    }
    session.save(new ReputationEvent(EventType.QUESTION_UPVOTE, question2, question1Author));
    long karmaRewardForQuestion1 = EventType.QUESTION_UPVOTE.reward().longValue() * 31;
    for (int i = 0; i < 10; i++) {
        session.save(new ReputationEvent(EventType.QUESTION_UPVOTE, question3, question3Author));
    }
    long karmaRewardForQuestion2 = EventType.QUESTION_UPVOTE.reward().longValue() * 10;
    List<UserSummaryForTag> summaryForTag = reputationEvents.getTopAskersSummaryAllTime(tag);
    assertEquals(2, summaryForTag.size());
    assertEquals(karmaRewardForQuestion1, summaryForTag.get(0).getKarmaReward().longValue());
    assertEquals(question1Author, summaryForTag.get(0).getUser());
    assertEquals(2l, summaryForTag.get(0).getCount().longValue());
    assertEquals(karmaRewardForQuestion2, summaryForTag.get(1).getKarmaReward().longValue());
    assertEquals(question3Author, summaryForTag.get(1).getUser());
    assertEquals(1l, summaryForTag.get(1).getCount().longValue());
}
Also used : 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 7 with Tag

use of org.mamute.model.Tag 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 8 with Tag

use of org.mamute.model.Tag 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 9 with Tag

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

the class VoteDAOTest method beforeTest.

@Before
public void beforeTest() {
    votes = new VoteDAO(session);
    currentUser = user("Current User", "currentUser@email.com");
    otherUser = user("Other User", "otherUser@email.com");
    session.save(otherUser);
    session.save(currentUser);
    tags.add(tag("bla"));
    for (Tag tag : tags) {
        session.save(tag);
    }
    InvisibleForUsersRule invisibleRule = new InvisibleForUsersRule(new LoggedUser(currentUser, null));
    votingMachine = new VotingMachine(votes, new KarmaCalculator(), new ReputationEventDAO(session, invisibleRule), new MassiveVote(), new RetrieveKarmaDownvote());
}
Also used : VotingMachine(org.mamute.model.vote.VotingMachine) RetrieveKarmaDownvote(org.mamute.controllers.RetrieveKarmaDownvote) ReputationEventDAO(org.mamute.dao.ReputationEventDAO) KarmaCalculator(org.mamute.reputation.rules.KarmaCalculator) LoggedUser(org.mamute.model.LoggedUser) MassiveVote(org.mamute.model.vote.MassiveVote) SuspectMassiveVote(org.mamute.dto.SuspectMassiveVote) VoteDAO(org.mamute.dao.VoteDAO) Tag(org.mamute.model.Tag) InvisibleForUsersRule(org.mamute.dao.InvisibleForUsersRule) Before(org.junit.Before)

Example 10 with Tag

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

the class WatcherDAOTest method set_up.

@Before
public void set_up() {
    User leo = user("Leonardo", "leo@leo.com");
    session.save(leo);
    Tag java = tag("java");
    session.save(java);
    question = question(leo, java);
    session.save(question);
    watchers = new WatcherDAO(session, new InvisibleForUsersRule(new LoggedUser(leo, null)));
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) WatcherDAO(org.mamute.dao.WatcherDAO) LoggedUser(org.mamute.model.LoggedUser) Tag(org.mamute.model.Tag) InvisibleForUsersRule(org.mamute.dao.InvisibleForUsersRule) Before(org.junit.Before)

Aggregations

Tag (org.mamute.model.Tag)21 Question (org.mamute.model.Question)9 Test (org.junit.Test)8 User (org.mamute.model.User)7 Before (org.junit.Before)5 LoggedUser (org.mamute.model.LoggedUser)5 Get (br.com.caelum.vraptor.Get)3 ArrayList (java.util.ArrayList)3 Answer (org.mamute.model.Answer)3 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)2 Post (br.com.caelum.vraptor.Post)2 InvisibleForUsersRule (org.mamute.dao.InvisibleForUsersRule)2 UserSummaryForTag (org.mamute.dto.UserSummaryForTag)2 Attachment (org.mamute.model.Attachment)2 QuestionInformation (org.mamute.model.QuestionInformation)2 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)2 ReputationEvent (org.mamute.model.ReputationEvent)2 TagPage (org.mamute.model.TagPage)2 Environment (br.com.caelum.vraptor.environment.Environment)1 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)1