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) {