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