Search in sources :

Example 16 with Question

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

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

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

the class EditQuestionTest method should_edit_question_of_other_author.

@Test
public void should_edit_question_of_other_author() throws Exception {
    Question question = createQuestionWithDao(moderator(), "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.pending")));
}
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 19 with Question

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

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

the class RssFeedFactoryTest method should_generate_feed.

@Test
public void should_generate_feed() throws IOException {
    DefaultEnvironment env = new DefaultEnvironment(new EnvironmentType("mamute"));
    QuestionRssEntryFactory factory = new QuestionRssEntryFactory(env);
    RssFeedFactory rssFeedFactory = new RssFeedFactory(env, factory);
    QuestionBuilder builder = new QuestionBuilder();
    DateTimeUtils.setCurrentMillisFixed(100);
    User user1 = user("author1", "author@email");
    user1.setPhotoUri(new URL("http://imagemsuser1.com"));
    Question question1 = builder.withAuthor(user1).withTitle("first question").withDescription("question").withId(1l).build();
    User user2 = user("author2", "author@email");
    user2.setPhotoUri(new URL("http://imagemsuser2.com"));
    Question question2 = builder.withId(2l).withTitle("second question").withAuthor(user2).build();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    rssFeedFactory.build(Arrays.<RssContent>asList(question1, question2), output, "title", "description");
    output.close();
    String xml = new String(output.toByteArray());
    assertTrue(xml.contains("first question"));
    assertTrue(xml.contains("second question"));
    assertTrue(xml.contains("http://imagemsuser1.com"));
    assertTrue(xml.contains("http://imagemsuser2.com"));
    DateTimeUtils.setCurrentMillisSystem();
}
Also used : DefaultEnvironment(br.com.caelum.vraptor.environment.DefaultEnvironment) EnvironmentType(br.com.caelum.vraptor.environment.EnvironmentType) User(org.mamute.model.User) RssFeedFactory(org.mamute.infra.rss.write.RssFeedFactory) QuestionBuilder(org.mamute.builder.QuestionBuilder) Question(org.mamute.model.Question) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QuestionRssEntryFactory(org.mamute.infra.rss.write.QuestionRssEntryFactory) URL(java.net.URL) 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