Search in sources :

Example 46 with QuestionDetail

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

the class QuestionnaireValidatorTest method shouldThrowExceptionWhenQuestionTitleIsProvided.

@Test
public void shouldThrowExceptionWhenQuestionTitleIsProvided() {
    try {
        questionnaireValidator.validateForDefineQuestion(new QuestionDetail(null, QuestionType.FREETEXT));
        fail("Should have thrown the validation exception");
    } catch (SystemException e) {
        assertEquals(QUESTION_TEXT_NOT_PROVIDED, e.getKey());
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 47 with QuestionDetail

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

the class QuestionnaireValidatorTest method shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMinBoundGiven.

@Test
public void shouldNotThrowExceptionForNumericQuestionTypeWhenOnlyMinBoundGiven() {
    try {
        QuestionDetail questionDetail = new QuestionDetail("Title", QuestionType.NUMERIC);
        questionDetail.setNumericMin(10);
        questionnaireValidator.validateForDefineQuestion(questionDetail);
    } catch (SystemException e) {
        fail("Should not have thrown the exception");
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 48 with QuestionDetail

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

the class QuestionnaireValidatorTest method shouldThrowExceptionWhenANumericQuestionHasAnswerLessThanMin.

@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldThrowExceptionWhenANumericQuestionHasAnswerLessThanMin() {
    QuestionDetail questionDetail = getNumericQuestionDetail("Numeric Question", 10, null);
    SectionDetail sectionWithOneQuestion = getSectionWithOneQuestion("Sec1", questionDetail, "9");
    QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client", asList(sectionWithOneQuestion));
    try {
        questionnaireValidator.validateForQuestionGroupResponses(asList(questionGroupDetail));
        fail("Should have thrown the validation exception");
    } catch (ValidationException e) {
        assertEquals(GENERIC_VALIDATION, e.getKey());
        assertEquals(true, e.hasChildExceptions());
        assertEquals(1, e.getChildExceptions().size());
        ValidationException childException = e.getChildExceptions().get(0);
        assertTrue(childException instanceof BadNumericResponseException);
        assertEquals("Numeric Question", childException.getIdentifier());
        assertEquals(Integer.valueOf(10), ((BadNumericResponseException) childException).getAllowedMinValue());
        assertNull(((BadNumericResponseException) childException).getAllowedMaxValue());
    }
}
Also used : BadNumericResponseException(org.mifos.platform.questionnaire.exceptions.BadNumericResponseException) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ValidationException(org.mifos.platform.validations.ValidationException) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) SectionQuestionDetail(org.mifos.platform.questionnaire.service.SectionQuestionDetail) Test(org.junit.Test)

Example 49 with QuestionDetail

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

the class QuestionTest method testRemoveAnswerChoice.

@Test
public void testRemoveAnswerChoice() {
    Question question = new Question(new QuestionDetail());
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    question.setCurrentChoice("choice2");
    question.addAnswerChoice();
    question.setCurrentChoice("choice1");
    question.addAnswerChoice();
    assertEquals("choice1", question.getChoices().get(0).getValue());
    assertEquals("choice2", question.getChoices().get(1).getValue());
    assertEquals("choice1", question.getChoices().get(2).getValue());
    question.removeChoice(0);
    assertEquals("choice2", question.getChoices().get(0).getValue());
    assertEquals("choice1", question.getChoices().get(1).getValue());
    question.removeChoice(1);
    assertEquals("choice2", question.getChoices().get(0).getValue());
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

Example 50 with QuestionDetail

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

the class QuestionTest method testAddSmartChoice.

@Test
public void testAddSmartChoice() {
    Question question = new Question(new QuestionDetail());
    question.setCurrentSmartChoice("Choice1");
    question.addAnswerSmartChoice();
    assertThat(question.getCurrentSmartChoice(), is(nullValue()));
    assertThat(question.getCurrentSmartChoiceTags().size(), is(1));
    assertThat(question.getCurrentSmartChoiceTags().get(0), is(""));
    question.setCurrentSmartChoice("Choice2");
    question.addAnswerSmartChoice();
    assertThat(question.getCurrentSmartChoice(), is(nullValue()));
    assertThat(question.getCurrentSmartChoiceTags().size(), is(2));
    assertThat(question.getCurrentSmartChoiceTags().get(0), is(""));
    assertThat(question.getCurrentSmartChoiceTags().get(1), is(""));
}
Also used : Question(org.mifos.platform.questionnaire.ui.model.Question) QuestionDetail(org.mifos.platform.questionnaire.service.QuestionDetail) Test(org.junit.Test)

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