Search in sources :

Example 66 with QuestionDetail

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

the class QuestionGroupInstanceDaoIntegrationTest method getSection.

private SectionDetail getSection(String name) throws SystemException {
    SectionDetail section = new SectionDetail();
    section.setName(name);
    String questionTitle = "Question" + name + currentTimeMillis();
    QuestionDetail questionDetail = defineQuestion(questionTitle, QuestionType.NUMERIC);
    section.addQuestion(new SectionQuestionDetail(questionDetail, true));
    return section;
}
Also used : SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail)

Example 67 with QuestionDetail

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

the class QuestionControllerTest method testAddQuestionWhenTitleIsEditedToOneAlreadyInDB.

@Test
public void testAddQuestionWhenTitleIsEditedToOneAlreadyInDB() throws Exception {
    Question currentQuestion = new Question();
    QuestionDetail questionDetail = new QuestionDetail();
    questionDetail.setText(TITLE);
    currentQuestion.setQuestionDetail(questionDetail);
    QuestionForm questionForm = new QuestionForm();
    questionForm.setCurrentQuestion(currentQuestion);
    questionForm.getCurrentQuestion().setText(TITLE + 1);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE + 1)).thenReturn(true);
    String result = questionController.addQuestion(questionForm, requestContext, false);
    Assert.assertThat(questionForm.getQuestions().size(), is(0));
    Assert.assertThat(result, is("failure"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 68 with QuestionDetail

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

the class QuestionControllerTest method testAddQuestionWhenTitleIsEdited.

@Test
public void testAddQuestionWhenTitleIsEdited() throws Exception {
    Question currentQuestion = new Question();
    QuestionDetail questionDetail = new QuestionDetail();
    questionDetail.setText(TITLE);
    questionDetail.setType(QuestionType.SINGLE_SELECT);
    questionDetail.setAnswerChoices(new ArrayList<ChoiceDto>(Arrays.asList(new ChoiceDto("choice1"), new ChoiceDto("choice2"))));
    currentQuestion.setQuestionDetail(questionDetail);
    currentQuestion.setCurrentChoice("choice3");
    currentQuestion.addAnswerChoice();
    QuestionForm questionForm = new QuestionForm();
    questionForm.setCurrentQuestion(currentQuestion);
    questionForm.getCurrentQuestion().setText(TITLE + 1);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE + 1)).thenReturn(false);
    String result = questionController.addQuestion(questionForm, requestContext, false);
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    Assert.assertThat(questionForm.getQuestions().get(0).getInitialNumberOfChoices(), is(2));
    Assert.assertThat(questionForm.getQuestions().get(0).getChoices().size(), is(3));
    Assert.assertThat(result, is("success"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) ChoiceDto(org.mifos.platform.questionnaire.service.dtos.ChoiceDto) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 69 with QuestionDetail

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

the class QuestionControllerTest method testAddQuestionDuringEditOperationWhereTitleIsUnchanged.

@Test
public void testAddQuestionDuringEditOperationWhereTitleIsUnchanged() throws Exception {
    Question currentQuestion = new Question();
    QuestionDetail questionDetail = new QuestionDetail();
    questionDetail.setText(TITLE);
    currentQuestion.setQuestionDetail(questionDetail);
    QuestionForm questionForm = new QuestionForm();
    questionForm.setCurrentQuestion(currentQuestion);
    when(requestContext.getMessageContext()).thenReturn(messageContext);
    when(questionnaireServiceFacade.isDuplicateQuestion(TITLE)).thenReturn(true);
    String result = questionController.addQuestion(questionForm, requestContext, false);
    Assert.assertThat(questionForm.getQuestions().size(), is(1));
    Assert.assertThat(result, is("success"));
}
Also used : QuestionForm(org.mifos.platform.questionnaire.ui.model.QuestionForm) Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 70 with QuestionDetail

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

the class QuestionFormTest method getQuestion.

private Question getQuestion(String title) {
    Question question = new Question(new QuestionDetail());
    question.setText(title);
    return question;
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail)

Aggregations

QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)72 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)55 Test (org.junit.Test)44 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)24 Question (org.mifos.platform.questionnaire.ui.model.Question)16 ChoiceDto (org.mifos.platform.questionnaire.service.dtos.ChoiceDto)13 ArrayList (java.util.ArrayList)11 SystemException (org.mifos.framework.exceptions.SystemException)11 QuestionEntity (org.mifos.platform.questionnaire.domain.QuestionEntity)9 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)8 ValidationException (org.mifos.platform.validations.ValidationException)5 QuestionForm (org.mifos.platform.questionnaire.ui.model.QuestionForm)4 Matchers.anyString (org.mockito.Matchers.anyString)4 QuestionChoiceEntity (org.mifos.platform.questionnaire.domain.QuestionChoiceEntity)3 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)3 BadNumericResponseException (org.mifos.platform.questionnaire.exceptions.BadNumericResponseException)3 QuestionChoicesMatcher (org.mifos.platform.questionnaire.matchers.QuestionChoicesMatcher)3 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)3 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)3 QuestionGroupDetails (org.mifos.platform.questionnaire.service.QuestionGroupDetails)2