Search in sources :

Example 11 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testRemoveQuestionFromSection.

@Test
public void testRemoveQuestionFromSection() {
    QuestionGroupForm questionGroup = new QuestionGroupForm();
    List<SectionDetailForm> sections = new ArrayList<SectionDetailForm>();
    sections.add(getSectionSectionDetailForm("sectionName", new ArrayList<SectionQuestionDetail>(asList(getSectionQuestionDetail(1, "Q1"), getSectionQuestionDetail(2, "Q2")))));
    questionGroup.setSections(sections);
    assertThat(questionGroup.getSections().size(), CoreMatchers.is(1));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().size(), CoreMatchers.is(2));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().get(0).getText(), CoreMatchers.is("Q1"));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().get(1).getText(), CoreMatchers.is("Q2"));
    questionGroupController.deleteQuestion(questionGroup, "sectionName", "1");
    assertThat(questionGroup.getSections().size(), CoreMatchers.is(1));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().size(), CoreMatchers.is(1));
    assertThat(questionGroup.getSections().get(0).getSectionQuestions().get(0).getText(), CoreMatchers.is("Q2"));
    questionGroupController.deleteQuestion(questionGroup, "sectionName", "2");
    assertThat(questionGroup.getSections().size(), CoreMatchers.is(0));
}
Also used : SectionDetailForm(org.mifos.platform.questionnaire.ui.model.SectionDetailForm) ArrayList(java.util.ArrayList) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 12 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testCreateQuestionGroupForFailureWhenQuestionGroupAppliesToNotProvided.

@Test
public void testCreateQuestionGroupForFailureWhenQuestionGroupAppliesToNotProvided() throws Exception {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, QuestionnaireConstants.DEFAULT_APPLIES_TO_OPTION, "Section");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true);
    assertThat(result, Is.is(notNullValue()));
    assertThat(result, Is.is("failure"));
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.appliesTo.mandatory")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 13 with QuestionGroupForm

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

the class QuestionGroupControllerTest method shouldGetQuestionGroupById.

@Test
public void shouldGetQuestionGroupById() throws SystemException {
    int questionGroupId = 1;
    QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(questionGroupId, TITLE, "S1", "S2", "S3");
    when(questionnaireServiceFacade.getQuestionGroupDetail(questionGroupId)).thenReturn(questionGroupDetail);
    when(httpServletRequest.getParameter("questionGroupId")).thenReturn(Integer.toString(questionGroupId));
    String view = questionGroupController.getQuestionGroup(model, httpServletRequest);
    assertThat(view, Is.is("viewQuestionGroupDetail"));
    verify(questionnaireServiceFacade).getQuestionGroupDetail(questionGroupId);
    verify(questionnaireServiceFacade, times(1)).getAllEventSources();
    verify(httpServletRequest, times(1)).getParameter("questionGroupId");
    verify(model).addAttribute(Matchers.eq("questionGroupDetail"), argThat(new QuestionGroupDetailFormMatcher(new QuestionGroupForm(questionGroupDetail))));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupDetailFormMatcher(org.mifos.platform.questionnaire.matchers.QuestionGroupDetailFormMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 14 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testAddQuestionForEmptyTitle.

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

Example 15 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testCreateQuestionGroupFailure.

@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testCreateQuestionGroupFailure() throws Exception {
    QuestionGroupForm questionGroupForm = getQuestionGroupForm(TITLE, "Create.Client", "S1", "S2");
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    doThrow(new SystemException("questionnaire.error.duplicate.question.found.in.section")).when(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject());
    String result = questionGroupController.defineQuestionGroup(questionGroupForm, requestContext, true);
    assertThat(result, Is.is("failure"));
    verify(questionnaireServiceFacade).createActiveQuestionGroup(Matchers.<QuestionGroupDetail>anyObject());
    verify(requestContext).getMessageContext();
    verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.error.duplicate.question.found.in.section")));
}
Also used : MessageMatcher(org.mifos.platform.matchers.MessageMatcher) SystemException(org.mifos.framework.exceptions.SystemException) 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