Search in sources :

Example 6 with User

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

use of org.mamute.model.User 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 8 with User

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

Example 9 with User

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

the class EditQuestionTest method should_edit_and_automatically_approve_author_edit.

@Test
public void should_edit_and_automatically_approve_author_edit() throws Exception {
    User karmaNigga = karmaNigga();
    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(), karmaNigga.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 : 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 10 with User

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

the class SignupController method signup.

@Post
public void signup(String email, String password, SanitizedText name, String passwordConfirmation) {
    checkSignup();
    User newUser = new User(name, email);
    LoginMethod brutalLogin = LoginMethod.brutalLogin(newUser, email, password);
    newUser.add(brutalLogin);
    validator.validate(newUser, password, passwordConfirmation);
    result.include("email", email);
    result.include("name", name);
    validator.onErrorRedirectTo(this).signupForm();
    users.save(newUser);
    loginMethods.save(brutalLogin);
    result.include("mamuteMessages", asList(messageFactory.build("confirmation", "signup.confirmation")));
    linker.linkTo(ListController.class).home(null);
    result.forwardTo(AuthController.class).login(email, password, linker.get());
}
Also used : User(org.mamute.model.User) LoginMethod(org.mamute.model.LoginMethod) Post(br.com.caelum.vraptor.Post)

Aggregations

User (org.mamute.model.User)97 Test (org.junit.Test)56 Question (org.mamute.model.Question)28 LoggedUser (org.mamute.model.LoggedUser)25 VRaptorTestResult (br.com.caelum.vraptor.test.VRaptorTestResult)9 UserFlow (br.com.caelum.vraptor.test.requestflow.UserFlow)9 Answer (org.mamute.model.Answer)9 LoginMethod (org.mamute.model.LoginMethod)9 Post (br.com.caelum.vraptor.Post)7 Before (org.junit.Before)7 Tag (org.mamute.model.Tag)7 QuestionInformation (org.mamute.model.QuestionInformation)6 Email (org.apache.commons.mail.Email)5 UserPersonalInfo (org.mamute.dto.UserPersonalInfo)5 ReputationEvent (org.mamute.model.ReputationEvent)5 ArrayList (java.util.ArrayList)4 Watcher (org.mamute.model.watch.Watcher)4 DateTime (org.joda.time.DateTime)3 Elements (org.jsoup.select.Elements)3 DaoManager (org.mamute.integration.util.DaoManager)3