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);
}
}
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);
}
}
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);
}
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());
}
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));
}
Aggregations