Search in sources :

Example 16 with QuestionGroupForm

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"));
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 17 with QuestionGroupForm

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")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 18 with QuestionGroupForm

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;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail)

Example 19 with 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));
}
Also used : QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 20 with QuestionGroupForm

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));
}
Also used : QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Aggregations

QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)34 Test (org.junit.Test)31 MessageMatcher (org.mifos.platform.matchers.MessageMatcher)10 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)8 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)6 SectionDetailForm (org.mifos.platform.questionnaire.ui.model.SectionDetailForm)6 ArrayList (java.util.ArrayList)3 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)3 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)3 SystemException (org.mifos.framework.exceptions.SystemException)2 QuestionGroupDetailMatcher (org.mifos.platform.questionnaire.matchers.QuestionGroupDetailMatcher)2 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)2 Question (org.mifos.platform.questionnaire.ui.model.Question)2 QuestionGroupDetailFormMatcher (org.mifos.platform.questionnaire.matchers.QuestionGroupDetailFormMatcher)1 SectionQuestionDetailForm (org.mifos.platform.questionnaire.ui.model.SectionQuestionDetailForm)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1