Search in sources :

Example 46 with User

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

the class UserLogger method logUser.

public void logUser(@Observes MethodReady methodReady) {
    String userName = "anonymous";
    if (loggedUser.isLoggedIn()) {
        User user = loggedUser.getCurrent();
        String name = user.getName();
        String id = user.getId().toString();
        userName = format("%s (id=%s)", name, id);
    }
    String realIp = clientIp.get();
    String uri = request.getRequestURI();
    String method = getMethod();
    String log = format("%s -> %s from %s %s", method, uri, userName, realIp);
    LOG.info(log);
}
Also used : User(org.mamute.model.User) LoggedUser(org.mamute.model.LoggedUser)

Example 47 with User

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

the class AnswerQuestionTest method should_not_display_answer_form_when_already_answered.

@Test
public void should_not_display_answer_form_when_already_answered() {
    Question question = createQuestionWithDao(moderator(), "Titulo da questao hahaha", "Descricao da questao longa demais", tag("java"));
    User karmaNigga = karmaNigga();
    answerQuestionWithDao(karmaNigga, question, "Resposta da questao do teste de edicao", false);
    UserFlow navigation = login(navigate(), karmaNigga.getEmail());
    navigation = goToQuestionPage(navigation, question);
    VRaptorTestResult questionPage = navigation.followRedirect().execute();
    questionPage.wasStatus(200).isValid();
    Elements answerForm = getElementsByClass(questionPage.getResponseBody(), "answer-form");
    assertTrue(answerForm.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) Test(org.junit.Test)

Example 48 with User

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

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

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

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