Search in sources :

Example 16 with LoggedUser

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

the class EditAnswerRuleTest method moderator_should_be_allowed_to_edit.

@Test
public void moderator_should_be_allowed_to_edit() throws IOException {
    LoggedUser loggedUser = loggedUser("moderator", "moderator@brutal.com", NOT_AUTHOR);
    loggedUser.getCurrent().asModerator();
    ServletContext ctx = mock(ServletContext.class);
    EnvironmentKarma env = new EnvironmentKarma(new MamuteEnvironment(ctx));
    assertTrue(new EditAnswerRule(loggedUser, 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 17 with LoggedUser

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

the class EditQuestionRuleTest method user_with_low_karma_should_not_be_allowed_to_edit.

@Test
public void user_with_low_karma_should_not_be_allowed_to_edit() throws IOException {
    LoggedUser other = loggedUser("other", "other@brutal.com", 3l);
    ServletContext ctx = mock(ServletContext.class);
    EnvironmentKarma env = new EnvironmentKarma(new MamuteEnvironment(ctx));
    assertFalse(new EditQuestionRule(other, 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)

Example 18 with LoggedUser

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

the class NewsBuilder method build.

public News build() {
    if (loggedUser == null) {
        loggedUser = new LoggedUser(author, null);
    }
    NewsInformation newsInformation = new NewsInformation(title, description, loggedUser, comment);
    News news = new News(newsInformation, author);
    setId(news, id);
    return news;
}
Also used : News(org.mamute.model.News) NewsInformation(org.mamute.model.NewsInformation) LoggedUser(org.mamute.model.LoggedUser)

Example 19 with LoggedUser

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

the class BrutalAdsTest method should_return_true_if_user_have_less_then_50_karma.

@Test
public void should_return_true_if_user_have_less_then_50_karma() {
    User user = user("Leo", "leo@leo.com");
    user.increaseKarma(20);
    LoggedUser loggedUser = new LoggedUser(user, null);
    BrutalAds brutalAds = new BrutalAds(loggedUser);
    assertTrue(brutalAds.shouldShowAds());
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) BrutalAds(org.mamute.ads.BrutalAds) LoggedUser(org.mamute.model.LoggedUser) Test(org.junit.Test)

Example 20 with LoggedUser

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

the class AuthTest method should_log_in.

@Test
public void should_log_in() {
    User user = randomUser();
    UserFlow navigation = login(navigate(), user.getEmail());
    VRaptorTestResult loginResult = navigation.followRedirect().execute();
    loginResult.wasStatus(200).isValid();
    LoggedUser loggedUser = loginResult.getObject("currentUser");
    User currentUser = loggedUser.getCurrent();
    assertThat(currentUser.getId(), equalTo(user.getId()));
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) LoggedUser(org.mamute.model.LoggedUser) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) 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