Search in sources :

Example 1 with Poll

use of org.survey.model.poll.Poll in project survey by markoniemi.

the class EditPollBeanTest method addPollWithError.

@Test
public void addPollWithError() {
    String result = editPollBean.addPoll();
    Assert.assertEquals("editPollBean.addPoll returned an unexpected value", "editPoll", result);
    Poll createdPoll = new Poll("poll");
    editPollBean.setPoll(createdPoll);
    result = editPollBean.savePoll();
    Assert.assertEquals("editPollBean.savePoll returned an unexpected value", "pollSaved", result);
    Poll pollFromDatabase = pollService.findOne(createdPoll.getName());
    Assert.assertNotNull("registered poll was not added to database", pollFromDatabase);
    Assert.assertEquals("poll", pollFromDatabase.getName());
    result = editPollBean.addPoll();
    createdPoll.setId(null);
    editPollBean.setPoll(createdPoll);
    result = editPollBean.savePoll();
    Assert.assertNull(result);
    Assert.assertEquals("Poll with this name already exists.", editPollBean.getMessage());
}
Also used : Poll(org.survey.model.poll.Poll) Test(org.junit.Test)

Example 2 with Poll

use of org.survey.model.poll.Poll in project survey by markoniemi.

the class EditPollBeanTest method tearDown.

@After
public void tearDown() {
    Poll[] polls = pollService.findAll();
    for (Poll poll : polls) {
        pollService.delete(poll.getName());
    }
    userService.delete(this.user.getUsername());
}
Also used : Poll(org.survey.model.poll.Poll) After(org.junit.After)

Example 3 with Poll

use of org.survey.model.poll.Poll in project survey by markoniemi.

the class EditPollBeanTest method questionTypeChanged.

@Ignore("poll is attached and test does not represent the situation in runtime")
@Test
public void questionTypeChanged() {
    // addQuestion calls addPoll
    addQuestion();
    editPollBean.getPoll().getQuestions().get(0).setType(QuestionType.BOOLEAN);
    editPollBean.questionTypeChanged(0);
    String result = editPollBean.savePoll();
    Assert.assertEquals("editPollBean.savePoll returned an unexpected value", "pollSaved", result);
    Poll pollFromDatabase = pollService.findOne("poll");
    QuestionType type = pollFromDatabase.getQuestions().get(0).getType();
    Assert.assertEquals(QuestionType.BOOLEAN, type);
}
Also used : Poll(org.survey.model.poll.Poll) QuestionType(org.survey.model.poll.QuestionType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Poll

use of org.survey.model.poll.Poll in project survey by markoniemi.

the class EditPollBeanTest method addPoll.

@Test
public void addPoll() {
    String result = editPollBean.addPoll();
    Assert.assertEquals("editPollBean.register returned an unexpected value", "editPoll", result);
    // Poll createdPoll = new Poll("poll");
    // editPollBean.setPoll(createdPoll);
    editPollBean.getPoll().setName("poll");
    result = editPollBean.savePoll();
    Assert.assertEquals("editPollBean.savePoll returned an unexpected value", "pollSaved", result);
    Poll pollFromDatabase = pollService.findOne("poll");
    Assert.assertNotNull("registered poll was not added to database", pollFromDatabase);
    Assert.assertEquals("poll", pollFromDatabase.getName());
}
Also used : Poll(org.survey.model.poll.Poll) Test(org.junit.Test)

Example 5 with Poll

use of org.survey.model.poll.Poll in project survey by markoniemi.

the class PollController method editPoll.

@RequestMapping(value = "/poll/{name}", method = RequestMethod.GET)
public ModelAndView editPoll(@PathVariable String name) {
    Poll poll = pollService.findOne(name);
    log.debug("editPoll() - found poll: " + poll);
    if (poll == null) {
        poll = new Poll();
    }
    ModelAndView model = new ModelAndView();
    model.setViewName("/poll/poll");
    model.addObject("poll", poll);
    return model;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Poll(org.survey.model.poll.Poll) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Poll (org.survey.model.poll.Poll)21 Test (org.junit.Test)14 After (org.junit.After)2 Ignore (org.junit.Ignore)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 CrudRepositoryTest (org.survey.repository.CrudRepositoryTest)2 Before (org.junit.Before)1 ResultActions (org.springframework.test.web.servlet.ResultActions)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 Question (org.survey.model.poll.Question)1 QuestionType (org.survey.model.poll.QuestionType)1 User (org.survey.model.user.User)1