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