Search in sources :

Example 31 with QuestionGroupForm

use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.

the class QuestionGroupControllerTest method testAddSectionForSuccessWhenQuestionTitleProvidedWithAllBlanks.

@Test
public void testAddSectionForSuccessWhenQuestionTitleProvidedWithAllBlanks() throws Exception {
    QuestionGroupForm questionGroup = new QuestionGroupForm();
    questionGroup.setQuestionPool(new ArrayList<SectionQuestionDetail>(asList(getSectionQuestionDetail(1, "Q1"), getSectionQuestionDetail(2, "Q2"))));
    questionGroup.setSelectedQuestionIds(asList("1", "2"));
    questionGroup.setSectionName("        ");
    String result = questionGroupController.addSection(questionGroup, requestContext);
    assertThat(questionGroup.getSections().size(), Is.is(1));
    assertThat(questionGroup.getSections().get(0).getName(), Is.is("Misc"));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().size(), Is.is(2));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().get(0).getText(), Is.is("Q1"));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().get(1).getText(), Is.is("Q2"));
    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 32 with QuestionGroupForm

use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.

the class QuestionGroupControllerTest method testAddQuestionForDuplicateTitle.

@Test
public void testAddQuestionForDuplicateTitle() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(TITLE);
    questionGroupForm.getCurrentQuestion().setType("freeText");
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE)).thenReturn(true);
    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.duplicate")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 33 with QuestionGroupForm

use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.

the class QuestionGroupControllerTest method testAddQuestion.

@Test
public void testAddQuestion() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.getCurrentQuestion().setText("Question1");
    questionGroupForm.getCurrentQuestion().setType("freeText");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionGroupController.addQuestion(questionGroupForm, requestContext);
    assertThat(result, is("success"));
    verify(requestContext, times(1)).getMessageContext();
}
Also used : QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 34 with QuestionGroupForm

use of org.mifos.platform.questionnaire.ui.model.QuestionGroupForm in project head by mifos.

the class QuestionGroupControllerTest method testAddSectionsSuccessWhenSectionNameIsNotProvided.

@Test
public void testAddSectionsSuccessWhenSectionNameIsNotProvided() {
    QuestionGroupForm questionGroup = new QuestionGroupForm();
    questionGroup.setQuestionPool(new ArrayList<SectionQuestionDetail>(asList(getSectionQuestionDetail(1, "Q1"), getSectionQuestionDetail(2, "Q2"))));
    questionGroup.setSelectedQuestionIds(asList("2"));
    String result = questionGroupController.addSection(questionGroup, requestContext);
    assertThat(questionGroup.getSections().size(), Is.is(1));
    assertThat(questionGroup.getSections().get(0).getName(), Is.is("Misc"));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().size(), Is.is(1));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().get(0).getText(), Is.is("Q2"));
    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)

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