Search in sources :

Example 16 with Answer

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

the class AnswerTest method return_true_if_answer_has_pending_edits.

@Test
public void return_true_if_answer_has_pending_edits() throws Exception {
    Question myQuestion = question.withTitle("question title").withDescription("description").withAuthor(author).build();
    Answer answer = answer("blablablab", myQuestion, author);
    assertFalse(answer.hasPendingEdits());
    AnswerInformation approved = new AnswerInformation(notMarked("blablabalblab"), new LoggedUser(editUser, null), answer, "");
    answer.enqueueChange(approved, PENDING);
    assertTrue(answer.hasPendingEdits());
}
Also used : Answer(org.mamute.model.Answer) Question(org.mamute.model.Question) LoggedUser(org.mamute.model.LoggedUser) AnswerInformation(org.mamute.model.AnswerInformation) Test(org.junit.Test)

Example 17 with Answer

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

the class SolrQuestionIndex method toDoc.

private SolrInputDocument toDoc(Question q) {
    List<String> tagNames = Lists.transform(q.getTags(), new Function<Tag, String>() {

        @Nullable
        @Override
        public String apply(@Nullable Tag tag) {
            return tag.getName();
        }
    });
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", q.getId());
    doc.addField("title", q.getTitle());
    doc.addField("description", q.getMarkedDescription());
    doc.addField("tags", join(tagNames));
    String solution = null;
    List<String> answers = new ArrayList<>();
    for (Answer a : q.getAnswers()) {
        if (a.isSolution()) {
            solution = a.getDescription();
        } else {
            answers.add(a.getDescription());
        }
    }
    if (solution != null) {
        doc.addField("solution", solution);
    }
    if (answers.size() > 0) {
        doc.addField("answers", join(answers));
    }
    return doc;
}
Also used : Answer(org.mamute.model.Answer) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) Tag(org.mamute.model.Tag) Nullable(javax.annotation.Nullable)

Example 18 with Answer

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

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

the class EditAnswerTest method should_edit_answer_of_other_author.

@Test
public void should_edit_answer_of_other_author() throws Exception {
    User moderator = moderator();
    Question question = createQuestionWithDao(moderator, "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
    Answer answer = answerQuestionWithDao(moderator, 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.pending")));
}
Also used : Answer(org.mamute.model.Answer) User(org.mamute.model.User) UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) Question(org.mamute.model.Question) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Test(org.junit.Test)

Example 20 with Answer

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

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