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

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


    }
  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testDeleteQuestion() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(false, true, false);
    Question question = null;
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
      // update internal id's by reloading the object
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertFalse(survey.getQuestions().isEmpty()); // FIXME delete this
      // delete known ID
      this.initAction("/do/jpsurvey/Survey", "deleteQuestion");
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      question = this.getSurveyManager().loadQuestion(survey.getQuestions().get(0).getId());
      assertNull(question);
     
      // delete unknown ID
      this.initAction("/do/jpsurvey/Survey", "deleteQuestion");
      this.addParameter("questionId", -1);
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
     
      // invoke with no params
      this.initAction("/do/jpsurvey/Survey", "deleteQuestion");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
     
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
View Full Code Here


    }
  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testMoveQuestionUp() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(false, true, false);
    Survey expected = null;
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
      // update internal id's by reloading the object
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertEquals(2, survey.getQuestions().size());
      // load a copy
      expected = this.getSurveyManager().loadSurvey(survey.getId());
      // invoke without arguments
      this.initAction("/do/jpsurvey/Survey", "moveQuestionUp");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
      // swap unknown id
      this.initAction("/do/jpsurvey/Survey", "moveQuestionUp");
      this.addParameter("questionId", -1);
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertEquals(expected.getQuestions().get(0).getId(), survey.getQuestions().get(0).getId());
      assertEquals(expected.getQuestions().get(1).getId(), survey.getQuestions().get(1).getId());
      // swap known id
      this.initAction("/do/jpsurvey/Survey", "moveQuestionUp");
      this.addParameter("questionId", survey.getQuestions().get(1).getId());
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertEquals(expected.getQuestions().get(0).getId(), survey.getQuestions().get(1).getId());
      assertEquals(expected.getQuestions().get(1).getId(), survey.getQuestions().get(0).getId());
      this.initAction("/do/jpsurvey/Survey", "moveQuestionUp");
      this.addParameter("questionId", survey.getQuestions().get(1).getId());
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey=getSurveyManager().loadSurvey(survey.getId());
      assertEquals(expected.getQuestions().get(0).getId(), survey.getQuestions().get(0).getId());     
    } catch (Throwable t) {
      throw t;
    } finally {
      getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here

    }
  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testMoveQuestionDown() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(false, true, false);
    Survey expected = null;
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertEquals(2, survey.getQuestions().size());
      expected = this.getSurveyManager().loadSurvey(survey.getId());
      // invoke without arguments
      this.initAction("/do/jpsurvey/Survey", "moveQuestionDown");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
      // swap unknown id
      this.initAction("/do/jpsurvey/Survey", "moveQuestionDown");
      this.addParameter("questionId", -1);
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertEquals(expected.getQuestions().get(0).getId(), survey.getQuestions().get(0).getId());
      assertEquals(expected.getQuestions().get(1).getId(), survey.getQuestions().get(1).getId());
      expected = survey;
      this.initAction("/do/jpsurvey/Survey", "moveQuestionDown");
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertEquals(expected.getQuestions().get(0).getId(), survey.getQuestions().get(1).getId());
      assertEquals(expected.getQuestions().get(1).getId(), survey.getQuestions().get(0).getId());
      this.initAction("/do/jpsurvey/Survey", "moveQuestionDown");
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertEquals(expected.getQuestions().get(1).getId(), survey.getQuestions().get(1).getId());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here

  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  // NOTE: this will return SUCCESS only when you are allowed to add a new text
  public void testAddFreeText() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(false, true, false);
    Survey free = this.createFakeSurveyForTest(false, true, true);
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
      // update internal id's by reloading the object
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      this.getSurveyManager().saveSurvey(free);
      free = this.getSurveyManager().loadSurvey(free.getId());
      // invoke without arguments
      this.initAction("/do/jpsurvey/Survey", "addFreeText");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
     
      // add choice to unknown question
      this.initAction("/do/jpsurvey/Survey", "addFreeText");
      this.addParameter("questionId", -1);
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
     
      // request to add new question with valid data
      this.initAction("/do/jpsurvey/Survey", "addFreeText");
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      this.addParameter("questionnaire", true);
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      this.addParameter("singleChoice", true);
      this.addParameter("question-it", "TEST");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
     
      // request to add new question with valid data
      this.initAction("/do/jpsurvey/Survey", "addFreeText");
      this.addParameter("questionId", free.getQuestions().get(0).getId());
      this.addParameter("questionnaire", true);
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      this.addParameter("singleChoice", true);
      this.addParameter("question-it", "TEST");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals("noMoreFreeText", result);
    } catch (Throwable t) {
      throw t;
    } finally {
      getSurveyManager().deleteSurvey(survey.getId());
      getSurveyManager().deleteSurvey(free.getId());
    }
  }
View Full Code Here

    }
  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testAddChoice() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(false, true, true);
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
      // update internal id's by reloading the object
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      // invoke without arguments
      this.initAction("/do/jpsurvey/Survey", "addChoice");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
     
      // invoke without arguments
      this.initAction("/do/jpsurvey/Survey", "addChoice");
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      this.addParameter("questionnaire", true);
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      this.addParameter("singleChoice", true);
      this.addParameter("question-it", "TEST");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
View Full Code Here

  public String intercept(ActionInvocation invocation) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    VoterResponse voterResponse = this.getVoterResponse(request);
    if (null == voterResponse) return "nullVoterResponse";
   
    Survey survey = voterResponse.getSurvey();
    Date today = new Date();
    boolean started = (today.getTime() > survey.getStartDate().getTime());
    //SE NON INIZIATO, ESCI
    if (!started) return "surveyNotBegunYet";
    boolean expired = (null != survey.getEndDate() && today.getTime() > survey.getEndDate().getTime());
    //SE FINITO ESCI
    if (expired) return "expiredSurvey";
   
    UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    if (survey.isCheckUsername() && (null == currentUser || currentUser.getUsername().equals(SystemConstants.GUEST_USER_NAME))) {
      return "userNotAllowedToSurvey";
    }
   
    String checkGroup = this.checkSurveyGroup(survey, request);
    if (null != checkGroup) return checkGroup;
   
    try {
      boolean voted = CheckVotingUtil.isSurveyVoted(survey, request);
      if (voted) return "surveyAlreadyVoted";
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "intercept", "Error checking the  the vote for survey " + survey.getId());
      throw new Exception("Error checking the  the vote for survey " + survey.getId(), t);
    }
   
    return invocation.invoke();
  }
View Full Code Here

      int currentIndexInt = this.getCurrentQuestionIndex().intValue()+1;
      if (currentIndexInt != currentVotingInfoBean.getCurrentQuestionIndex()) {
        //Check REFRESH
        return SUCCESS;
      }
      Survey survey = this.getVoterResponse().getSurvey();
      if (survey.getQuestions().size() == currentIndexInt) {
        this.getResponseManager().saveVoterResponse(this.getVoterResponse());
        this.addCookieVoting(survey.getId());
        this.getRequest().getSession().removeAttribute(ApsAdminSurveySystemConstants.SURVEY_CURRENT_VOTING_INFO_SESSION_PARAM);
        this.getRequest().getSession().removeAttribute(ApsAdminSurveySystemConstants.SURVEY_CURRENT_QUESTION_INDEX_SESSION_PARAM);
        this.setSurveyId(survey.getId());
        return "submitSurvey";
      }
      Integer currentIndex = new Integer(currentIndexInt);
      this.getRequest().getSession().setAttribute(ApsAdminSurveySystemConstants.SURVEY_CURRENT_QUESTION_INDEX_SESSION_PARAM, currentIndex);
    } catch (Throwable t) {
View Full Code Here

 
  public boolean isEditable(Integer surveyId) {
    boolean res = false;
    try {
      if (null == surveyId) return true;
      Survey survey = this.getSurveyManager().loadSurvey(surveyId);
      res =! survey.isElegibleForVoting(null);
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "isEditable");
      throw new RuntimeException("Error checking the \"editable\" state of the survey with id " + surveyId, t);
    }
    return res;
View Full Code Here

    }
  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testSaveChoice() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(true, true, false);
    Survey verify = null;
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
      // update internal id's by reloading the object
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(survey);
      // invoke without arguments
      this.initAction("/do/jpsurvey/Survey", "saveChoice");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
     
      // save new choice
      this.initAction("/do/jpsurvey/Survey", "saveChoice");
      this.addParameter("choiceId", -1);
      this.addParameter("surveyId", survey.getId());
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      this.addParameter("strutsAction", ApsAdminSystemConstants.ADD);
      this.addParameter("choice-it", "forza Cagliari");
      this.addParameter("isQuestionnaire", "true");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      verify = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(verify.getQuestions().get(0).getChoices());
      assertEquals(3, verify.getQuestions().get(0).getChoices().size());
      assertEquals("forza Cagliari", verify.getQuestions().get(0).getChoices().get(2).getAnswer("it"));
     
      // save edited choice
      survey = getSurveyManager().loadSurvey(survey.getId());
      this.initAction("/do/jpsurvey/Survey", "saveChoice");
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      this.addParameter("choiceId", survey.getQuestions().get(0).getChoices().get(2).getId());
      this.addParameter("surveyId", survey.getId());
      this.addParameter("choice-it", "forza Milan");
      this.addParameter("isQuestionnaire", "true");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      verify = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(verify.getQuestions().get(0).getChoices());
      assertEquals(3, verify.getQuestions().get(0).getChoices().size());
      assertEquals("forza Milan", verify.getQuestions().get(0).getChoices().get(2).getAnswer("it"));
    } catch (Throwable t) {
      throw t;
    } finally {
      getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here

    }
  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testAddFreeText() throws Throwable {
    Survey survey = this.createFakeSurveyForTest(true, true, false);
    String result = null;
    try {
      this.setUserOnSession("admin");
      // save the survey
      this.getSurveyManager().saveSurvey(survey);
      // update internal id's by reloading the object
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      // invoke without arguments
      this.initAction("/do/jpsurvey/Survey", "addNewFreeText");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
     
      // invoke with invalid question id, we expect a SQL exception
      this.initAction("/do/jpsurvey/Survey", "addNewFreeText");
      this.addParameter("questionId", "-1");
      this.addParameter("strutsAction", ApsAdminSystemConstants.ADD);
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.FAILURE, result);
     
      // normal operation
      this.initAction("/do/jpsurvey/Survey", "addNewFreeText");
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      this.addParameter("strutsAction", ApsAdminSystemConstants.ADD);
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(survey);
      assertNotNull(survey.getQuestions().get(0).getChoices());
      assertEquals(3, survey.getQuestions().get(0).getChoices().size());
      assertTrue(survey.getQuestions().get(0).getChoices().get(2).isFreeText());
    } catch (Throwable t) {
      throw t;
    } finally {
      getSurveyManager().deleteSurvey(survey.getId());
    }
  }
View Full Code Here

TOP

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

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.