Search in sources :

Example 16 with VRaptorTestResult

use of br.com.caelum.vraptor.test.VRaptorTestResult in project mamute by caelum.

the class AuthTest method should_log_in.

@Test
public void should_log_in() {
    User user = randomUser();
    UserFlow navigation = login(navigate(), user.getEmail());
    VRaptorTestResult loginResult = navigation.followRedirect().execute();
    loginResult.wasStatus(200).isValid();
    LoggedUser loggedUser = loginResult.getObject("currentUser");
    User currentUser = loggedUser.getCurrent();
    assertThat(currentUser.getId(), equalTo(user.getId()));
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser) UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) LoggedUser(org.mamute.model.LoggedUser) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Test(org.junit.Test)

Example 17 with VRaptorTestResult

use of br.com.caelum.vraptor.test.VRaptorTestResult 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 18 with VRaptorTestResult

use of br.com.caelum.vraptor.test.VRaptorTestResult 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 19 with VRaptorTestResult

use of br.com.caelum.vraptor.test.VRaptorTestResult 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 20 with VRaptorTestResult

use of br.com.caelum.vraptor.test.VRaptorTestResult 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)

Aggregations

VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)28 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)27 Test (org.junit.Test)27 Question (org.mamute.model.Question)15 User (org.mamute.model.User)9 Elements (org.jsoup.select.Elements)5 Answer (org.mamute.model.Answer)5 LoggedUser (org.mamute.model.LoggedUser)4 ArrayList (java.util.ArrayList)3 AnswerAndVotes (org.mamute.model.AnswerAndVotes)3 DaoManager (org.mamute.integration.util.DaoManager)1 Tag (org.mamute.model.Tag)1