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

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


      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  public void testChangeQuestionPosition() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    Survey actual = null;
    Survey expected = null;
    try {
      // prepare a known survey for swapping questions
      survey.getQuestions().get(0).setSingleChoice(true);
      survey.getQuestions().get(0).setMinResponseNumber(1);
      survey.getQuestions().get(0).setMaxResponseNumber(5);
      assertEquals(0, survey.getQuestions().get(0).getPos());
      survey.getQuestions().get(1).setMinResponseNumber(6);
      survey.getQuestions().get(1).setMaxResponseNumber(10);
      survey.getQuestions().get(1).setSingleChoice(false);
      assertEquals(1, survey.getQuestions().get(1).getPos());
      this.getSurveyManager().saveSurvey(survey);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      // Move the first question down
      this.getSurveyManager().swapQuestionPosition(actual.getQuestions().get(0).getId(), false);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(survey.getQuestions().get(0).getId(), actual.getQuestions().get(1).getId());
      assertEquals(true, actual.getQuestions().get(1).isSingleChoice());
      assertEquals(1, actual.getQuestions().get(1).getMinResponseNumber());
      assertEquals(5, actual.getQuestions().get(1).getMaxResponseNumber());
      assertEquals(survey.getQuestions().get(1).getId(), actual.getQuestions().get(0).getId());
      assertEquals(false, actual.getQuestions().get(0).isSingleChoice());
      assertEquals(6, actual.getQuestions().get(0).getMinResponseNumber());
      assertEquals(10, actual.getQuestions().get(0).getMaxResponseNumber());
     
      // move the last question down does nothing
      expected = this.getSurveyManager().loadSurvey(survey.getId());
      this.getSurveyManager().swapQuestionPosition(actual.getQuestions().get(1).getId(), false);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(expected.getQuestions().get(0).getId(), actual.getQuestions().get(0).getId());
      assertEquals(true, actual.getQuestions().get(1).isSingleChoice());
      assertEquals(1, actual.getQuestions().get(1).getMinResponseNumber());
      assertEquals(5, actual.getQuestions().get(1).getMaxResponseNumber());
      assertEquals(expected.getQuestions().get(1).getId(), actual.getQuestions().get(1).getId());
      assertEquals(false, actual.getQuestions().get(0).isSingleChoice());
      assertEquals(6, actual.getQuestions().get(0).getMinResponseNumber());
      assertEquals(10, actual.getQuestions().get(0).getMaxResponseNumber());
     
      // move the first question up does nothing
      expected = this.getSurveyManager().loadSurvey(survey.getId());
      this.getSurveyManager().swapQuestionPosition(actual.getQuestions().get(0).getId(), true);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertEquals(expected.getQuestions().get(0).getId(), actual.getQuestions().get(0).getId());
      assertEquals(true, actual.getQuestions().get(1).isSingleChoice());
      assertEquals(1, actual.getQuestions().get(1).getMinResponseNumber());
      assertEquals(5, actual.getQuestions().get(1).getMaxResponseNumber());
      assertEquals(expected.getQuestions().get(1).getId(), actual.getQuestions().get(1).getId());
      assertEquals(false, actual.getQuestions().get(0).isSingleChoice());
      assertEquals(6, actual.getQuestions().get(0).getMinResponseNumber());
      assertEquals(10, actual.getQuestions().get(0).getMaxResponseNumber());
     
    } catch (Throwable t) {
View Full Code Here


      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  public void testSwapChoicePosition() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    Survey actual = null;
    Survey expected = null;
    try {
      // prepare a known survey for swapping questions
      survey.getQuestions().remove(1);
      survey.getQuestions().get(0).getChoices().get(0).setPos(1);
      survey.getQuestions().get(0).getChoices().get(0).setFreeText(false);
      survey.getQuestions().get(0).getChoices().get(1).setPos(2);
      survey.getQuestions().get(0).getChoices().get(1).setFreeText(true);
      this.getSurveyManager().saveSurvey(survey);
      expected = this.getSurveyManager().loadSurvey(survey.getId());
      // swap the first choice downwards
      this.getSurveyManager().swapChoicePosition(expected.getQuestions().get(0).getChoices().get(0).getId(), false);
      actual = this.getSurveyManager().loadSurvey(survey.getId());
      assertNotNull(actual);
      assertNotNull(actual.getQuestions());
      assertNotNull(actual.getQuestions().get(0).getChoices());
      assertEquals(expected.getQuestions().get(0).getChoices().get(1).getId(), actual.getQuestions().get(0).getChoices().get(0).getId());
      assertEquals(true, actual.getQuestions().get(0).getChoices().get(0).isFreeText());
      assertEquals(expected.getQuestions().get(0).getChoices().get(0).getId(), actual.getQuestions().get(0).getChoices().get(1).getId());
      assertEquals(false, actual.getQuestions().get(0).getChoices().get(1).isFreeText());
      // swap the first choice upwards does nothing
      expected = this.getSurveyManager().loadSurvey(actual.getId());
      this.getSurveyManager().swapChoicePosition(actual.getQuestions().get(0).getChoices().get(0).getId(), true);
      assertEquals(expected.getQuestions().get(0).getChoices().get(0).getId(), actual.getQuestions().get(0).getChoices().get(0).getId());
      assertEquals(true, actual.getQuestions().get(0).getChoices().get(0).isFreeText());
      assertEquals(expected.getQuestions().get(0).getChoices().get(1).getId(), actual.getQuestions().get(0).getChoices().get(1).getId());
      assertEquals(false, actual.getQuestions().get(0).getChoices().get(1).isFreeText());
      // swap the first choice downwards does nothing
      expected = this.getSurveyManager().loadSurvey(actual.getId());
      this.getSurveyManager().swapChoicePosition(actual.getQuestions().get(0).getChoices().get(1).getId(), false);
      assertEquals(expected.getQuestions().get(0).getChoices().get(0).getId(), actual.getQuestions().get(0).getChoices().get(0).getId());
      assertEquals(true, actual.getQuestions().get(0).getChoices().get(0).isFreeText());
      assertEquals(expected.getQuestions().get(0).getChoices().get(1).getId(), actual.getQuestions().get(0).getChoices().get(1).getId());
      assertEquals(false, actual.getQuestions().get(0).getChoices().get(1).isFreeText());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
View Full Code Here

      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  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());
      assertEquals(888, actual.getQuestions().get(2).getMaxResponseNumber());
      assertEquals(777, actual.getQuestions().get(2).getMinResponseNumber());
      assertEquals(10, actual.getQuestions().get(2).getPos());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
View Full Code Here

      throw t;
    }
  }
 
  public void testSearchSurveyXMLsafe() throws Throwable {
    Survey survey = this.getFakeActiveSurvey("key=\"it\"","propertie");
    List<Integer> result = null;
    try {
      // search for XML statements in the existing surveys
      result = this.getSurveyManager().searchSurvey(null, "key=\"en\"", null, null, null, null, null);
      assertNotNull(result);
      assertEquals(0, result.size());
      result = this.getSurveyManager().searchSurvey(null, null, null, null, null, "key=\"en\"", null);
      assertNotNull(result);
      assertEquals(0, result.size());
      // save a survey with XML statement-like strings
      survey.getQuestions().clear();
      this.getSurveyManager().saveSurvey(survey);
      result = this.getSurveyManager().searchSurvey(null, "key=", null, null, null, null, null);
      assertEquals(1, result.size());
      result = this.getSurveyManager().searchSurvey(null, null, null, null, null, "prop", null);
      assertEquals(1, result.size());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
View Full Code Here

      this.getSurveyManager().deleteSurvey(survey.getId());
    }
  }
 
  public void testGetSurveyList() throws Throwable {
    Survey survey1 = getFakeActiveSurvey();
    Survey survey2 = getFakeActiveSurvey();
    List<Integer> list = null;
    try {
      this.getSurveyManager().saveSurvey(survey1);
      this.getSurveyManager().saveSurvey(survey2);
      // get all surveys
      list = this.getSurveyManager().getSurveyList();
      assertNotNull(list);
      assertEquals(4, list.size());
      // get active surveys list
      list = this.getSurveyManager().getActiveSurveyList();
      assertNotNull(list);
      assertEquals(3, list.size());
      // minus one!
      survey1.setActive(false);
      this.getSurveyManager().updateSurvey(survey1);
      list = this.getSurveyManager().getActiveSurveyList();
      assertNotNull(list);
      assertEquals(2, list.size());
      // get all surveys again :)
      list = this.getSurveyManager().getSurveyList();
      assertNotNull(list);
      assertEquals(4, list.size());
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey1.getId());
      this.getSurveyManager().deleteSurvey(survey2.getId());
    }
  }
View Full Code Here

*/
public class SurveyFrontEntryPointAction extends AbstractSurveyAction implements ISurveyFrontEntryPointAction {
 
  @Override
  public String startSurvey() {
    Survey survey = null;
    try {
      this.getRequest().getSession().removeAttribute(ApsAdminSurveySystemConstants.SURVEY_CURRENT_VOTING_INFO_SESSION_PARAM);
      this.getRequest().getSession().removeAttribute(ApsAdminSurveySystemConstants.SURVEY_CURRENT_QUESTION_INDEX_SESSION_PARAM);
      survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
      Voter voter = this.createVoter();
     
      CurrentVotingInfoBean currentVotingInfoBean = new CurrentVotingInfoBean(survey, voter);
      this.getRequest().getSession().setAttribute(ApsAdminSurveySystemConstants.SURVEY_CURRENT_VOTING_INFO_SESSION_PARAM, currentVotingInfoBean);
      this.getRequest().getSession().setAttribute(ApsAdminSurveySystemConstants.SURVEY_CURRENT_QUESTION_INDEX_SESSION_PARAM, new Integer(-1));
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "startSurvey");
      return FAILURE;
    }
    if (survey.isGatherUserInfo()) {
      return "profileVoterUser";
    }
    return SUCCESS;
  }
View Full Code Here

  }

  public void testRemoveImage() throws Throwable {
    SurveyAction action = null;
    String result = null;
    Survey survey = this.prepareSurveyForTest(true, true);
    Survey verify = null;
    ApsProperties prop = null;
    try {
      this.setUserOnSession("admin");
      this.getSurveyManager().saveSurvey(survey);
      survey.setImageId("29975");
      this.getSurveyManager().updateSurvey(survey);
      this.initAction("/do/jpsurvey/Survey", "removeSurveyImage");
      this.addParameter("surveyId", survey.getId());
      this.addParameter("questionnaire", survey.isQuestionnaire());
      this.addParameter("checkCookie", survey.isCheckCookie());
      this.addParameter("imageId", survey.getImageId());
      this.addParameter("title-it", "Questa");
      this.addParameter("description-it", "è");
      this.addParameter("imageDescription-it", "Spartaaaa");
      this.addParameter("resourceTypeCode", "Image");
      this.addParameter("groupName", survey.getGroupName());
      this.addParameter("startDate", "10/06/2009");
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      this.addParameter("gatherUserInfo", survey.isGatherUserInfo());
      result = this.executeAction();
      assertNotNull(result);
      action = (SurveyAction) this.getAction();
      assertEquals(action.SUCCESS, result);
      verify = this.getSurveyManager().loadSurvey(survey.getId());
      assertNull(verify.getImageId());
      assertTrue(verify.getImageDescriptions().isEmpty());
      prop = verify.getTitles();
      assertEquals("Questa", prop.getProperty("it"));
      prop = verify.getDescriptions();
      assertEquals("è", prop.getProperty("it"));
      prop = verify.getImageDescriptions();
      assertNull(prop.getProperty("it"));
    } catch (Throwable t) {
      throw t;
    } finally {
      this.getSurveyManager().deleteSurvey(survey.getId());
View Full Code Here

      throw t;
    }
  }
 
  private Survey prepareSurveyForTest(Boolean questionnaire, Boolean active) throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    survey.setActive(active);
    survey.setQuestionnaire(questionnaire);
    return survey;
  }
View Full Code Here

* @author E.Santoboni
*/
public class SurveyDetailAction extends AbstractSurveyAction implements ISurveyDetailAction {
 
  public Survey getSurvey() {
    Survey survey = null;
    try {
      survey = this.getSurveyManager().loadSurvey(this.getSurveyId());
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "getSurvey");
      throw new RuntimeException("Error loading survey: " + this.getSurveyId(), t);
View Full Code Here

    }
  }
 
  //TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
  public void testSaveQuestion() throws Throwable {
    Survey survey = this.getFakeActiveSurvey();
    String result = null;
    try {
      this.setUserOnSession("admin");
      survey.getQuestions().clear();
      survey.setQuestionnaire(false);
      survey.setActive(true);
      this.getSurveyManager().saveSurvey(survey);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertTrue(survey.getQuestions().isEmpty());
     
      // invoke without parameters
      this.initAction("/do/jpsurvey/Survey", "saveQuestion");
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.INPUT, result);
     
      // add a new question to the current survey
      this.initAction("/do/jpsurvey/Survey", "saveQuestion");
      this.addParameter("strutsAction", ApsAdminSystemConstants.ADD);
      this.addParameter("questionnaire", true);
      this.addParameter("surveyId", survey.getId());
      this.addParameter("question-it", "La risposta a tutto è: ....");
      this.addParameter("questionId", -1); // NOT NEEDED
      result = this.executeAction();
      assertNotNull(result);
      assertEquals("editSingleQuestion", result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertFalse(survey.getQuestions().isEmpty());
      assertEquals("La risposta a tutto è: ....", survey.getQuestions().get(0).getQuestions().get("it"));
     
      // modify an existing question
      this.initAction("/do/jpsurvey/Survey", "saveQuestion");
      this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
      this.addParameter("questionnaire", true);
      this.addParameter("surveyId", survey.getId());
      this.addParameter("question-it", "42");
      this.addParameter("singleChoice", 1);
      this.addParameter("questionId", survey.getQuestions().get(0).getId());
      result = this.executeAction();
      assertNotNull(result);
      assertEquals(BaseAction.SUCCESS, result);
      survey = this.getSurveyManager().loadSurvey(survey.getId());
      assertFalse(survey.getQuestions().isEmpty());
      assertEquals("42", survey.getQuestions().get(0).getQuestions().get("it"));
    } catch (Throwable t) {
      throw t;
    } finally {
      if (null != survey) {
        this.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.