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());
}
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));
}
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());
}
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());
}
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());
}
Aggregations