Search in sources :

Example 21 with Poll

use of it.vige.rubia.model.Poll in project rubia-forums by flashboss.

the class ForumsModuleImpl method removePollInTopic.

@Override
public void removePollInTopic(Topic topic) throws ModuleException {
    try {
        if (topic != null && topic.getPoll() != null) {
            Poll poll = em.find(Poll.class, topic.getPoll().getId());
            topic.setPoll(null);
            em.remove(poll);
            em.flush();
        }
    } catch (Exception e) {
        String errorMessage = "Cannot delete poll";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : Poll(it.vige.rubia.model.Poll) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 22 with Poll

use of it.vige.rubia.model.Poll in project rubia-forums by flashboss.

the class ForumsModuleImpl method addPollToTopic.

@Override
public Poll addPollToTopic(Topic topic, Poll poll) throws ModuleException {
    try {
        TypedQuery<Poll> query = em.createNamedQuery("findPoll", Poll.class);
        query.setParameter("topicid", topic.getId());
        Poll oldpoll = null;
        try {
            oldpoll = query.getSingleResult();
        } catch (NoResultException ex) {
            oldpoll = null;
        }
        if (oldpoll != null) {
            em.remove(oldpoll);
        }
        em.persist(poll);
        topic.setPoll(poll);
        for (PollOption pollOption : poll.getOptions()) {
            pollOption.setPoll(poll);
            em.persist(pollOption);
        }
        update(topic);
        em.flush();
        return poll;
    } catch (Exception e) {
        String errorMessage = "Cannot add poll to topic";
        throw new ModuleException(errorMessage, e);
    }
}
Also used : Poll(it.vige.rubia.model.Poll) PollOption(it.vige.rubia.model.PollOption) NoResultException(javax.persistence.NoResultException) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 23 with Poll

use of it.vige.rubia.model.Poll in project rubia-forums by flashboss.

the class OperationPollTest method verifyVote.

@Test
public void verifyVote() {
    Topic topic = new Topic(new Forum("Second Test Forum"), "Fourth Test Topic");
    goTo(driver, topic);
    Poll pollToUpdate = getPollOfCurrentTopic(driver);
    Poll updatedPoll = vote(driver, pollToUpdate, 0);
    assertEquals("Fourth Test Question", updatedPoll.getTitle());
    assertEquals(100, updatedPoll.getVotesSum());
    List<PollOption> options = updatedPoll.getOptions();
    assertEquals("Seventh Test Answer", options.get(0).getQuestion());
    assertEquals("Eight Test Answer", options.get(1).getQuestion());
    assertEquals(100, options.get(0).getVotes());
    assertEquals(0, options.get(1).getVotes());
    assertEquals(2, options.size());
    updatedPoll = vote(driver, pollToUpdate, 1);
    assertEquals("Fourth Test Question", updatedPoll.getTitle());
    assertEquals(100, updatedPoll.getVotesSum());
    options = updatedPoll.getOptions();
    assertEquals("Seventh Test Answer", options.get(0).getQuestion());
    assertEquals("Eight Test Answer", options.get(1).getQuestion());
    assertEquals(50, options.get(0).getVotes());
    assertEquals(50, options.get(1).getVotes());
    assertEquals(2, options.size());
    topic.setPoll(updatedPoll);
    String message = removePoll(driver, topic);
    assertTrue(message.equals(OK));
    String[] createdOptions = addPoll(driver, updatedPoll);
    assertEquals(2, createdOptions.length);
}
Also used : UpdatePoll.updatePoll(it.vige.rubia.selenium.forum.action.UpdatePoll.updatePoll) Poll(it.vige.rubia.model.Poll) RemovePoll.removePoll(it.vige.rubia.selenium.forum.action.RemovePoll.removePoll) CreatePoll.addPoll(it.vige.rubia.selenium.forum.action.CreatePoll.addPoll) PollOption(it.vige.rubia.model.PollOption) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) VerifyPoll.getPollOfCurrentTopic(it.vige.rubia.selenium.forum.action.VerifyPoll.getPollOfCurrentTopic) Forum(it.vige.rubia.model.Forum) RemoveForum.removeForum(it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum) CreateForum.createForum(it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum) Test(org.junit.Test)

Example 24 with Poll

use of it.vige.rubia.model.Poll in project rubia-forums by flashboss.

the class OperationPollTest method verifyAddDeleteOptions.

@Test
public void verifyAddDeleteOptions() {
    Topic topic = new Topic(new Forum("Second Test Forum"), "Fourth Test Topic");
    goTo(driver, topic);
    Poll pollToUpdate = getPollOfCurrentTopic(driver);
    pollToUpdate.getOptions().clear();
    pollToUpdate.getOptions().add(new PollOption("Third Test Answer"));
    pollToUpdate.getOptions().add(new PollOption("Fifth Test with Truncation over 25 characters Answer"));
    Poll updatedPoll = addOptions(driver, pollToUpdate);
    assertEquals("Fourth Test Question", updatedPoll.getTitle());
    assertEquals(0, updatedPoll.getVotesSum());
    List<PollOption> options = updatedPoll.getOptions();
    assertEquals("Seventh Test Answer", options.get(0).getQuestion());
    assertEquals("Eight Test Answer", options.get(1).getQuestion());
    assertEquals("Third Test Answer", options.get(2).getQuestion());
    assertEquals("Fifth Test with Truncation over 25 characters Answer", options.get(3).getQuestion());
    assertEquals(0, options.get(0).getVotes());
    assertEquals(0, options.get(1).getVotes());
    assertEquals(0, options.get(2).getVotes());
    assertEquals(0, options.get(3).getVotes());
    assertEquals(4, options.size());
    pollToUpdate.getOptions().clear();
    pollToUpdate.getOptions().add(new PollOption("Third Test Answer"));
    pollToUpdate.getOptions().add(new PollOption("Fifth Test with Truncation over 25 characters Answer"));
    updatedPoll = deleteOptions(driver, pollToUpdate);
    assertEquals("Fourth Test Question", updatedPoll.getTitle());
    assertEquals(0, updatedPoll.getVotesSum());
    options = updatedPoll.getOptions();
    assertEquals("Seventh Test Answer", options.get(0).getQuestion());
    assertEquals("Eight Test Answer", options.get(1).getQuestion());
    assertEquals(0, options.get(0).getVotes());
    assertEquals(0, options.get(1).getVotes());
    assertEquals(2, options.size());
}
Also used : UpdatePoll.updatePoll(it.vige.rubia.selenium.forum.action.UpdatePoll.updatePoll) Poll(it.vige.rubia.model.Poll) RemovePoll.removePoll(it.vige.rubia.selenium.forum.action.RemovePoll.removePoll) CreatePoll.addPoll(it.vige.rubia.selenium.forum.action.CreatePoll.addPoll) PollOption(it.vige.rubia.model.PollOption) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) VerifyPoll.getPollOfCurrentTopic(it.vige.rubia.selenium.forum.action.VerifyPoll.getPollOfCurrentTopic) Forum(it.vige.rubia.model.Forum) RemoveForum.removeForum(it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum) CreateForum.createForum(it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum) Test(org.junit.Test)

Example 25 with Poll

use of it.vige.rubia.model.Poll in project rubia-forums by flashboss.

the class OperationPollTest method stop.

@AfterClass
public static void stop() {
    Topic topic = new Topic(new Forum("First Test Forum"), "First Test Topic", asList(new Post[] { new Post("First Test Body", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))) }), NORMAL, new Poll("First Test Question", asList(new PollOption[] { new PollOption("First Test Answer"), new PollOption("Second Test Answer") }), 4));
    String message = removePoll(driver, topic);
    assertTrue(message.equals(OK));
    message = removeTopic(driver, topic);
    assertTrue(message.equals(OK));
    topic = new Topic(new Forum("First Test Forum"), "Second Test Topic", asList(new Post[] { new Post("Second Test Body", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))) }), IMPORTANT, new Poll("Second Test Question", asList(new PollOption[] { new PollOption("Third Test Answer"), new PollOption("Fourth Test Answer") }), 8));
    message = removePoll(driver, topic);
    assertTrue(message.equals(OK));
    message = removeTopic(driver, topic);
    assertTrue(message.equals(OK));
    topic = new Topic(new Forum("Second Test Forum"), "Third Test Topic", asList(new Post[] { new Post("Third Test Body", asList(new Attachment("first", "First Test File"), new Attachment("second", "Second Test File"), new Attachment("third", "Third Test File"))) }), ADVICE, new Poll("Third Test Question", asList(new PollOption[] { new PollOption("Fifth Test with Truncation over 25 characters Answer"), new PollOption("Sixth Test Answer") }), 9));
    message = removePoll(driver, topic);
    assertTrue(message.equals(OK));
    message = removeTopic(driver, topic);
    assertTrue(message.equals(OK));
    topic = new Topic(new Forum("Second Test Forum"), "Fourth Test Topic", asList(new Post[] { new Post("Fourth Test Body", asList(new Attachment("fourth", "Fourth Test File"), new Attachment("fifth", "Fifth Test with Truncation over 25 characters File"), new Attachment("sixth", "Sixth Test File"))) }), IMPORTANT, new Poll("Fourth Test Question", asList(new PollOption[] { new PollOption("Seventh Test Answer"), new PollOption("Eight Test Answer") }), 0));
    message = removePoll(driver, topic);
    assertTrue(message.equals(OK));
    message = removeTopic(driver, topic);
    assertTrue(message.equals(OK));
    message = removeForum(driver, new Forum("First Test Forum"), "Second Test Forum");
    assertTrue(message.equals(REMOVED_FORUM_0_MESSAGE));
    message = removeForum(driver, new Forum("Second Test Forum"), SELECT_FORUM_TYPE);
    assertTrue(message.equals(REMOVED_FORUM_1_MESSAGE));
    message = removeCategory(driver, new Category("First Test Category"), SELECT_CATEGORY_TYPE);
    assertTrue(message.equals(REMOVED_CATEGORY_0_MESSAGE));
    message = removeCategory(driver, new Category("Second Test Category"), SELECT_CATEGORY_TYPE);
    assertTrue(message.equals(REMOVED_CATEGORY_1_MESSAGE));
}
Also used : CreateCategory.createCategory(it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory) RemoveCategory.removeCategory(it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory) Category(it.vige.rubia.model.Category) Post(it.vige.rubia.model.Post) UpdatePoll.updatePoll(it.vige.rubia.selenium.forum.action.UpdatePoll.updatePoll) Poll(it.vige.rubia.model.Poll) RemovePoll.removePoll(it.vige.rubia.selenium.forum.action.RemovePoll.removePoll) CreatePoll.addPoll(it.vige.rubia.selenium.forum.action.CreatePoll.addPoll) Attachment(it.vige.rubia.model.Attachment) PollOption(it.vige.rubia.model.PollOption) RemoveTopic.removeTopic(it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic) CreateTopic.createTopic(it.vige.rubia.selenium.forum.action.CreateTopic.createTopic) Topic(it.vige.rubia.model.Topic) VerifyPoll.getPollOfCurrentTopic(it.vige.rubia.selenium.forum.action.VerifyPoll.getPollOfCurrentTopic) Forum(it.vige.rubia.model.Forum) RemoveForum.removeForum(it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum) CreateForum.createForum(it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum) AfterClass(org.junit.AfterClass)

Aggregations

Poll (it.vige.rubia.model.Poll)37 PollOption (it.vige.rubia.model.PollOption)29 Topic (it.vige.rubia.model.Topic)25 Forum (it.vige.rubia.model.Forum)23 Post (it.vige.rubia.model.Post)21 CreateTopic.createTopic (it.vige.rubia.selenium.forum.action.CreateTopic.createTopic)21 CreateForum.createForum (it.vige.rubia.selenium.adminpanel.action.CreateForum.createForum)20 Attachment (it.vige.rubia.model.Attachment)19 RemoveForum.removeForum (it.vige.rubia.selenium.adminpanel.action.RemoveForum.removeForum)19 Category (it.vige.rubia.model.Category)14 RemoveTopic.removeTopic (it.vige.rubia.selenium.forum.action.RemoveTopic.removeTopic)14 CreateCategory.createCategory (it.vige.rubia.selenium.adminpanel.action.CreateCategory.createCategory)12 RemoveCategory.removeCategory (it.vige.rubia.selenium.adminpanel.action.RemoveCategory.removeCategory)12 BeforeClass (org.junit.BeforeClass)11 WebElement (org.openqa.selenium.WebElement)10 Test (org.junit.Test)9 CreatePost.createPost (it.vige.rubia.selenium.forum.action.CreatePost.createPost)8 VerifyPoll.getPollOfCurrentTopic (it.vige.rubia.selenium.forum.action.VerifyPoll.getPollOfCurrentTopic)8 CreatePoll.addPoll (it.vige.rubia.selenium.forum.action.CreatePoll.addPoll)6 RemovePoll.removePoll (it.vige.rubia.selenium.forum.action.RemovePoll.removePoll)6