Search in sources :

Example 1 with QuestionGroupForm

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

the class QuestionGroupController method getQuestionGroup.

@RequestMapping("/viewQuestionGroupDetail.ftl")
public String getQuestionGroup(ModelMap model, HttpServletRequest httpServletRequest) {
    String questionGroupId = httpServletRequest.getParameter("questionGroupId");
    try {
        if (isInvalidNumber(questionGroupId)) {
            model.addAttribute("error_message_code", QuestionnaireConstants.INVALID_QUESTION_GROUP_ID);
        } else {
            QuestionGroupDetail questionGroupDetail = questionnaireServiceFacade.getQuestionGroupDetail(Integer.valueOf(questionGroupId));
            QuestionGroupForm questionGroupForm = new QuestionGroupForm(questionGroupDetail);
            model.addAttribute("questionGroupDetail", questionGroupForm);
            model.addAttribute("eventSources", getAllQgEventSources());
        }
    } catch (SystemException e) {
        //TODO: move mifosLogManager to common after dependency resolution
        //MifosLogManager.getLogger(LoggerConstants.ROOTLOGGER).error(e.getMessage(), e);
        model.addAttribute("error_message_code", QuestionnaireConstants.QUESTION_GROUP_NOT_FOUND);
    }
    return "viewQuestionGroupDetail";
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SystemException(org.mifos.framework.exceptions.SystemException) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with QuestionGroupForm

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

the class QuestionGroupControllerTest method getQuestionGroupForm.

private QuestionGroupForm getQuestionGroupForm(String title, String eventSourceId, String... sectionNames) {
    QuestionGroupForm questionGroup = new QuestionGroupForm();
    questionGroup.setTitle(title);
    questionGroup.setEventSourceIds(Arrays.asList(eventSourceId));
    for (String sectionName : sectionNames) {
        questionGroup.setSectionName(sectionName);
        questionGroup.addCurrentSection();
    }
    return questionGroup;
}
Also used : QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)

Example 3 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testAddQuestionForEmptyType.

@Test
public void testAddQuestionForEmptyType() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(TITLE);
    questionGroupForm.getCurrentQuestion().setType(null);
    when(messageContext.hasErrorMessages()).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("NotNull.QuestionGroupForm.currentQuestion.type")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 4 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testAddSectionWithoutQuestions.

@Test
public void testAddSectionWithoutQuestions() throws Exception {
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    QuestionGroupForm questionGroup = new QuestionGroupForm();
    questionGroup.setTitle("title");
    questionGroup.setSectionName("sectionName");
    String result = questionGroupController.addSection(questionGroup, requestContext);
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.no.question.in.section")));
    assertThat(result, Is.is("failure"));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 5 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testAddQuestionForInvalidNumericBounds.

@Test
public void testAddQuestionForInvalidNumericBounds() {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "Default");
    questionGroupForm.setValidator(validator);
    questionGroupForm.getCurrentQuestion().setText(TITLE);
    questionGroupForm.getCurrentQuestion().setType("number");
    questionGroupForm.getCurrentQuestion().setNumericMin(100);
    questionGroupForm.getCurrentQuestion().setNumericMax(10);
    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(QuestionnaireConstants.INVALID_NUMERIC_BOUNDS)));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) 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