Search in sources :

Example 1 with VRaptorTestResult

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

the class AuthTest method should_not_log_in_with_invalid_user.

@Test
public void should_not_log_in_with_invalid_user() {
    UserFlow navigation = login(navigate(), "invalidEmail");
    VRaptorTestResult loginResult = navigation.followRedirect().execute();
    loginResult.wasStatus(200).isValid();
    LoggedUser loggedUser = loginResult.getObject("currentUser");
    User currentUser = loggedUser.getCurrent();
    assertThat(currentUser, equalTo(User.GHOST));
}
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 2 with VRaptorTestResult

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

the class AuthTest method should_save_url_when_redirected_to_login.

@Test
public void should_save_url_when_redirected_to_login() {
    UserFlow navigation = createQuestionPage(navigate());
    VRaptorTestResult navigationResult = navigation.followRedirect().execute();
    navigationResult.wasStatus(200).isValid();
    Elements redirectInput = getElementsByAttributeAndValue(navigationResult, "name", "redirectUrl");
    String redirectUrl = redirectInput.first().attr("value");
    String expectedUrl = rootPath(navigationResult).concat("/perguntar");
    assertThat(redirectUrl, equalTo(expectedUrl));
}
Also used : UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 3 with VRaptorTestResult

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

the class CommentAnswerTest method should_comment_answer_after_login.

@Test
public void should_comment_answer_after_login() throws Exception {
    User moderator = moderator();
    Question question = createQuestionWithDao(moderator, "Should comment answer after login", "Yeah, definitely should, who're you to say otherwise?", tag("java"));
    Answer answer = answerQuestionWithDao(karmaNigga(), question, "I'm de guy with lots of karma, nigga! So get over here!", false);
    String comment = "Oh, right, then I can't do a thing about it.";
    UserFlow navigation = login(navigate(), moderator.getEmail());
    navigation = commentWithFlow(navigation, answer, comment, false);
    VRaptorTestResult commentResult = navigation.followRedirect().execute();
    // COULD NOT COMPILE JSP
    commentResult.wasStatus(200).isValid();
    navigation = login(navigate(), moderator.getEmail());
    navigation = goToQuestionPage(navigation, question);
    VRaptorTestResult commentedAnswer = navigation.followRedirect().execute();
    commentedAnswer.wasStatus(200).isValid();
    Elements commentElement = getElementsByClass(commentedAnswer.getResponseBody(), "comment-container");
    Elements commentSpan = getElementsByTag(commentElement.html(), "span");
    Elements commentParagraph = getElementsByTag(commentSpan.html(), "p");
    assertEquals(comment, commentParagraph.html());
}
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) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 4 with VRaptorTestResult

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

the class CreateQuestionTest method should_make_a_question.

@Test
public void should_make_a_question() {
    String title = "My new question about java";
    String description = "just a question that i have about java hahahhaha";
    Tag tag = tag("java");
    UserFlow navigation = login(navigate(), karmaNigga().getEmail());
    navigation = createQuestionWithFlow(navigation, title, description, tag.getName(), false);
    VRaptorTestResult createdQuestion = navigation.followRedirect().execute();
    createdQuestion.wasStatus(200).isValid();
    Question question = createdQuestion.getObject("question");
    Tag questionTag = question.getTags().get(0);
    assertThat(question.getTitle(), equalTo(title));
    assertThat(question.getDescription(), equalTo(description));
    assertThat(questionTag.getName(), equalTo(tag.getName()));
}
Also used : UserFlow(br.com.caelum.vraptor.test.requestflow.UserFlow) Question(org.mamute.model.Question) Tag(org.mamute.model.Tag) VRaptorTestResult(br.com.caelum.vraptor.test.VRaptorTestResult) Test(org.junit.Test)

Example 5 with VRaptorTestResult

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

the class EditQuestionTest method should_touch_question.

@Test
public void should_touch_question() throws Exception {
    User user = new DaoManager().randomUser();
    Question question = createQuestionWithDao(user(user.getEmail()), "Question question question question question", "Description description description description description", tag("java"));
    UserFlow navigation = login(navigate(), user.getEmail());
    navigation = editQuestionWithFlow(navigation, question, "ASdoA sodi aosido iasod iOASIDoIASOdi", "asd oiasudo iausdoi uasoid uaosiduasoduoasi udaiosud oiasud oiasud oisa", "so diaos diaosi d", "java");
    VRaptorTestResult editedQuestion = navigation.followRedirect().execute();
    editedQuestion.wasStatus(200).isValid();
    Elements questionElements = getElementsByClass(editedQuestion.getResponseBody(), "edited-touch");
    Elements touchImage = getElementsByTag(questionElements.html(), "img");
    assertTrue(touchImage.isEmpty());
    navigation = login(navigate(), moderator().getEmail());
    navigation = editQuestionWithFlow(navigation, question, "Question question question question question", "Description description description description description", "new comment", "java");
    editedQuestion = navigation.followRedirect().execute();
    editedQuestion.wasStatus(200).isValid();
    questionElements = getElementsByClass(editedQuestion.getResponseBody(), "edited-touch");
    touchImage = getElementsByTag(questionElements.html(), "img");
    assertFalse(touchImage.isEmpty());
}
Also used : 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) Elements(org.jsoup.select.Elements) DaoManager(org.mamute.integration.util.DaoManager) 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