Search in sources :

Example 46 with Question

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

the class WithUserPaginatedDAOTest method should_return_only_questions_with_the_provided_user_ordered_by_date.

@Test
public void should_return_only_questions_with_the_provided_user_ordered_by_date() {
    DateTimeUtils.setCurrentMillisFixed(new DateTime().minusMonths(2).getMillis());
    Question javaEEQuestion = javaEEQuestion();
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeUtils.setCurrentMillisFixed(new DateTime().minusMonths(1).getMillis());
    Question androidQuestion = androidQuestion();
    DateTimeUtils.setCurrentMillisSystem();
    Question javaQuestion = javaQuestion();
    List<Question> perguntasDoAuthor = questionsWithUser.by(author, ByDate, 1);
    assertTrue(perguntasDoAuthor.contains(javaQuestion));
    assertTrue(perguntasDoAuthor.contains(javaEEQuestion));
    assertTrue(perguntasDoAuthor.contains(androidQuestion));
    assertEquals(javaQuestion, perguntasDoAuthor.get(0));
    assertEquals(androidQuestion, perguntasDoAuthor.get(1));
    assertEquals(javaEEQuestion, perguntasDoAuthor.get(2));
}
Also used : Question(org.mamute.model.Question) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 47 with Question

use of org.mamute.model.Question 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)

Example 48 with Question

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

the class WithUserPaginatedDAOTest method androidQuestion.

private Question androidQuestion() {
    Question q = question.withTitle("Some question about android and other stuff?").withDescription("Please help solving my question about android! Thanks, guys!").withAuthor(author).withTag(defaultTag).build();
    session.save(q);
    return q;
}
Also used : Question(org.mamute.model.Question)

Example 49 with Question

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

the class AttachmentRepositoryTest method should_detach_from_question.

@Test
public void should_detach_from_question() {
    final User author = user("question owner", "question@owner.local");
    session.save(author);
    final Attachment attachment = createAttachment("test");
    attachmentRepository.save(attachment);
    final Tag tag = tag("testtag");
    session.save(tag);
    final Question question = question(author, tag);
    question.getAttachments().add(attachment);
    session.save(question);
    attachmentRepository.delete(question.getAttachments());
    assertEquals(0, question.getAttachments().size());
}
Also used : User(org.mamute.model.User) Attachment(org.mamute.model.Attachment) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag) Test(org.junit.Test)

Example 50 with Question

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

the class AttachmentRepositoryTest method should_detach_from_answer.

@Test
public void should_detach_from_answer() {
    final User author = user("question owner", "question@owner.local");
    session.save(author);
    final Attachment attachment = createAttachment("test");
    attachmentRepository.save(attachment);
    final Tag tag = tag("testtag");
    session.save(tag);
    final Question question = question(author, tag);
    session.save(question);
    final Answer answer = answer("answer answer answer answer answer", question, author);
    answer.getAttachments().add(attachment);
    session.save(answer);
    attachmentRepository.delete(answer.getAttachments());
    assertEquals(0, answer.getAttachments().size());
}
Also used : Answer(org.mamute.model.Answer) User(org.mamute.model.User) Attachment(org.mamute.model.Attachment) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag) Test(org.junit.Test)

Aggregations

Question (org.mamute.model.Question)96 Test (org.junit.Test)74 User (org.mamute.model.User)28 Answer (org.mamute.model.Answer)24 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)15 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)15 Tag (org.mamute.model.Tag)9 ArrayList (java.util.ArrayList)8 QuestionBuilder (org.mamute.builder.QuestionBuilder)7 QuestionInformation (org.mamute.model.QuestionInformation)7 DateTime (org.joda.time.DateTime)6 LoggedUser (org.mamute.model.LoggedUser)5 QuestionInformationBuilder (org.mamute.model.QuestionInformationBuilder)5 Elements (org.jsoup.select.Elements)4 AnswerAndVotes (org.mamute.model.AnswerAndVotes)4 Comment (org.mamute.model.Comment)4 Get (br.com.caelum.vraptor.Get)3 Before (org.junit.Before)3 DaoManager (org.mamute.integration.util.DaoManager)3 AnswerInformation (org.mamute.model.AnswerInformation)3