Search in sources :

Example 16 with QuestionGroupInstanceDetail

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

the class QuestionnaireServiceTest method shouldGetQuestionGroupInstances.

@Test
public void shouldGetQuestionGroupInstances() {
    List<Section> sections = new ArrayList<Section>();
    List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(3031, 2010, 7, 26, getQuestionGroup(4041, "QG1", sections)), getQuestionGroupInstance(3032, 2010, 7, 26, getQuestionGroup(4042, "QG2", sections)), getQuestionGroupInstance(3033, 2010, 7, 26, getQuestionGroup(4043, "QG3", sections)), getQuestionGroupInstance(3034, 2010, 7, 25, getQuestionGroup(4041, "QG1", sections)), getQuestionGroupInstance(3035, 2010, 7, 25, getQuestionGroup(4042, "QG2", sections)), getQuestionGroupInstance(3036, 2010, 7, 24, getQuestionGroup(4042, "QG2", sections)), getQuestionGroupInstance(3037, 2010, 7, 24, getQuestionGroup(4043, "QG3", sections)));
    when(questionGroupInstanceDao.retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202)).thenReturn(questionGroupInstances);
    when(eventSourceDao.retrieveByEventAndSource("View", "Client")).thenReturn(asList(getEventSourceEntity(202)));
    EventSourceDto eventSourceDto = new EventSourceDto("View", "Client", "View.Client");
    List<QuestionGroupInstanceDetail> instances = questionnaireService.getQuestionGroupInstances(101, eventSourceDto, false, false);
    assertThat(instances, is(notNullValue()));
    assertThat(instances.size(), is(7));
    assertQuestionGroupInstanceDetail(instances.get(0), "QG1", 2010, 7, 26, questionGroupInstances.get(0).getId());
    assertQuestionGroupInstanceDetail(instances.get(1), "QG2", 2010, 7, 26, questionGroupInstances.get(1).getId());
    assertQuestionGroupInstanceDetail(instances.get(2), "QG3", 2010, 7, 26, questionGroupInstances.get(2).getId());
    assertQuestionGroupInstanceDetail(instances.get(3), "QG1", 2010, 7, 25, questionGroupInstances.get(3).getId());
    assertQuestionGroupInstanceDetail(instances.get(4), "QG2", 2010, 7, 25, questionGroupInstances.get(4).getId());
    assertQuestionGroupInstanceDetail(instances.get(5), "QG2", 2010, 7, 24, questionGroupInstances.get(5).getId());
    assertQuestionGroupInstanceDetail(instances.get(6), "QG3", 2010, 7, 24, questionGroupInstances.get(6).getId());
    verify(questionGroupInstanceDao, times(1)).retrieveQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202);
    verify(questionnaireValidator, times(1)).validateForEventSource(eventSourceDto);
    verify(eventSourceDao, times(1)).retrieveByEventAndSource("View", "Client");
}
Also used : ArrayList(java.util.ArrayList) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Test(org.junit.Test)

Example 17 with QuestionGroupInstanceDetail

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

the class QuestionnaireMapperTest method shouldMapToQuestionGroupInstanceDetails.

@Test
public void shouldMapToQuestionGroupInstanceDetails() {
    QuestionGroupInstance questionGroupInstance1 = getQuestionGroupInstance("QG1", 2010, 7, 25);
    QuestionGroupInstance questionGroupInstance2 = getQuestionGroupInstance("QG3", 2009, 2, 12);
    QuestionGroup questionGroup = getQuestionGroup(1991, "QG5", getSectionWithOneMultiSelectQuestion(222, "Section3", "Question3", "Choice1", "Choice2", "Choice3", "Choice4"));
    QuestionGroupInstance questionGroupInstance3 = getQuestionGroupInstanceWithSingleMultiSelectQuestion(101, 3, questionGroup, "Choice1", "Choice3", "Choice4");
    List<QuestionGroupInstance> questionGroupInstances = asList(questionGroupInstance1, questionGroupInstance2, questionGroupInstance3);
    List<QuestionGroupInstanceDetail> questionGroupInstanceDetails = questionnaireMapper.mapToQuestionGroupInstanceDetails(questionGroupInstances);
    assertThat(questionGroupInstanceDetails, is(notNullValue()));
    assertThat(questionGroupInstanceDetails.size(), is(3));
    assertQuestionGroupInstanceDetail(questionGroupInstanceDetails.get(0), "QG1", 2010, 7, 25);
    assertQuestionGroupInstanceDetail(questionGroupInstanceDetails.get(1), "QG3", 2009, 2, 12);
    QuestionGroupInstanceDetail detail = questionGroupInstanceDetails.get(2);
    assertThat(detail.getQuestionGroupTitle(), is("QG5"));
    List<SelectionDetail> values = detail.getQuestionGroupDetail().getSectionDetail(0).getQuestionDetail(0).getSelections();
    assertThat(values, is(notNullValue()));
    assertThat(values.size(), is(3));
    assertThat(values.get(0).getSelectedChoice(), is("Choice1"));
    assertThat(values.get(1).getSelectedChoice(), is("Choice3"));
    assertThat(values.get(2).getSelectedChoice(), is("Choice4"));
}
Also used : SelectionDetail(org.mifos.platform.questionnaire.service.SelectionDetail) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Test(org.junit.Test)

Example 18 with QuestionGroupInstanceDetail

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

the class QuestionnaireMapperTest method shouldMapToEmptyQuestionGroupInstanceDetail.

@Test
public void shouldMapToEmptyQuestionGroupInstanceDetail() {
    QuestionGroupInstanceDetail detail = questionnaireMapper.mapToEmptyQuestionGroupInstanceDetail(getQuestionGroup(1991, "QG1", getSection("Section1")));
    assertThat(detail, is(notNullValue()));
    assertThat(detail.getQuestionGroupDetail().getId(), is(1991));
    assertThat(detail.getQuestionGroupTitle(), is("QG1"));
    assertThat(detail.getId(), is(0));
}
Also used : QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Test(org.junit.Test)

Example 19 with QuestionGroupInstanceDetail

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

the class QuestionnaireServiceTest method shouldGetLatestQuestionGroupInstances.

@Test
public void shouldGetLatestQuestionGroupInstances() {
    List<Section> sections = new ArrayList<Section>();
    List<QuestionGroupInstance> questionGroupInstances = asList(getQuestionGroupInstance(3033, 2010, 7, 26, getQuestionGroup(4043, "QG2", sections)), getQuestionGroupInstance(3034, 2010, 7, 25, getQuestionGroup(4041, "QG1", sections)), getQuestionGroupInstance(3037, 2010, 7, 24, getQuestionGroup(4043, "QG3", sections)));
    when(questionGroupInstanceDao.retrieveLatestQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202)).thenReturn(questionGroupInstances);
    when(eventSourceDao.retrieveByEventAndSource("View", "Client")).thenReturn(asList(getEventSourceEntity(202)));
    EventSourceDto eventSourceDto = new EventSourceDto("View", "Client", "View.Client");
    List<QuestionGroupInstanceDetail> instances = questionnaireService.getQuestionGroupInstances(101, eventSourceDto, false, true);
    assertThat(instances, is(notNullValue()));
    assertThat(instances.size(), is(3));
    assertQuestionGroupInstanceDetail(instances.get(0), "QG2", 2010, 7, 26, questionGroupInstances.get(0).getId());
    assertQuestionGroupInstanceDetail(instances.get(1), "QG1", 2010, 7, 25, questionGroupInstances.get(1).getId());
    assertQuestionGroupInstanceDetail(instances.get(2), "QG3", 2010, 7, 24, questionGroupInstances.get(2).getId());
    verify(questionGroupInstanceDao, times(1)).retrieveLatestQuestionGroupInstancesByEntityIdAndEventSourceId(101, 202);
    verify(questionnaireValidator, times(1)).validateForEventSource(eventSourceDto);
    verify(eventSourceDao, times(1)).retrieveByEventAndSource("View", "Client");
}
Also used : ArrayList(java.util.ArrayList) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Test(org.junit.Test)

Example 20 with QuestionGroupInstanceDetail

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

the class QuestionnaireServiceTest method shouldGetQuestionGroupInstance.

@Test
public void shouldGetQuestionGroupInstance() {
    QuestionGroupInstance questionGroupInstance = getQuestionGroupInstance(12, 1, getQuestionGroup(54, "QG1", asList(getSectionWithQuestions(89, "Sec1", "Ques1"))), "Hello");
    when(questionGroupInstanceDao.getDetails(1212)).thenReturn(questionGroupInstance);
    QuestionGroupInstanceDetail questionGroupInstanceDetail = questionnaireService.getQuestionGroupInstance(1212);
    assertThat(questionGroupInstanceDetail, is(notNullValue()));
    assertThat(questionGroupInstanceDetail.getQuestionGroupTitle(), is("QG1"));
    verify(questionGroupInstanceDao, times(1)).getDetails(1212);
}
Also used : QuestionGroupInstanceDetail(org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail) Test(org.junit.Test)

Aggregations

QuestionGroupInstanceDetail (org.mifos.platform.questionnaire.service.QuestionGroupInstanceDetail)23 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4 Flow (org.mifos.framework.util.helpers.Flow)4 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)4 QuestionnaireServiceFacade (org.mifos.platform.questionnaire.service.QuestionnaireServiceFacade)4 HashSet (java.util.HashSet)3 LoanBO (org.mifos.accounts.loan.business.LoanBO)3 LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)3 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)3 MessageLookup (org.mifos.application.master.MessageLookup)3 CustomFieldDefinitionEntity (org.mifos.application.master.business.CustomFieldDefinitionEntity)3 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)3 LoanActivityDto (org.mifos.dto.domain.LoanActivityDto)3 ValueListElement (org.mifos.dto.domain.ValueListElement)3 LoanInformationDto (org.mifos.dto.screen.LoanInformationDto)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 UserContext (org.mifos.security.util.UserContext)3