Search in sources :

Example 36 with QuestionGroupDetail

use of org.mifos.platform.questionnaire.service.QuestionGroupDetail 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 37 with QuestionGroupDetail

use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.

the class QuestionGroupControllerTest method getQuestionGroupDetail.

private QuestionGroupDetail getQuestionGroupDetail(String title, String event, String source, String... sectionNames) {
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail();
    questionGroupDetail.setTitle(title);
    questionGroupDetail.setEventSources(Arrays.asList(new EventSourceDto(event, source, null)));
    List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
    for (String sectionName : sectionNames) {
        SectionDetail sectionDetail = new SectionDetail();
        sectionDetail.setName(sectionName);
        sectionDetails.add(sectionDetail);
    }
    questionGroupDetail.setSectionDetails(sectionDetails);
    return questionGroupDetail;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 38 with QuestionGroupDetail

use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.

the class QuestionGroupControllerTest method getQuestionGroupDetail.

private QuestionGroupDetail getQuestionGroupDetail(int questionGroupId, String title, String event, String source, boolean active, boolean editable, String... sectionNames) {
    List<SectionDetail> sectionDetails = new ArrayList<SectionDetail>();
    for (String sectionName : sectionNames) {
        SectionDetail sectionDetail = new SectionDetail();
        sectionDetail.setName(sectionName);
        sectionDetails.add(sectionDetail);
    }
    return new QuestionGroupDetail(questionGroupId, title, Arrays.asList(new EventSourceDto(event, source, null)), sectionDetails, editable, active);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto)

Example 39 with QuestionGroupDetail

use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.

the class CreateSavingsAccountFormBeanTest method validateAnswerQuestionGroupStepMissingMandatoryResponseShouldFail.

@Test
public void validateAnswerQuestionGroupStepMissingMandatoryResponseShouldFail() {
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    formBean.setQuestionGroups(questionGroups);
    doThrow(validationException).when(questionnaireServiceFacade).validateResponses(formBean.getQuestionGroups());
    formBean.validateAnswerQuestionGroupStep(validationContext);
    MessageContext messageContext = validationContext.getMessageContext();
    Message[] messages = messageContext.getAllMessages();
    Assert.assertEquals(1, messages.length);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) Message(org.springframework.binding.message.Message) ArrayList(java.util.ArrayList) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 40 with QuestionGroupDetail

use of org.mifos.platform.questionnaire.service.QuestionGroupDetail in project head by mifos.

the class QuestionnaireFlowAdapter method saveResponses.

public void saveResponses(HttpServletRequest request, QuestionResponseCapturer form, int associateWithId) {
    List<QuestionGroupDetail> questionResponses = form.getQuestionGroups();
    if (CollectionUtils.isNotEmpty(questionResponses)) {
        QuestionnaireServiceFacade questionnaireServiceFacade = serviceLocator.getService(request);
        //MifosUser loggedinUser = ((MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
        if (questionnaireServiceFacade != null) {
            UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
            Integer eventSourceId = questionnaireServiceFacade.getEventSourceId(event, source);
            QuestionGroupDetails questionGroupDetails = new QuestionGroupDetails(userContext.getId(), associateWithId, eventSourceId, questionResponses);
            questionnaireServiceFacade.saveResponses(questionGroupDetails);
        }
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) UserContext(org.mifos.security.util.UserContext) QuestionGroupDetails(org.mifos.platform.questionnaire.service.QuestionGroupDetails) QuestionnaireServiceFacade(org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade)

Aggregations

QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)74 Test (org.junit.Test)43 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)25 ArrayList (java.util.ArrayList)23 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)15 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)11 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)11 List (java.util.List)8 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)8 ValidationException (org.mifos.platform.validations.ValidationException)7 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)6 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)6 SystemException (org.mifos.framework.exceptions.SystemException)5 Arrays.asList (java.util.Arrays.asList)4 QuestionGroupReference (org.mifos.accounts.productdefinition.business.QuestionGroupReference)4 LoanProductBuilder (org.mifos.domain.builders.LoanProductBuilder)4 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 Transactional (org.springframework.transaction.annotation.Transactional)4 HashMap (java.util.HashMap)3