Search in sources :

Example 86 with Question

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

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

the class AnswerQuestionTest method should_not_display_answer_form_when_not_logged_in.

@Test
public void should_not_display_answer_form_when_not_logged_in() {
    Question question = createQuestionWithDao(moderator(), "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
    UserFlow navigation = goToQuestionPage(navigate(), question);
    VRaptorTestResult questionPage = navigation.followRedirect().execute();
    questionPage.wasStatus(200).isValid();
    Elements answerForm = getElementsByClass(questionPage.getResponseBody(), "answer-form");
    assertTrue(answerForm.isEmpty());
}
Also used : UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) Question(org.mamute.model.Question) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 88 with Question

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

the class EditQuestionTest method should_edit_and_automatically_approve_moderator.

@Test
public void should_edit_and_automatically_approve_moderator() throws Exception {
    Question question = createQuestionWithDao(karmaNigga(), "Title title title title title title title", "Description description description description description", tag("java"));
    String newTitle = "NEW title title title title title title title";
    String newDescription = "NEW description description description description description";
    UserFlow navigation = login(navigate(), moderator().getEmail());
    navigation = editQuestionWithFlow(navigation, question, newTitle, newDescription, "edited question woots!", "java");
    VRaptorTestResult editedQuestion = navigation.followRedirect().execute();
    editedQuestion.wasStatus(200).isValid();
    List<String> messagesList = messagesList(editedQuestion);
    assertTrue(messagesList.contains(message("status.no_need_to_approve")));
    Question fetchQuestion = editedQuestion.getObject("question");
    assertEquals(newTitle, fetchQuestion.getTitle());
    assertEquals(newDescription, fetchQuestion.getDescription());
}
Also used : 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 89 with Question

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

the class ListTest method should_list_unsolved_questions.

@Test
public void should_list_unsolved_questions() {
    UserFlow navigation = unsolvedQuestions();
    VRaptorTestResult unsolved = navigation.execute();
    unsolved.wasStatus(200).isValid();
    List<Question> questions = unsolved.getObject("questions");
    boolean onlyUnsolved = true;
    for (Question q : questions) {
        if (q.getAnswersCount() != 0) {
            onlyUnsolved = false;
            break;
        }
    }
    assertTrue(onlyUnsolved);
}
Also used : 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 90 with Question

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

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