Search in sources :

Example 1 with QuestionBuilder

use of org.mamute.builder.QuestionBuilder in project mamute by caelum.

the class PostViewCounterTest method should_increase_count_only_first_time.

@Test
public void should_increase_count_only_first_time() {
    Question question = new QuestionBuilder().withId(1l).build();
    questionViewCounter.ping(question);
    mockQuestionVisited(question);
    assertEquals(1l, question.getViews());
    questionViewCounter.ping(question);
    assertEquals(1l, question.getViews());
}
Also used : QuestionBuilder(org.mamute.builder.QuestionBuilder) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 2 with QuestionBuilder

use of org.mamute.builder.QuestionBuilder in project mamute by caelum.

the class PostViewCounterTest method should_increase_count_only_the_news_counter.

@Test
public void should_increase_count_only_the_news_counter() {
    Question question = new QuestionBuilder().withId(1l).build();
    News news = new NewsBuilder().withId(1l).build();
    questionViewCounter.ping(question);
    mockQuestionVisited(question);
    questionViewCounter.ping(news);
    assertEquals(1l, question.getViews());
    assertEquals(1l, news.getViews());
}
Also used : NewsBuilder(org.mamute.builder.NewsBuilder) QuestionBuilder(org.mamute.builder.QuestionBuilder) News(org.mamute.model.News) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 3 with QuestionBuilder

use of org.mamute.builder.QuestionBuilder 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 4 with QuestionBuilder

use of org.mamute.builder.QuestionBuilder in project mamute by caelum.

the class DaoManager method createQuestion.

public Question createQuestion(User author, String title, String description, Tag... tags) {
    this.session.beginTransaction();
    Question question = new QuestionBuilder().withTitle(title).withDescription(description).withTags(Arrays.asList(tags)).withAuthor(author).build();
    this.questionDao.save(question);
    this.session.getTransaction().commit();
    return question;
}
Also used : QuestionBuilder(org.mamute.builder.QuestionBuilder) Question(org.mamute.model.Question)

Example 5 with QuestionBuilder

use of org.mamute.builder.QuestionBuilder in project mamute by caelum.

the class TagDAOTest method questionWith.

private Question questionWith(List<Tag> tags, User leo) {
    Question question = new QuestionBuilder().withAuthor(leo).withTags(tags).build();
    session.save(question);
    return question;
}
Also used : QuestionBuilder(org.mamute.builder.QuestionBuilder)

Aggregations

QuestionBuilder (org.mamute.builder.QuestionBuilder)11 Question (org.mamute.model.Question)7 Test (org.junit.Test)5 Before (org.junit.Before)3 DefaultEnvironment (br.com.caelum.vraptor.environment.DefaultEnvironment)2 EnvironmentType (br.com.caelum.vraptor.environment.EnvironmentType)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 QuestionRssEntryFactory (org.mamute.infra.rss.write.QuestionRssEntryFactory)2 User (org.mamute.model.User)2 URL (java.net.URL)1 AuthorRule (org.mamute.auth.rules.AuthorRule)1 NewsBuilder (org.mamute.builder.NewsBuilder)1 RssFeedFactory (org.mamute.infra.rss.write.RssFeedFactory)1 News (org.mamute.model.News)1 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)1 Moderatable (org.mamute.model.interfaces.Moderatable)1