}
}
//TODO FARE CONTROLLO NUMERI ERRORI E CAMPI
public void testPublishSurvey() throws Throwable {
Survey poll = this.prepareSurveyForTest(false, false);
Survey questionnaire = this.prepareSurveyForTest(true, false);
Survey actual = null;
String result = null;
try {
this.setUserOnSession("admin");
this.getSurveyManager().saveSurvey(poll);
this.getSurveyManager().saveSurvey(questionnaire);
// publish existing poll
assertTrue(poll.isPublishable());
this.initAction("/do/jpsurvey/Survey", "publishSurvey");
assertEquals(3, poll.getId());
assertFalse(poll.isActive());
this.addParameter("surveyId", poll.getId());
this.addParameter("questionnaire", false);
result = this.executeAction();
assertNotNull(result);
assertEquals(BaseAction.SUCCESS, result);
actual = this.getSurveyManager().loadSurvey(poll.getId());
assertNotNull(actual);
assertTrue(actual.isActive());
// publish existing questionnaire
assertTrue(questionnaire.isPublishable());
this.initAction("/do/jpsurvey/Survey", "publishSurvey");
assertEquals(4, questionnaire.getId());
assertFalse(questionnaire.isActive());
this.addParameter("surveyId", questionnaire.getId());
this.addParameter("questionnaire", true);
result = this.executeAction();
assertNotNull(result);
assertEquals(BaseAction.SUCCESS, result);
actual = this.getSurveyManager().loadSurvey(questionnaire.getId());
assertNotNull(actual);
assertTrue(actual.isActive());
// publish existing questionnaire
this.initAction("/do/jpsurvey/Survey", "publishSurvey");
assertFalse(questionnaire.isActive());
this.addParameter("surveyId", questionnaire.getId());
this.addParameter("questionnaire", true);
result = this.executeAction();
assertNotNull(result);
assertEquals(BaseAction.SUCCESS, result);
actual = this.getSurveyManager().loadSurvey(questionnaire.getId());
assertNotNull(actual);
assertTrue(actual.isActive());
questionnaire.setActive(false);
questionnaire.getQuestions().get(1).getChoices().remove(0);
questionnaire.getQuestions().get(1).getChoices().get(0).setFreeText(false);
getSurveyManager().updateSurvey(questionnaire); // NOT PUBLISHABLE ANYMORE
this.initAction("/do/jpsurvey/Survey", "publishSurvey");
assertFalse(questionnaire.isActive());
this.addParameter("surveyId", questionnaire.getId());
this.addParameter("questionnaire", true);
result = this.executeAction();
assertNotNull(result);
assertEquals(BaseAction.SUCCESS, result);
actual=this.getSurveyManager().loadSurvey(questionnaire.getId());
assertNotNull(actual);
assertFalse(actual.isActive());
assertEquals(2, actual.getQuestions().size());
// enable unknown survey
this.initAction("/do/jpsurvey/Survey", "publishSurvey");
assertEquals(4, questionnaire.getId());
assertFalse(questionnaire.isActive());