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));
}
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")));
}
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))));
}
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")));
}
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")));
}
Aggregations