Package com.agiletec.plugins.jpsurvey.aps.system.services.survey.model

Examples of com.agiletec.plugins.jpsurvey.aps.system.services.survey.model.Question


  }
 
  public void testDeleteQuestion() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    Survey actual = null;
    Question question = null;
    try {
      // delete an unknown question, no exceptions!
      question = this.getSurveyManager().loadQuestion(222);
      assertNull(question);
      this.getSurveyManager().deleteQuestion(222);
View Full Code Here


      assertEquals(survey.isActive(), actual.isActive());
      assertEquals(survey.isCheckCookie(), actual.isCheckCookie());
      assertEquals(survey.isCheckIpAddress(), actual.isCheckIpAddress());
      assertEquals(survey.getQuestions().size(), actual.getQuestions().size());
      for (Question currentQuestion: survey.getQuestions()) {
        Question actualQuestion = actual.getQuestion(currentQuestion.getId());
        assertNotNull(actualQuestion);
        assertEquals(currentQuestion.getPos(), actualQuestion.getPos());
        assertEquals(currentQuestion.isSingleChoice(), actualQuestion.isSingleChoice());
        assertEquals(currentQuestion.getMaxResponseNumber(), actualQuestion.getMaxResponseNumber());
        assertEquals(currentQuestion.getMinResponseNumber(), actualQuestion.getMinResponseNumber());
        assertEquals(currentQuestion.getQuestions(), actualQuestion.getQuestions());
        for (Choice currentChoice: currentQuestion.getChoices()) {
          Choice actualChoice = actual.getQuestion(currentQuestion.getId()).getChoice(currentChoice.getId());
          assertNotNull(actualChoice);
          assertEquals(currentChoice.isFreeText(), actualChoice.isFreeText());
          assertEquals(currentChoice.getPos(), actualChoice.getPos());
          assertEquals(currentChoice.getChoices(), actualChoice.getChoices());
//          System.out.println(" QUID "+currentQuestion.getId()+" CID "+currentChoice.getId());
        }
      }
      // test a survey with no choices
      this.getSurveyManager().deleteSurvey(survey.getId());
      for (Question i: survey.getQuestions()) {
        i.setChoices(new ArrayList<Choice>());
      }
      this.getSurveyManager().saveSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(survey.getId(), actual.getId());
      assertEquals(survey.getGroupName(), actual.getGroupName());
      assertEquals(survey.getImageId(), actual.getImageId());
      assertEquals(survey.getDescriptions(), actual.getDescriptions());
      assertEquals(survey.getEndDate(), actual.getEndDate());
      assertEquals(survey.getImageDescriptions(), actual.getImageDescriptions());
      assertEquals(startDate, actual.getStartDate());
      assertEquals(survey.getTitles(), actual.getTitles());
      assertEquals(survey.isActive(), actual.isActive());
      assertEquals(survey.isCheckCookie(), actual.isCheckCookie());
      assertEquals(survey.isCheckIpAddress(), actual.isCheckIpAddress());
      assertEquals(survey.getQuestions().size(), actual.getQuestions().size());
      for (Question currentQuestion: survey.getQuestions()) {
        Question actualQuestion = actual.getQuestion(currentQuestion.getId());
        assertNotNull(actualQuestion);
        assertEquals(currentQuestion.getPos(), actualQuestion.getPos());
        assertEquals(currentQuestion.isSingleChoice(), actualQuestion.isSingleChoice());
        assertEquals(currentQuestion.getMaxResponseNumber(), actualQuestion.getMaxResponseNumber());
        assertEquals(currentQuestion.getMinResponseNumber(), actualQuestion.getMinResponseNumber());
        assertEquals(currentQuestion.getQuestions(), actualQuestion.getQuestions());
        assertNotNull(currentQuestion.getChoices());
        assertEquals(currentQuestion.getChoices().isEmpty(), actualQuestion.getChoices().isEmpty());
        // System.out.println(" QUID "+currentQuestion.getId());
      }
      // test a survey with no questions
      this.getSurveyManager().deleteSurvey(survey.getId());
      survey.getQuestions().clear();
View Full Code Here

    }
  }
 
  public void testDeleteChoiceByQuestionid() throws Throwable {
    Survey survey = null;
    Question actualQuestion = null;
    Survey actual = null;
    try {
      survey = this.getFakeActiveSurvey();
      survey.getQuestions().remove(0);
      assertEquals(1, survey.getQuestions().size());
      this.getSurveyManager().saveSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertNotNull(actual.getQuestions());
      assertEquals(1, actual.getQuestions().size());
      assertEquals(2, actual.getQuestions().get(0).getChoices().size());
      int questionId = survey.getQuestions().get(0).getId();
      this.getSurveyManager().deleteChoiceByQuestionId(questionId);
      actualQuestion = this.getSurveyManager().loadQuestion(questionId);
      assertNotNull(actualQuestion);
      assertNotNull(actualQuestion.getChoices());
      assertEquals(0, actualQuestion.getChoices().size());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here

      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  public void testUpdateQuestion() throws Throwable {
    Question question = this.getFakeQuestion();
    try {
      // standard question with choices
      this.getSurveyManager().saveQuestion(question);
      question = this.getSurveyManager().loadQuestion(question.getId());
      assertNotNull(question);
      assertFalse(question.isSingleChoice());
      question.setMinResponseNumber(2677);
      question.setMaxResponseNumber(1977);
      question.setPos(38);
      question.setSingleChoice(true);
      question.setSurveyId(2);
      assertNotNull(question.getChoices());
      assertTrue(!question.getChoices().isEmpty());
      question.getChoices().get(0).setPos(1976); // this choice will be placed in last position!!!
      this.getSurveyManager().updateQuestion(question);
      question = this.getSurveyManager().loadQuestion(question.getId());
      assertNotNull(question);
      assertTrue(question.isSingleChoice());
      assertNotNull(question.getQuestions());
      assertEquals(38, question.getPos());
      assertEquals(1977, question.getMaxResponseNumber());
      assertEquals(2677, question.getMinResponseNumber());
      assertEquals(2, question.getSurveyId());
      assertNotNull(question.getChoices());
      assertTrue(!question.getChoices().isEmpty());
      assertEquals(2, question.getChoices().size());
      assertEquals(1976, question.getChoices().get(1).getPos());
      // delete one choice
      question.getChoices().remove(0);
      question.getChoices().get(0).setPos(123);
      question.setMinResponseNumber(1);
      this.getSurveyManager().updateQuestion(question);
      question = this.getSurveyManager().loadQuestion(question.getId());
      assertNotNull(question);
      assertEquals(1, question.getMinResponseNumber());
      assertEquals(1, question.getChoices().size());
      assertEquals(123, question.getChoices().get(0).getPos());
      // delete the remaining choice
      question.getChoices().clear();
      question.setMinResponseNumber(123);
      question.setMaxResponseNumber(321);
      this.getSurveyManager().updateQuestion(question);
      question = this.getSurveyManager().loadQuestion(question.getId());
      assertNotNull(question);
      assertEquals(123, question.getMinResponseNumber());
      assertEquals(321, question.getMaxResponseNumber());
      assertNotNull(question.getChoices());
      assertTrue(question.getChoices().isEmpty());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteQuestion(question.getId());
    }
  }
View Full Code Here

      assertEquals(survey.getImageId(), actual.getImageId());
      assertEquals(survey.isActive(), actual.isActive());
      assertEquals(survey.getDescriptions(), actual.getDescriptions());
      assertTrue(actual.getQuestions().isEmpty());
      for (Question question: survey.getQuestions()) {
        Question actualQuestion = this.getSurveyManager().loadQuestion(question.getId());
        assertNull(actualQuestion);
        for (Choice choice: question.getChoices()) {
          Choice actualChoice = this.getSurveyManager().loadChoice(choice.getId());
          assertNull(actualChoice);
        }
View Full Code Here

      assertEquals(true, actual.isActive());
      assertEquals(false, actual.isPublicPartialResult());
      assertEquals(true, actual.getQuestions().get(0).isSingleChoice());
      assertEquals(11, actual.getQuestions().get(0).getPos());
      // alternate question checks, load directly from the DB
      Question question = this.getSurveyManager().loadQuestion(actual.getQuestions().get(0).getId());
      assertNotNull(question);
      assertNotNull(question.getChoices());
      assertTrue(question.getChoices().isEmpty());
      // update a survey with no question
      survey = this.getSurveyManager().loadSurvey(actual.getId());
      survey.getQuestions().clear();
      survey.setActive(false);
      survey.setPublicPartialResult(false);
View Full Code Here

  }
 
  public void testSaveQuestionInSortedPosition() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    Survey actual = null;
    Question question = getFakeQuestion();
    try {
      // prepare a known survey for swapping questions
      survey.getQuestions().get(0).setPos(3);
      survey.getQuestions().get(0).setSingleChoice(true);
      survey.getQuestions().get(0).setMinResponseNumber(1);
      survey.getQuestions().get(0).setMaxResponseNumber(5);
      survey.getQuestions().get(1).setPos(9);
      survey.getQuestions().get(1).setSingleChoice(false);
      survey.getQuestions().get(1).setMinResponseNumber(6);
      survey.getQuestions().get(1).setMaxResponseNumber(10);
      this.getSurveyManager().saveSurvey(survey);
      // add the new question
      question.setSurveyId(survey.getId());
      question.setPos(1); // this will be ignored when saving
      question.setMaxResponseNumber(888);
      question.setMinResponseNumber(777);
      this.getSurveyManager().saveQuestionInSortedPosition(question);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertNotNull(actual.getQuestions());
      assertEquals(3, actual.getQuestions().size());
View Full Code Here

*/
public class QuestionDAO extends AbstractSurveyDAO implements IQuestionDAO {
 
  @Override
  public Question loadQuestion(int id) {
    Question question = null;
    Connection conn = null;
    PreparedStatement stat = null;
    ResultSet res = null;
    try {
      conn = this.getConnection();
      stat = conn.prepareStatement(GET_COMPLETE_QUESTION_BY_ID);
      stat.setInt(1, id);
      res = stat.executeQuery();
      while (res.next()) {
        if (null == question) {
          question = this.buildQuestionRecordFromResultSet(res, 1);
        }
        // get extra info: questions need the survey type
        int questionnaireValue = res.getInt(13);
        boolean questionnaire = questionnaireValue == 1 ? true:false;
        ApsProperties titles = new ApsProperties();
        titles.loadFromXml(res.getString(14));
        question.setExtraInfo(questionnaire, titles);
        Choice choice = this.buildChoiceRecordFromResultSet(res, 8);
        if (null == choice) continue;
        choice.setExtraInfo(question.getSurveyId(), question.isQuestionnaire(), question.getSurveyTitles(), question.getQuestions());
        if (null == question.getChoice(choice.getId())) {
          question.getChoices().add(choice);
        }
      }
    } catch (Throwable t) {
      processDaoException(t, "Error while loading the question of ID "+id, "loadQuestion");
    } finally {
View Full Code Here

  /* (non-Javadoc)
   * @see com.agiletec.plugins.jpsurvey.apsadmin.survey.IChoiceAction#addNewChoice()
   */
  public String addNewChoice() {
    Question question = null;
    Choice fakeChoice = new Choice(); // this is a dummy used only to contain extra infos!
    try {
      question = this.getSurveyManager().loadQuestion(this.getQuestionId());
      if (null != question) {
        fakeChoice.setExtraInfo(question.getSurveyId(), question.isQuestionnaire(), question.getSurveyTitles(), question.getQuestions());
      }
      fakeChoice.setId(-1);
      fakeChoice.setQuestionId(this.getQuestionId());
      this.setChoice(fakeChoice);
    } catch (Throwable t) {
View Full Code Here

  @Override
  public List<Choice> getQuestionChoices(int id) {
    List<Choice> list = new ArrayList<Choice>();
    try {
      Question question = this.loadQuestion(id);
      if (null != question) {
        list = question.getChoices();
      }
    } catch (Throwable t) {
      processDaoException(t, "Error while loading the choices belonging to the question of ID " + id, "loadQuestion");
    }
    return list;
View Full Code Here

TOP

Related Classes of com.agiletec.plugins.jpsurvey.aps.system.services.survey.model.Question

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.