}
//TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
public void testSaveSurvey() throws Throwable {
String result = null;
Survey poll = this.prepareSurveyForTest(false,false);
Survey questionnaire = this.prepareSurveyForTest(true,false);
SurveyAction action = null;
try {
this.setUserOnSession("admin");
this.getSurveyManager().saveSurvey(poll);
this.getSurveyManager().saveSurvey(questionnaire);
// updating wrong ID
this.initAction("/do/jpsurvey/Survey", "saveSurvey");
this.addParameter("surveyId", "-1");
this.addParameter("questionnaire", true);
this.addParameter("checkCookie", "true");
this.addParameter("description-it", "mucca");
this.addParameter("title-it", "lilla");
this.addParameter("groupName", Group.FREE_GROUP_NAME);
this.addParameter("startDate", "02/06/2008");
this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
result = this.executeAction();
assertNotNull(result);
assertEquals(BaseAction.FAILURE, result);
// editing existing id
this.initAction("/do/jpsurvey/Survey", "saveSurvey");
this.addParameter("surveyId", poll.getId());
assertEquals(3, poll.getId());
this.addParameter("questionnaire", false);
this.addParameter("description-it", "mucca");
this.addParameter("checkCookie", "true");
this.addParameter("title-it", "lilla");
this.addParameter("groupName", Group.FREE_GROUP_NAME);
this.addParameter("startDate", "02/06/2008");
this.addParameter("publicPartialResult", "1");
this.addParameter("publicResult", "1");
this.addParameter("profileUser", "0");
this.addParameter("gatherUserInfo", "0");
this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
this.addParameter("imageDescription-it", "Forza Cagliari");
result = this.executeAction();
assertEquals("listSurveys", result);
// modify existing id with missing parameter
this.initAction("/do/jpsurvey/Survey", "saveSurvey");
this.addParameter("surveyId", questionnaire.getId());
assertEquals(4, questionnaire.getId());
this.addParameter("questionnaire", true);
// this.addParameter("description-it", "mucca"); // oops!
this.addParameter("checkCookie", "true");
this.addParameter("title-it", "lilla");
this.addParameter("groupName", Group.FREE_GROUP_NAME);
this.addParameter("startDate", "02/06/2008");
this.addParameter("publicPartialResult", "1");
this.addParameter("publicResult", "1");
this.addParameter("profileUser", "0");
this.addParameter("strutsAction", ApsAdminSystemConstants.EDIT);
result = this.executeAction();
assertEquals(Action.INPUT, result);
} catch (Throwable t) {
throw t;
} finally {
this.getSurveyManager().deleteSurvey(poll.getId());
this.getSurveyManager().deleteSurvey(questionnaire.getId());
}
}