Search in sources :

Example 1 with QuestionGroupDto

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

the class QuestionnaireServiceFacadeTest method testCreateQuestionGroupUsingDTO.

@Test
public void testCreateQuestionGroupUsingDTO() {
    QuestionGroupDto questionGroupDto = new QuestionGroupDto();
    questionnaireServiceFacade.createQuestionGroup(questionGroupDto);
    verify(questionnaireService).defineQuestionGroup(questionGroupDto);
}
Also used : QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Test(org.junit.Test)

Example 2 with QuestionGroupDto

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

the class QuestionnaireServiceImpl method uploadPPIQuestionGroup.

@Override
public Integer uploadPPIQuestionGroup(String country) {
    String ppiXmlForCountry = ppiSurveyLocator.getPPIUploadFileForCountry(country);
    QuestionGroupDto questionGroupDto = questionGroupDefinitionParser.parse(ppiXmlForCountry);
    // according to MIFOS-4146 all uploaded QG and questions should be active
    activateQGWithQuestions(questionGroupDto);
    if (questionGroupDto.isPpi()) {
        // according to MIFOS-4149 PPI questions should be editable
        makePPIQuestionsNotEditable(questionGroupDto);
    }
    return defineQuestionGroup(questionGroupDto, false);
}
Also used : QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)

Example 3 with QuestionGroupDto

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

the class QuestionnaireMapperTest method shouldMapToQuestionGroupFromDto.

@Test
public void shouldMapToQuestionGroupFromDto() {
    when(eventSourceDao.retrieveByEventAndSource("Create", "Client")).thenReturn(asList(getEventSourceEntity("Create", "Client")));
    QuestionDto question1 = new QuestionDtoBuilder().withText("Ques1").withMandatory(true).withType(QuestionType.FREETEXT).withOrder(1).build();
    ChoiceDto choice1 = new ChoiceDetailBuilder().withValue("Ch1").withOrder(1).build();
    ChoiceDto choice2 = new ChoiceDetailBuilder().withValue("Ch2").withOrder(2).build();
    ChoiceDto choice3 = new ChoiceDetailBuilder().withValue("Ch3").withOrder(3).build();
    QuestionDto question2 = new QuestionDtoBuilder().withText("Ques2").withType(QuestionType.SINGLE_SELECT).addChoices(choice1, choice2, choice3).withOrder(2).build();
    SectionDto section1 = new SectionDtoBuilder().withName("Sec1").withOrder(1).addQuestions(question1, question2).build();
    QuestionGroupDto questionGroupDto = new QuestionGroupDtoBuilder().withTitle("QG1").withEventSource("Create", "Client").addSections(section1).build();
    assertQuestionGroupEntity(questionnaireMapper.mapToQuestionGroup(questionGroupDto));
    verify(eventSourceDao, times(1)).retrieveByEventAndSource(anyString(), anyString());
}
Also used : SectionDtoBuilder(org.mifos.platform.questionnaire.builders.SectionDtoBuilder) QuestionDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionDtoBuilder) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) QuestionDto(org.mifos.platform.questionnaire.service.dtos.QuestionDto) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) ChoiceDetailBuilder(org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder) QuestionGroupDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder) Test(org.junit.Test)

Example 4 with QuestionGroupDto

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

the class QuestionGroupDefinitionParserTest method shouldParseQuestionDefinitionXml.

@Test
public void shouldParseQuestionDefinitionXml() throws Exception {
    QuestionGroupDefinitionParser questionGroupDefinitionParser = new QuestionGroupDefinitionParserImpl();
    String questionGroupDefXml = "/org/mifos/platform/questionnaire/QuestionGroupDefinition.xml";
    InputStream inputStream = getClass().getResourceAsStream(questionGroupDefXml);
    QuestionGroupDto questionGroupDto = questionGroupDefinitionParser.parse(inputStream);
    assertQuestionGroupDto(questionGroupDto);
    EventSourceDto eventSourceDto = questionGroupDto.getEventSourceDtos().get(0);
    assertEventSource(eventSourceDto);
    List<SectionDto> sectionDtos = questionGroupDto.getSections();
    assertSections(sectionDtos);
}
Also used : InputStream(java.io.InputStream) SectionDto(org.mifos.platform.questionnaire.service.dtos.SectionDto) QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Example 5 with QuestionGroupDto

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

the class QuestionnaireServiceTest method shouldUploadPPIQuestionGroup.

@Test
public void shouldUploadPPIQuestionGroup() throws IOException {
    String ppiXmlPath = "org/mifos/platform/questionnaire/PPISurveyINDIA.xml";
    String country = "India";
    when(ppiSurveyLocator.getPPIUploadFileForCountry(country)).thenReturn(ppiXmlPath);
    QuestionGroupDto questionGroupDto = getQuestionGroupDto();
    when(questionGroupDefinitionParser.parse(ppiXmlPath)).thenReturn(questionGroupDto);
    questionnaireService.uploadPPIQuestionGroup(country);
    verify(ppiSurveyLocator).getPPIUploadFileForCountry(country);
    verify(questionGroupDefinitionParser).parse(ppiXmlPath);
    verify(questionnaireValidator).validateForDefineQuestionGroup(questionGroupDto, false);
    verify(questionGroupDao).create(any(QuestionGroup.class));
}
Also used : QuestionGroupDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

QuestionGroupDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupDto)40 Test (org.junit.Test)39 ValidationException (org.mifos.platform.validations.ValidationException)30 Arrays.asList (java.util.Arrays.asList)27 List (java.util.List)27 QuestionDto (org.mifos.platform.questionnaire.service.dtos.QuestionDto)4 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)3 SectionDto (org.mifos.platform.questionnaire.service.dtos.SectionDto)3 ChoiceDetailBuilder (org.mifos.platform.questionnaire.builders.ChoiceDetailBuilder)2 QuestionDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionDtoBuilder)2 QuestionGroupDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupDtoBuilder)2 SectionDtoBuilder (org.mifos.platform.questionnaire.builders.SectionDtoBuilder)2 InputStream (java.io.InputStream)1 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Transactional (org.springframework.transaction.annotation.Transactional)1