Search in sources :

Example 61 with QuestionGroupDetail

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

the class LoanPrdActionTest method shouldSetSelectedQuestionGroupsOnSession.

@Test
public void shouldSetSelectedQuestionGroupsOnSession() throws PageExpiredException {
    List<QuestionGroupDetail> questionGroupDetails = asList(getQuestionGroupDetail(1, "QG1", true), getQuestionGroupDetail(2, "QG2", true), getQuestionGroupDetail(3, "QG3", false));
    when(questionnaireServiceFacade.getQuestionGroupDetailForLoanPrd(1)).thenReturn(questionGroupDetails.get(0));
    when(questionnaireServiceFacade.getQuestionGroupDetailForLoanPrd(2)).thenReturn(questionGroupDetails.get(1));
    when(questionnaireServiceFacade.getQuestionGroupDetailForLoanPrd(3)).thenReturn(questionGroupDetails.get(2));
    when(request.getAttribute(Constants.CURRENTFLOWKEY)).thenReturn(FLOW_KEY);
    when(request.getSession()).thenReturn(session);
    when(session.getAttribute(Constants.FLOWMANAGER)).thenReturn(flowManager);
    Flow flow = new Flow();
    when(flowManager.getFlowWithValidation(FLOW_KEY)).thenReturn(flow);
    LoanOfferingBO loanOfferingBO = new LoanProductBuilder().buildForUnitTests();
    loanOfferingBO.setQuestionGroups(getQustionGroups(1, 2, 3));
    loanPrdAction.setSelectedQuestionGroupsOnSession(request, loanOfferingBO, questionnaireServiceFacade);
    List<QuestionGroupDetail> questionGroupDetailList = (List<QuestionGroupDetail>) flow.getObjectFromSession(ProductDefinitionConstants.SELECTEDQGLIST);
    assertThat(questionGroupDetailList, is(notNullValue()));
    assertThat(questionGroupDetailList.size(), is(2));
    assertQuestionGroup(questionGroupDetailList.get(0), 1, "QG1");
    assertQuestionGroup(questionGroupDetailList.get(1), 2, "QG2");
    verify(questionnaireServiceFacade, times(3)).getQuestionGroupDetailForLoanPrd(anyInt());
    verify(request, times(1)).getAttribute(Constants.CURRENTFLOWKEY);
    verify(request, times(1)).getSession();
    verify(session, times(1)).getAttribute(Constants.FLOWMANAGER);
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) LoanProductBuilder(org.mifos.domain.builders.LoanProductBuilder) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Flow(org.mifos.framework.util.helpers.Flow) Test(org.junit.Test)

Example 62 with QuestionGroupDetail

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

the class LoanPrdActionFormTest method getQuestionGroupDetail.

private QuestionGroupDetail getQuestionGroupDetail(int id, String title) {
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail();
    questionGroupDetail.setId(id);
    questionGroupDetail.setTitle(title);
    return questionGroupDetail;
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail)

Example 63 with QuestionGroupDetail

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupDefinitionToExistingQuestionGroup.

@Test
public void shouldMapQuestionGroupDefinitionToExistingQuestionGroup() {
    when(eventSourceDao.retrieveByEventAndSource(anyString(), anyString())).thenReturn(new ArrayList<EventSourceEntity>());
    when(questionDao.getDetails(12)).thenReturn(new QuestionEntity());
    Section section = getSection("S1");
    when(questionGroupDao.getDetails(123)).thenReturn(getQuestionGroup(123, "QG Title", section));
    when(questionGroupDao.retrieveSectionByNameAndQuestionGroupId("S1", 123)).thenReturn(asList(section));
    EventSourceDto eventSourceDto = getEventSource("Create", "Client");
    List<SectionDetail> sectionDetails = asList(getSectionDefinition("S1", 12, TITLE), getSectionDefinition("S2", 0, TITLE));
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(123, TITLE, Arrays.asList(eventSourceDto), sectionDetails, true);
    questionGroupDetail.setActive(false);
    QuestionGroup questionGroup = questionnaireMapper.mapToQuestionGroup(questionGroupDetail);
    assertQuestionGroup(questionGroup, QuestionGroupState.INACTIVE);
    assertThat(questionGroup.isEditable(), is(true));
    verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
    verify(questionDao, times(1)).getDetails(12);
    verify(questionGroupDao, times(1)).getDetails(123);
    verify(questionGroupDao, times(1)).retrieveSectionByNameAndQuestionGroupId("S1", 123);
}
Also used : EventSourceEntity(org.mifos.platform.questionnaire.domain.EventSourceEntity) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionEntity(org.mifos.platform.questionnaire.domain.QuestionEntity) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Section(org.mifos.platform.questionnaire.domain.Section) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 64 with QuestionGroupDetail

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupToQuestionGroupDetail.

@Test
public void shouldMapQuestionGroupToQuestionGroupDetail() {
    QuestionGroup questionGroup = getQuestionGroup("Create", "Client", "S1", "S2");
    QuestionGroupDetail questionGroupDetail = questionnaireMapper.mapToQuestionGroupDetail(questionGroup);
    assertThat(questionGroupDetail, is(notNullValue()));
    assertThat(questionGroupDetail.getTitle(), is(TITLE));
    assertThat(questionGroupDetail.isEditable(), is(true));
    assertThat(questionGroupDetail.isActive(), is(true));
    List<SectionDetail> sectionDetails = questionGroupDetail.getSectionDetails();
    assertThat(sectionDetails, is(notNullValue()));
    assertThat(questionGroupDetail.getSectionDetails().size(), is(2));
    assertThat(questionGroupDetail.getSectionDetails().get(0).getName(), is("S1"));
    assertThat(questionGroupDetail.getSectionDetails().get(1).getName(), is("S2"));
    EventSourceDto eventSourceDto = questionGroupDetail.getEventSources().get(0);
    assertThat(eventSourceDto, is(notNullValue()));
    assertThat(eventSourceDto.getEvent(), is("Create"));
    assertThat(eventSourceDto.getSource(), is("Client"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 65 with QuestionGroupDetail

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

the class QuestionnaireMapperTest method shouldMapQuestionGroupsToQuestionGroupDetails.

@Test
public void shouldMapQuestionGroupsToQuestionGroupDetails() {
    int countOfQuestions = 10;
    List<QuestionGroup> questionGroups = new ArrayList<QuestionGroup>();
    for (int i = 0; i < countOfQuestions; i++) {
        questionGroups.add(getQuestionGroup(1991, TITLE + i, "View", "Loan", QuestionGroupState.ACTIVE, true, getSection(SECTION + i), getSection(SECTION + (i + 1))));
    }
    List<QuestionGroupDetail> questionGroupDetails = questionnaireMapper.mapToQuestionGroupDetails(questionGroups);
    assertThat(questionGroupDetails, is(notNullValue()));
    for (int i = 0; i < countOfQuestions; i++) {
        QuestionGroupDetail questionGroupDetail = questionGroupDetails.get(i);
        assertThat(questionGroupDetail.getTitle(), is(TITLE + i));
        SectionDetail sectionDefinition1 = questionGroupDetail.getSectionDetails().get(0);
        assertThat(sectionDefinition1.getName(), is(SECTION + i));
        List<SectionQuestionDetail> questionDetails1 = sectionDefinition1.getQuestions();
        assertThat(questionDetails1.size(), is(1));
        assertThat(questionDetails1.get(0).getText(), is(SECTION + i));
        assertThat(questionDetails1.get(0).getQuestionType(), is(QuestionType.DATE));
        SectionDetail sectionDefinition2 = questionGroupDetail.getSectionDetails().get(1);
        assertThat(sectionDefinition2.getName(), is(SECTION + (i + 1)));
        List<SectionQuestionDetail> questionDetails2 = sectionDefinition2.getQuestions();
        assertThat(questionDetails2.size(), is(1));
        assertThat(questionDetails2.get(0).getText(), is(SECTION + (i + 1)));
        assertThat(questionDetails2.get(0).getQuestionType(), is(QuestionType.DATE));
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) ArrayList(java.util.ArrayList) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) Test(org.junit.Test)

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