Search in sources :

Example 6 with QuestionGroupForm

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

the class QuestionGroupControllerTest method shouldGetAllSectionQuestionsWithoutExcludedQuestions.

@Test
public void shouldGetAllSectionQuestionsWithoutExcludedQuestions() {
    List<Integer> excludedQuestions = asList(3);
    List<QuestionDetail> questionDetails = asList(getQuestionDetail(1, "Q1", QuestionType.NUMERIC), getQuestionDetail(2, "Q2", QuestionType.DATE));
    when(questionnaireServiceFacade.getAllActiveQuestions(excludedQuestions)).thenReturn(questionDetails);
    QuestionGroupForm questionGroupForm = getQuestionGroupFormWithOneSectionQuestion("QG1", 3);
    List<SectionQuestionDetail> sectionQuestions = questionGroupController.getAllSectionQuestions(questionGroupForm);
    assertThat(sectionQuestions, Is.is(notNullValue()));
    assertThat(sectionQuestions.size(), Is.is(2));
    assertThat(sectionQuestions.get(0).getQuestionId(), Is.is(1));
    assertThat(sectionQuestions.get(0).getText(), Is.is("Q1"));
    assertThat(sectionQuestions.get(1).getQuestionId(), Is.is(2));
    assertThat(sectionQuestions.get(1).getText(), Is.is("Q2"));
    verify(questionnaireServiceFacade).getAllActiveQuestions(excludedQuestions);
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 7 with QuestionGroupForm

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

the class QuestionGroupControllerTest method testEditQuestionGroupSuccess.

@Test
public void testEditQuestionGroupSuccess() throws Exception {
    QuestionGroupForm questionGroup = getQuestionGroupForm("   " + TITLE + " ", "Create.Client", "S1", "S2");
    String result = questionGroupController.defineQuestionGroup(questionGroup, requestContext, false);
    assertThat(result, Is.is("success"));
    QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(TITLE, "Create", "Client", "S1", "S2");
    questionGroupDetail.setActive(false);
    verify(questionnaireServiceFacade).createQuestionGroup(argThat(new QuestionGroupDetailMatcher(questionGroupDetail)));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupDetailMatcher(org.mifos.platform.questionnaire.matchers.QuestionGroupDetailMatcher) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 8 with QuestionGroupForm

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

the class QuestionGroupFormTest method testAddCurrentSection.

@Test
public void testAddCurrentSection() {
    QuestionGroupForm questionGroupForm = new QuestionGroupForm();
    questionGroupForm.setQuestionPool(new ArrayList<SectionQuestionDetail>(asList(getSectionQuestionDetail(1, "Q1", true), getSectionQuestionDetail(2, "Q2", false))));
    questionGroupForm.setSelectedQuestionIds(asList("1"));
    String title = "title";
    questionGroupForm.setTitle(title);
    String sectionName = "sectionName";
    questionGroupForm.setSectionName(sectionName);
    questionGroupForm.addCurrentSection();
    List<SectionDetailForm> sectionDetailForms = questionGroupForm.getSections();
    assertThat(sectionDetailForms.size(), is(1));
    String nameOfAddedSection = questionGroupForm.getSections().get(0).getName();
    assertThat(nameOfAddedSection, is(sectionName));
    List<SectionQuestionDetailForm> questions = sectionDetailForms.get(0).getSectionQuestions();
    assertThat(questions.size(), is(1));
    assertThat(questions.get(0).getText(), is("Q1"));
    assertThat(questions.get(0).isMandatory(), is(true));
    assertThat(questionGroupForm.getSectionName(), is(nameOfAddedSection));
    assertNotSame(questionGroupForm.getSelectedQuestionIds().size(), is(0));
    questionGroupForm.setSelectedQuestionIds(asList("2"));
    questionGroupForm.setSectionName(sectionName);
    questionGroupForm.addCurrentSection();
    sectionDetailForms = questionGroupForm.getSections();
    assertThat(sectionDetailForms.size(), is(1));
    nameOfAddedSection = questionGroupForm.getSections().get(0).getName();
    assertThat(nameOfAddedSection, is(sectionName));
    questions = sectionDetailForms.get(0).getSectionQuestions();
    assertThat(questions.size(), is(2));
    assertThat(questions.get(0).getText(), is("Q1"));
    assertThat(questions.get(0).isMandatory(), is(true));
    assertThat(questions.get(1).getText(), is("Q2"));
    assertThat(questions.get(1).isMandatory(), is(false));
    assertThat(questionGroupForm.getSectionName(), is(nameOfAddedSection));
    assertNotSame(questionGroupForm.getSelectedQuestionIds().size(), is(0));
}
Also used : SectionDetailForm(org.mifos.platform.questionnaire.ui.model.SectionDetailForm) SectionQuestionDetailForm(org.mifos.platform.questionnaire.ui.model.SectionQuestionDetailForm) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) Test(org.junit.Test)

Example 9 with QuestionGroupForm

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

the class QuestionGroupFormTest method shouldSetEventSource.

@Test
public void shouldSetEventSource() {
    QuestionGroupForm questionGroupForm;
    questionGroupForm = new QuestionGroupForm();
    questionGroupForm.setEventSources(Arrays.asList(new EventSourceDto("Create", "Client", null)));
    assertThat(questionGroupForm.getEventSourceIds().get(0), is("Create.Client"));
    questionGroupForm = new QuestionGroupForm();
    questionGroupForm.setEventSources(null);
    assertThat(questionGroupForm.getEventSourceIds().size(), is(0));
    questionGroupForm = new QuestionGroupForm();
    questionGroupForm.setEventSources(Arrays.asList(new EventSourceDto("", null, null)));
    assertThat(questionGroupForm.getEventSourceIds().size(), is(0));
}
Also used : QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 10 with QuestionGroupForm

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

the class QuestionGroupFormTest method removeSection.

@Test
public void removeSection() {
    QuestionGroupForm questionGroupForm = new QuestionGroupForm();
    List<SectionDetailForm> sections = new ArrayList<SectionDetailForm>();
    String sectionName = "sectionName";
    setupSection(questionGroupForm, sections, sectionName);
    questionGroupForm.removeSection(sectionName);
    assertThatQuestionFormHasNoSection(questionGroupForm);
}
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)

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