Search in sources :

Example 26 with LoggedUser

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

the class FlaggableDAOTest method setup.

@Before
public void setup() {
    flaggedInvisible.remove();
    addFlags(commentWithOneFlag, 1, author);
    addFlags(commentWithTwo, 2, author);
    addFlags(flaggedInvisible, 2, author);
    session.save(author);
    session.save(anyone);
    session.save(commentWithTwo);
    session.save(flaggedInvisible);
    session.save(commentWithOneFlag);
    session.save(java);
    session.save(question);
    session.flush();
    flaggables = new FlaggableDAO(session, meta);
    questions = new QuestionDAO(session, new InvisibleForUsersRule(new LoggedUser(anyone, null)));
    List<Class<? extends Flaggable>> moderatableTypes = new ArrayList<>();
    moderatableTypes.add(Question.class);
    moderatableTypes.add(Answer.class);
    moderatableTypes.add(Comment.class);
    moderatableTypes.add(News.class);
    when(meta.getFlaggableTypes()).thenReturn(moderatableTypes);
}
Also used : FlaggableDAO(org.mamute.dao.FlaggableDAO) Flaggable(org.mamute.model.interfaces.Flaggable) ArrayList(java.util.ArrayList) LoggedUser(org.mamute.model.LoggedUser) Before(org.junit.Before)

Example 27 with LoggedUser

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

the class InvisibleForUsersRuleTest method should_add_filter_if_user_is_not_logged_in.

@Test
public void should_add_filter_if_user_is_not_logged_in() {
    LoggedUser user = new LoggedUser(null, 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 28 with LoggedUser

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

the class QuestionDAOTest method setup.

@Before
public void setup() {
    author = user("Leonardo", "leo@leo");
    moderator = user("Leonardo", "leo@leo").asModerator();
    anyone = user("Leonardo", "leo@leo");
    session.save(author);
    session.save(moderator);
    session.save(anyone);
    session.save(java);
    session.save(defaultTag);
    this.questionsBeingAuthor = new QuestionDAO(session, new InvisibleForUsersRule(new LoggedUser(author, null)));
    this.questionsBeingModerator = new QuestionDAO(session, new InvisibleForUsersRule(new LoggedUser(moderator, null)));
    this.questionsForAnyone = new QuestionDAO(session, new InvisibleForUsersRule(new LoggedUser(anyone, null)));
}
Also used : LoggedUser(org.mamute.model.LoggedUser) Before(org.junit.Before)

Example 29 with LoggedUser

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

the class EditAnswerRuleTest method loggedUser_with_low_karma_should_not_be_allowed_to_edit.

@Test
public void loggedUser_with_low_karma_should_not_be_allowed_to_edit() throws IOException {
    LoggedUser other = loggedUser("other", "other@brutal.com", NOT_AUTHOR);
    ServletContext ctx = mock(ServletContext.class);
    EnvironmentKarma env = new EnvironmentKarma(new MamuteEnvironment(ctx));
    assertFalse(new EditAnswerRule(other, env).isAllowed(answer));
}
Also used : EnvironmentKarma(org.mamute.brutauth.auth.rules.EnvironmentKarma) MamuteEnvironment(org.mamute.vraptor.environment.MamuteEnvironment) EditAnswerRule(org.mamute.brutauth.auth.rules.EditAnswerRule) ServletContext(javax.servlet.ServletContext) LoggedUser(org.mamute.model.LoggedUser) Test(org.junit.Test)

Example 30 with LoggedUser

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

the class EditQuestionRuleTest method moderator_should_be_allowed_to_edit.

@Test
public void moderator_should_be_allowed_to_edit() throws IOException {
    LoggedUser moderator = loggedUser("moderator", "moderator@brutal.com", 2l);
    moderator.getCurrent().asModerator();
    ServletContext ctx = mock(ServletContext.class);
    EnvironmentKarma env = new EnvironmentKarma(new MamuteEnvironment(ctx));
    assertTrue(new EditQuestionRule(moderator, env).isAllowed(question));
}
Also used : EnvironmentKarma(org.mamute.brutauth.auth.rules.EnvironmentKarma) MamuteEnvironment(org.mamute.vraptor.environment.MamuteEnvironment) ServletContext(javax.servlet.ServletContext) EditQuestionRule(org.mamute.brutauth.auth.rules.EditQuestionRule) LoggedUser(org.mamute.model.LoggedUser) Test(org.junit.Test)

Aggregations

LoggedUser (org.mamute.model.LoggedUser)36 Test (org.junit.Test)24 Before (org.junit.Before)9 User (org.mamute.model.User)9 InvisibleForUsersRule (org.mamute.dao.InvisibleForUsersRule)7 ServletContext (javax.servlet.ServletContext)6 EnvironmentKarma (org.mamute.brutauth.auth.rules.EnvironmentKarma)6 MamuteEnvironment (org.mamute.vraptor.environment.MamuteEnvironment)6 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)4 Criterion (org.hibernate.criterion.Criterion)4 Answer (org.mamute.model.Answer)4 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)3 EditAnswerRule (org.mamute.brutauth.auth.rules.EditAnswerRule)3 EditQuestionRule (org.mamute.brutauth.auth.rules.EditQuestionRule)3 AnswerInformation (org.mamute.model.AnswerInformation)3 Comment (org.mamute.model.Comment)3 Question (org.mamute.model.Question)3 QuestionInformation (org.mamute.model.QuestionInformation)3 Tag (org.mamute.model.Tag)3 UpdateStatus (org.mamute.model.UpdateStatus)3