use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.
the class QuestionGroupControllerTest method testAddSectionForSuccess.
@Test
public void testAddSectionForSuccess() throws Exception {
QuestionGroupForm questionGroup = new QuestionGroupForm();
questionGroup.setQuestionPool(new ArrayList<SectionQuestionDetail>(asList(getSectionQuestionDetail(1, "Q1"), getSectionQuestionDetail(2, "Q2"))));
questionGroup.setSelectedQuestionIds(asList("1"));
questionGroup.setTitle("title");
questionGroup.setSectionName("sectionName");
String result = questionGroupController.addSection(questionGroup, requestContext);
assertThat(questionGroup.getSections().size(), Is.is(1));
assertThat(questionGroup.getSections().get(0).getName(), Is.is("sectionName"));
assertThat(questionGroup.getSections().get(0).getSectionQuestions().size(), Is.is(1));
assertThat(questionGroup.getSections().get(0).getSectionQuestions().get(0).getText(), Is.is("Q1"));
assertThat(result, Is.is("success"));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.
the class QuestionGroupControllerTest method testAddQuestionForInvalidAnswerChoices.
@Test
public void testAddQuestionForInvalidAnswerChoices() {
QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
questionGroupForm.setValidator(validator);
questionGroupForm.getCurrentQuestion().setText(TITLE);
questionGroupForm.getCurrentQuestion().setType("singleSelect");
questionGroupForm.getCurrentQuestion().setCurrentChoice("Choice1");
questionGroupForm.getCurrentQuestion().addAnswerChoice();
when(requestContext.getMessageContext()).thenReturn(messageContext);
String result = questionGroupController.addQuestion(questionGroupForm, requestContext);
assertThat(result, is("failure"));
verify(requestContext, times(1)).getMessageContext();
verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.question.choices")));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.
the class QuestionGroupControllerTest method getQuestionGroupFormWithOneSectionQuestion.
private QuestionGroupForm getQuestionGroupFormWithOneSectionQuestion(String qgTitle, int questionId) {
QuestionGroupForm questionGroupForm = getQuestionGroupForm(qgTitle, "Create.Client");
SectionDetail sectionDetail = new SectionDetail();
sectionDetail.setName("Sec1");
sectionDetail.setQuestionDetails(asList(new SectionQuestionDetail(getQuestionDetail(questionId, "Q3", QuestionType.FREETEXT), true)));
questionGroupForm.getQuestionGroupDetail().getSectionDetails().add(sectionDetail);
return questionGroupForm;
}
use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.
the class QuestionGroupFormTest method testIsDuplicateTitle.
@Test
public void testIsDuplicateTitle() {
QuestionGroupForm questionGroupForm = new QuestionGroupForm();
String title = "title";
questionGroupForm.setTitle(title);
String sectionName = "SectionWithNewQuestion";
Question currentQuestion = new Question(new QuestionDetail());
currentQuestion.setText(" Question1 ");
currentQuestion.setType("freeText");
questionGroupForm.setCurrentQuestion(currentQuestion);
questionGroupForm.setAddQuestionFlag(true);
questionGroupForm.setSectionName(sectionName);
questionGroupForm.addCurrentSection();
questionGroupForm.getCurrentQuestion().setText("Question2 ");
questionGroupForm.addCurrentSection();
assertThat(questionGroupForm.isDuplicateText("Question1"), is(true));
}
use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.
the class QuestionGroupFormTest method testAddCurrentSectionWhenSectionNameIsBlank.
@Test
public void testAddCurrentSectionWhenSectionNameIsBlank() {
QuestionGroupForm questionGroupForm = new QuestionGroupForm();
String title = "title";
questionGroupForm.setTitle(title);
String sectionName = " ";
questionGroupForm.setSectionName(sectionName);
questionGroupForm.addCurrentSection();
assertThat(questionGroupForm.getSections().size(), is(1));
String nameOfAddedSection = questionGroupForm.getSections().get(0).getName();
assertThat(nameOfAddedSection, is("Misc"));
assertThat(questionGroupForm.getSectionName(), is(nameOfAddedSection));
}
Aggregations