Search in sources :

Example 41 with User

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

the class RemoveAnythingFlaggedByModeratorTest method should_not_handle_normal_user.

@Test
public void should_not_handle_normal_user() throws Exception {
    User normal = user("normal", "normal@brutal.com");
    RemoveAnythingFlaggedByModerator removeFlaggedByModerator = new RemoveAnythingFlaggedByModerator(new LoggedUser(normal, null));
    Comment comment = comment(author, "blablablablba");
    assertFalse(removeFlaggedByModerator.shouldHandle(comment));
    assertTrue(comment.isVisible());
}
Also used : Comment(org.mamute.model.Comment) User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) LoggedUser(org.mamute.model.LoggedUser) RemoveAnythingFlaggedByModerator(org.mamute.model.flag.RemoveAnythingFlaggedByModerator) Test(org.junit.Test)

Example 42 with User

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

the class RssFeedFactoryTest method should_generate_feed.

@Test
public void should_generate_feed() throws IOException {
    DefaultEnvironment env = new DefaultEnvironment(new EnvironmentType("mamute"));
    QuestionRssEntryFactory factory = new QuestionRssEntryFactory(env);
    RssFeedFactory rssFeedFactory = new RssFeedFactory(env, factory);
    QuestionBuilder builder = new QuestionBuilder();
    DateTimeUtils.setCurrentMillisFixed(100);
    User user1 = user("author1", "author@email");
    user1.setPhotoUri(new URL("http://imagemsuser1.com"));
    Question question1 = builder.withAuthor(user1).withTitle("first question").withDescription("question").withId(1l).build();
    User user2 = user("author2", "author@email");
    user2.setPhotoUri(new URL("http://imagemsuser2.com"));
    Question question2 = builder.withId(2l).withTitle("second question").withAuthor(user2).build();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    rssFeedFactory.build(Arrays.<RssContent>asList(question1, question2), output, "title", "description");
    output.close();
    String xml = new String(output.toByteArray());
    assertTrue(xml.contains("first question"));
    assertTrue(xml.contains("second question"));
    assertTrue(xml.contains("http://imagemsuser1.com"));
    assertTrue(xml.contains("http://imagemsuser2.com"));
    DateTimeUtils.setCurrentMillisSystem();
}
Also used : DefaultEnvironment(br.com.caelum.vraptor.environment.DefaultEnvironment) EnvironmentType(br.com.caelum.vraptor.environment.EnvironmentType) User(org.mamute.model.User) RssFeedFactory(org.mamute.infra.rss.write.RssFeedFactory) QuestionBuilder(org.mamute.builder.QuestionBuilder) Question(org.mamute.model.Question) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QuestionRssEntryFactory(org.mamute.infra.rss.write.QuestionRssEntryFactory) URL(java.net.URL) Test(org.junit.Test)

Example 43 with User

use of org.mamute.model.User 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 44 with User

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

the class NotificationMailer method buildEmail.

public Email buildEmail(NotificationMail notificationMail) {
    DateTimeFormatter dateFormat = forPattern("MMM, dd").withLocale(new Locale("pt", "br"));
    EmailAction action = notificationMail.getAction();
    User to = notificationMail.getTo();
    Email email = templates.template(notificationMail.getEmailTemplate(), bundle.getMessage("site.name"), action.getMainThread().getTitle()).with("emailAction", action).with("dateFormat", dateFormat).with("sanitizer", POLICY).with("bundle", bundle).with("watcher", to).with("linkerHelper", new LinkToHelper(router, brutalEnv)).with("logoUrl", env.get("mail_logo_url")).to(to.getName(), to.getEmail());
    return email;
}
Also used : Locale(java.util.Locale) User(org.mamute.model.User) Email(org.apache.commons.mail.Email) EmailAction(org.mamute.mail.action.EmailAction) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 45 with User

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

the class VotingMachine method unRegister.

public void unRegister(Votable votable, Vote current, Class<?> votableType) {
    User voter = current.getAuthor();
    User votableAuthor = votable.getAuthor();
    ReputationEventContext eventContext = votes.contextOf(votable);
    if (votable.getAuthor().getId().equals(voter.getId())) {
        throw new IllegalArgumentException("an author can't unvote its own votable since it can't even vote on it");
    }
    Vote previous = votes.previousVoteFor(votable.getId(), voter, votableType);
    boolean shouldCountKarma = voteChecker.shouldCountKarma(voter, votableAuthor, current);
    /* O previous vai sempre existir nessa caso !! ( o ideal :]  ) */
    if (previous != null) {
        ReputationEvent receivedVote = new ReceivedVoteEvent(previous.getType(), votable, eventContext, shouldCountKarma).reputationEvent();
        votableAuthor.descreaseKarma(karmaCalculator.karmaFor(receivedVote));
        ReputationEvent votedAtSomething = new VotedAtSomethingEvent(previous, eventContext).reputationEvent();
        voter.descreaseKarma(karmaCalculator.karmaFor(votedAtSomething));
        reputationEvents.delete(receivedVote);
        reputationEvents.delete(votedAtSomething);
        votable.remove(previous);
    }
// ReputationEvent receivedVote = new ReceivedVoteEvent(current.getType(), votable, eventContext, shouldCountKarma).reputationEvent();
// votableAuthor.increaseKarma(karmaCalculator.karmaFor(receivedVote));
// ReputationEvent votedAtSomething = new VotedAtSomethingEvent(current, eventContext).reputationEvent();
// voter.increaseKarma(karmaCalculator.karmaFor(votedAtSomething));
// reputationEvents.save(receivedVote);
// reputationEvents.save(votedAtSomething);
// if (votable.getVoteCount() <= -5) {
// votable.getQuestion().remove();
// retrieveDownvote.retrieveKarma(votable.getVotes());
// }
}
Also used : Vote(org.mamute.model.Vote) User(org.mamute.model.User) ReceivedVoteEvent(org.mamute.reputation.rules.ReceivedVoteEvent) VotedAtSomethingEvent(org.mamute.reputation.rules.VotedAtSomethingEvent) ReputationEventContext(org.mamute.model.ReputationEventContext) ReputationEvent(org.mamute.model.ReputationEvent)

Aggregations

User (org.mamute.model.User)97 Test (org.junit.Test)56 Question (org.mamute.model.Question)28 LoggedUser (org.mamute.model.LoggedUser)25 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)9 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)9 Answer (org.mamute.model.Answer)9 LoginMethod (org.mamute.model.LoginMethod)9 Post (br.com.caelum.vraptor.Post)7 Before (org.junit.Before)7 Tag (org.mamute.model.Tag)7 QuestionInformation (org.mamute.model.QuestionInformation)6 Email (org.apache.commons.mail.Email)5 UserPersonalInfo (org.mamute.dto.UserPersonalInfo)5 ReputationEvent (org.mamute.model.ReputationEvent)5 ArrayList (java.util.ArrayList)4 Watcher (org.mamute.model.watch.Watcher)4 DateTime (org.joda.time.DateTime)3 Elements (org.jsoup.select.Elements)3 DaoManager (org.mamute.integration.util.DaoManager)3