Search in sources :

Example 1 with QuestionGroupInstanceDto

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

the class QuestionnaireServiceFacadeTest method testSaveQuestionGroupInstance.

@Test
public void testSaveQuestionGroupInstance() {
    QuestionGroupInstanceDto questionGroupInstanceDto = new QuestionGroupInstanceDto();
    when(questionnaireService.saveQuestionGroupInstance(questionGroupInstanceDto)).thenReturn(1234);
    Integer qgInstanceId = questionnaireServiceFacade.saveQuestionGroupInstance(questionGroupInstanceDto);
    assertThat(qgInstanceId, is(1234));
    verify(questionnaireService).saveQuestionGroupInstance(questionGroupInstanceDto);
}
Also used : QuestionGroupInstanceDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto) Test(org.junit.Test)

Example 2 with QuestionGroupInstanceDto

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

the class QuestionnaireMapperTest method shouldMapToQuestionGroupInstance.

@Test
public void shouldMapToQuestionGroupInstance() {
    QuestionGroupInstanceDto questionGroupInstanceDto = getQuestionGroupInstanceDto();
    QuestionGroup questionGroup = new QuestionGroup();
    when(questionGroupDao.getDetails(123)).thenReturn(questionGroup);
    SectionQuestion sectionQuestion = new SectionQuestion();
    when(sectionQuestionDao.getDetails(999)).thenReturn(sectionQuestion);
    QuestionGroupInstance questionGroupInstance = questionnaireMapper.mapToQuestionGroupInstance(questionGroupInstanceDto);
    assertThat(questionGroupInstance, is(notNullValue()));
    assertThat(questionGroupInstance.getCompletedStatus(), is(1));
    assertThat(questionGroupInstance.getCreatorId(), is(111));
    assertThat(questionGroupInstance.getEntityId(), is(12345));
    assertThat(questionGroupInstance.getVersionNum(), is(1));
    assertThat(questionGroupInstance.getQuestionGroup(), is(questionGroup));
    List<QuestionGroupResponse> questionGroupResponses = questionGroupInstance.getQuestionGroupResponses();
    assertThat(questionGroupResponses, is(notNullValue()));
    assertThat(questionGroupResponses.size(), is(1));
    QuestionGroupResponse questionGroupResponse = questionGroupResponses.get(0);
    assertThat(questionGroupResponse.getResponse(), is("Answer1"));
    assertThat(questionGroupResponse.getSectionQuestion(), is(sectionQuestion));
    verify(questionGroupDao).getDetails(123);
    verify(sectionQuestionDao).getDetails(999);
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) SectionQuestion(org.mifos.platform.questionnaire.domain.SectionQuestion) QuestionGroupInstanceDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) QuestionGroup(org.mifos.platform.questionnaire.domain.QuestionGroup) Test(org.junit.Test)

Example 3 with QuestionGroupInstanceDto

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

the class QuestionnaireServiceTest method shouldSaveQuestionGroupInstance.

@Test
public void shouldSaveQuestionGroupInstance() {
    QuestionGroupInstanceDtoBuilder instanceBuilder = new QuestionGroupInstanceDtoBuilder();
    QuestionGroupResponseDtoBuilder responseBuilder = new QuestionGroupResponseDtoBuilder();
    responseBuilder.withResponse("Answer1").withSectionQuestion(999);
    QuestionGroupResponseDto questionGroupResponseDto = responseBuilder.build();
    instanceBuilder.withQuestionGroup(123).withCompleted(true).withCreator(111).withEventSource(1).withEntity(12345).withVersion(1).addResponses(questionGroupResponseDto);
    QuestionGroupInstanceDto questionGroupInstanceDto = instanceBuilder.build();
    when(questionGroupInstanceDao.create(Matchers.<QuestionGroupInstance>any())).thenReturn(789);
    Integer qgInstanceId = questionnaireService.saveQuestionGroupInstance(questionGroupInstanceDto);
    assertThat(qgInstanceId, is(789));
    verify(questionGroupInstanceDao).create(any(QuestionGroupInstance.class));
}
Also used : QuestionGroupResponseDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupResponseDtoBuilder) QuestionGroupInstanceDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto) QuestionGroupInstanceDtoBuilder(org.mifos.platform.questionnaire.builders.QuestionGroupInstanceDtoBuilder) QuestionGroupResponseDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupResponseDto) Test(org.junit.Test)

Example 4 with QuestionGroupInstanceDto

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

the class QuestionnaireServiceIntegrationTest method shouldSaveQuestionGroupInstance.

@Test
@Transactional(rollbackFor = DataAccessException.class)
public void shouldSaveQuestionGroupInstance() {
    String title = "QG1" + currentTimeMillis();
    QuestionGroupDetail qgDetail = defineQuestionGroup(title, "Create", "Client", asList(getSection("S1")), true);
    Integer sectionQuestionId = qgDetail.getSectionDetail(0).getQuestionDetail(0).getId();
    QuestionGroupInstanceDto qgInstanceDto = getQuestionGroupInstanceDto("1234", 121, 567, qgDetail.getId(), sectionQuestionId);
    Integer qgInstanceId = questionnaireService.saveQuestionGroupInstance(qgInstanceDto);
    assertThat(qgInstanceId, is(notNullValue()));
    QuestionGroupInstance instance = questionGroupInstanceDao.getDetails(qgInstanceId);
    assertThat(instance, is(notNullValue()));
    assertThat(instance.getCreatorId(), is(121));
    assertThat(instance.getEntityId(), is(567));
    List<QuestionGroupResponse> questionGroupResponses = instance.getQuestionGroupResponses();
    assertThat(questionGroupResponses, is(notNullValue()));
    assertThat(questionGroupResponses.size(), is(1));
    assertThat(questionGroupResponses.get(0).getResponse(), is("1234"));
}
Also used : QuestionGroupResponse(org.mifos.platform.questionnaire.domain.QuestionGroupResponse) QuestionGroupInstanceDto(org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto) QuestionGroupInstance(org.mifos.platform.questionnaire.domain.QuestionGroupInstance) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Test (org.junit.Test)4 QuestionGroupInstanceDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupInstanceDto)4 QuestionGroupInstance (org.mifos.platform.questionnaire.domain.QuestionGroupInstance)2 QuestionGroupResponse (org.mifos.platform.questionnaire.domain.QuestionGroupResponse)2 QuestionGroupInstanceDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupInstanceDtoBuilder)1 QuestionGroupResponseDtoBuilder (org.mifos.platform.questionnaire.builders.QuestionGroupResponseDtoBuilder)1 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)1 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)1 QuestionGroupResponseDto (org.mifos.platform.questionnaire.service.dtos.QuestionGroupResponseDto)1 Transactional (org.springframework.transaction.annotation.Transactional)1