Search in sources :

Example 21 with Answer

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

the class EditAnswerTest method should_edit_and_automatically_approve_author_edit.

@Test
public void should_edit_and_automatically_approve_author_edit() throws Exception {
    Question question = createQuestionWithDao(moderator(), "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
    User karmaNigga = karmaNigga();
    Answer answer = answerQuestionWithDao(karmaNigga, question, "Resposta da questao do teste de edicao", false);
    String newDescription = "my new description of the first answer";
    UserFlow navigation = login(navigate(), karmaNigga.getEmail());
    navigation = editAnswerWithFlow(navigation, answer, newDescription, "comment");
    VRaptorTestResult answerEdited = navigation.followRedirect().execute();
    answerEdited.wasStatus(200).isValid();
    List<String> messagesList = messagesList(answerEdited);
    assertTrue(messagesList.contains(message("status.no_need_to_approve")));
    AnswerAndVotes answerAndVotes = answerEdited.getObject("answers");
    List<Answer> answers = new ArrayList<Answer>(answerAndVotes.getVotes().keySet());
    assertEquals(newDescription, answers.get(0).getDescription());
}
Also used : Answer(org.mamute.model.Answer) User(org.mamute.model.User) UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) AnswerAndVotes(org.mamute.model.AnswerAndVotes) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Test(org.junit.Test)

Example 22 with Answer

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

the class DaoManager method answerQuestion.

public Answer answerQuestion(User author, Question question, String description, boolean watching) {
    this.session.beginTransaction();
    LoggedUser loggedUser = new LoggedUser(author, null);
    AnswerInformation information = new AnswerInformation(notMarked(description), loggedUser, "new answer");
    Answer answer = new Answer(information, question, author);
    this.answerDao.save(answer);
    this.session.getTransaction().commit();
    return answer;
}
Also used : Answer(org.mamute.model.Answer) LoggedUser(org.mamute.model.LoggedUser) AnswerInformation(org.mamute.model.AnswerInformation)

Example 23 with Answer

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

the class VoteDAOTest method should_find_question_from_votable.

@Test
public void should_find_question_from_votable() throws Exception {
    Question question = question(currentUser, tags);
    Answer answer = answer("answer answer answer answer answer", question, currentUser);
    Comment comment = comment(currentUser, "blabla blabla blabla blabla blabla blabla");
    question.add(comment);
    session.save(question);
    session.save(answer);
    session.save(comment);
    assertEquals(question, votes.contextOf(question));
    assertEquals(question, votes.contextOf(answer));
    assertEquals(question, votes.contextOf(comment));
}
Also used : Answer(org.mamute.model.Answer) Comment(org.mamute.model.Comment) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 24 with Answer

use of org.mamute.model.Answer 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 25 with Answer

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

Answer (org.mamute.model.Answer)31 Test (org.junit.Test)27 Question (org.mamute.model.Question)24 User (org.mamute.model.User)9 ArrayList (java.util.ArrayList)6 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)5 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)5 LoggedUser (org.mamute.model.LoggedUser)5 AnswerAndVotes (org.mamute.model.AnswerAndVotes)4 AnswerInformation (org.mamute.model.AnswerInformation)4 Comment (org.mamute.model.Comment)3 Tag (org.mamute.model.Tag)3 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)2 Information (org.mamute.model.Information)2 Vote (org.mamute.model.Vote)2 CustomBrutauthRules (br.com.caelum.brutauth.auth.annotations.CustomBrutauthRules)1 Get (br.com.caelum.vraptor.Get)1 Nullable (javax.annotation.Nullable)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 DateTime (org.joda.time.DateTime)1