Search in sources :

Example 1 with InvisibleForUsersRule

use of org.mamute.dao.InvisibleForUsersRule 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 2 with InvisibleForUsersRule

use of org.mamute.dao.InvisibleForUsersRule 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)

Example 3 with InvisibleForUsersRule

use of org.mamute.dao.InvisibleForUsersRule in project mamute by caelum.

the class InvisibleForUsersRuleTest method should_not_add_filter_if_user_is_moderator.

@Test
public void should_not_add_filter_if_user_is_moderator() {
    LoggedUser user = new LoggedUser(user("leonardo", "leo@leo.com").asModerator(), null);
    InvisibleForUsersRule invisibleForUsersRule = new InvisibleForUsersRule(user);
    invisibleForUsersRule.addFilter("x", criteria);
    verify(criteria, never()).add(Mockito.any(Criterion.class));
}
Also used : Criterion(org.hibernate.criterion.Criterion) LoggedUser(org.mamute.model.LoggedUser) InvisibleForUsersRule(org.mamute.dao.InvisibleForUsersRule) Test(org.junit.Test)

Example 4 with InvisibleForUsersRule

use of org.mamute.dao.InvisibleForUsersRule in project mamute by caelum.

the class InvisibleForUsersRuleTest method should_add_filter_if_user_is_not_moderator.

@Test
public void should_add_filter_if_user_is_not_moderator() {
    LoggedUser user = new LoggedUser(user("leonardo", "leo@leo.com"), null);
    InvisibleForUsersRule invisibleForUsersRule = new InvisibleForUsersRule(user);
    invisibleForUsersRule.addFilter("x", criteria);
    verify(criteria, only()).add(Mockito.any(Criterion.class));
}
Also used : Criterion(org.hibernate.criterion.Criterion) LoggedUser(org.mamute.model.LoggedUser) InvisibleForUsersRule(org.mamute.dao.InvisibleForUsersRule) Test(org.junit.Test)

Example 5 with InvisibleForUsersRule

use of org.mamute.dao.InvisibleForUsersRule in project mamute by caelum.

the class WithUserPaginatedDAOTest method setup.

@Before
public void setup() {
    session.save(author);
    session.save(upVote);
    session.save(upVote2);
    session.save(upVote3);
    session.save(defaultTag);
    InvisibleForUsersRule invisibleFilter = new InvisibleForUsersRule(new LoggedUser(author, null));
    questionsWithUser = new WithUserPaginatedDAO<Question>(session, Question.class, UserRole.AUTHOR, invisibleFilter);
    answersWithUser = new WithUserPaginatedDAO<Answer>(session, Answer.class, UserRole.AUTHOR, invisibleFilter);
}
Also used : Answer(org.mamute.model.Answer) LoggedUser(org.mamute.model.LoggedUser) Question(org.mamute.model.Question) InvisibleForUsersRule(org.mamute.dao.InvisibleForUsersRule) Before(org.junit.Before)

Aggregations

InvisibleForUsersRule (org.mamute.dao.InvisibleForUsersRule)7 LoggedUser (org.mamute.model.LoggedUser)7 Criterion (org.hibernate.criterion.Criterion)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Tag (org.mamute.model.Tag)2 User (org.mamute.model.User)2 RetrieveKarmaDownvote (org.mamute.controllers.RetrieveKarmaDownvote)1 ReputationEventDAO (org.mamute.dao.ReputationEventDAO)1 VoteDAO (org.mamute.dao.VoteDAO)1 WatcherDAO (org.mamute.dao.WatcherDAO)1 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)1 Answer (org.mamute.model.Answer)1 Question (org.mamute.model.Question)1 MassiveVote (org.mamute.model.vote.MassiveVote)1 VotingMachine (org.mamute.model.vote.VotingMachine)1 KarmaCalculator (org.mamute.reputation.rules.KarmaCalculator)1