Search in sources :

Example 1 with AnswerAndVotes

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

the class VoteDAO method previousVotesForAnswers.

@SuppressWarnings("unchecked")
public AnswerAndVotes previousVotesForAnswers(Question question, User currentUser) {
    Query query = session.createQuery("select a,v from Answer as a join a.votes as v where v.author = :author and a.question = :question");
    query.setParameter("author", currentUser);
    query.setParameter("question", question);
    return new AnswerAndVotes(question, question.getAnswers(), query.list());
}
Also used : Query(org.hibernate.Query) AnswerAndVotes(org.mamute.model.AnswerAndVotes)

Example 2 with AnswerAndVotes

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

the class AnswerAndVotesTest method should_fill_value_with_null_only_answers_that_has_no_currentUserVote.

@Test
public void should_fill_value_with_null_only_answers_that_has_no_currentUserVote() {
    Question q = question.build();
    Object[] first = new Object[] { answerFor(q, 1), mock(Vote.class) };
    Object[] second = new Object[] { answerFor(q, 2), mock(Vote.class) };
    Answer third = answerFor(q, 3);
    List<Object[]> voteList = new ArrayList<>();
    voteList.add(first);
    voteList.add(second);
    List<Answer> answers = new ArrayList<>();
    answers.add((Answer) first[0]);
    answers.add((Answer) second[0]);
    answers.add(third);
    AnswerAndVotes votes = new AnswerAndVotes(q, answers, voteList);
    Map<Answer, Vote> map = votes.getVotes();
    assertEquals(first[1], map.get(first[0]));
    assertEquals(second[1], map.get(second[0]));
    assertEquals(null, map.get(third));
    assertTrue(map.containsKey(third));
}
Also used : Answer(org.mamute.model.Answer) Vote(org.mamute.model.Vote) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) AnswerAndVotes(org.mamute.model.AnswerAndVotes) Test(org.junit.Test)

Example 3 with AnswerAndVotes

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

the class AnswerQuestionTest method should_answer_when_logged_in.

@Test
public void should_answer_when_logged_in() {
    Question question = createQuestionWithDao(moderator(), "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
    String description = "Resposta da questao do teste de edicao";
    UserFlow navigation = login(navigate(), karmaNigga().getEmail());
    navigation = answerQuestionWithFlow(navigation, question, description, false);
    VRaptorTestResult questionAnswered = navigation.followRedirect().execute();
    questionAnswered.wasStatus(200).isValid();
    AnswerAndVotes answerAndVotes = questionAnswered.getObject("answers");
    List<Answer> answers = new ArrayList<Answer>(answerAndVotes.getVotes().keySet());
    Assert.assertEquals(description, answers.get(0).getDescription());
}
Also used : Answer(org.mamute.model.Answer) 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 4 with AnswerAndVotes

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

the class EditAnswerTest method should_edit_and_automatically_approve_moderator.

@Test
public void should_edit_and_automatically_approve_moderator() throws Exception {
    User moderator = moderator();
    Question question = createQuestionWithDao(moderator, "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
    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(), moderator.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 5 with AnswerAndVotes

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

Aggregations

AnswerAndVotes (org.mamute.model.AnswerAndVotes)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Answer (org.mamute.model.Answer)4 Question (org.mamute.model.Question)4 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)3 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)3 User (org.mamute.model.User)2 Query (org.hibernate.Query)1 Vote (org.mamute.model.Vote)1