Search in sources :

Example 91 with Question

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

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

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

the class DaoManager method createQuestion.

public Question createQuestion(User author, String title, String description, Tag... tags) {
    this.session.beginTransaction();
    Question question = new QuestionBuilder().withTitle(title).withDescription(description).withTags(Arrays.asList(tags)).withAuthor(author).build();
    this.questionDao.save(question);
    this.session.getTransaction().commit();
    return question;
}
Also used : QuestionBuilder(org.mamute.builder.QuestionBuilder) Question(org.mamute.model.Question)

Example 94 with Question

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

the class ListTest method should_list_by_tag.

@Test
public void should_list_by_tag() {
    String tag = "java";
    UserFlow navigation = tagList(tag);
    VRaptorTestResult tagList = navigation.execute();
    tagList.wasStatus(200).isValid();
    List<Question> questions = tagList.getObject("questions");
    boolean onlyTag = true;
    for (Question q : questions) {
        if (!q.getTagsAsString(" ").contains(tag)) {
            onlyTag = false;
            break;
        }
    }
    assertTrue(onlyTag);
}
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 95 with Question

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

the class ListTest method should_not_show_questions_with_too_low_reputation.

@Test
public void should_not_show_questions_with_too_low_reputation() {
    UserFlow navigation = home();
    VRaptorTestResult home = navigation.execute();
    home.wasStatus(200).isInvalid();
    List<Question> questions = home.getObject("questions");
    boolean showLowReputation = false;
    for (Question q : questions) {
        if (q.getVoteCount() <= QuestionDAO.SPAM_BOUNDARY) {
            showLowReputation = true;
            break;
        }
    }
    assertFalse(showLowReputation);
}
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)

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