Search in sources :

Example 51 with QuestionGroupDetail

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

the class CreateSavingsAccountTest method testAnswerQuestionGroupStep_QuestionsAnswered.

@Test
public void testAnswerQuestionGroupStep_QuestionsAnswered() {
    List<QuestionGroupDetail> questionGroups = new ArrayList<QuestionGroupDetail>();
    doNothing().when(questionnaireServiceFacade).validateResponses(questionGroups);
    setCurrentState("answerQuestionGroupStep");
    MockExternalContext context = new MockExternalContext();
    context.setEventId("questionsAnswered");
    resumeFlow(context);
    assertCurrentStateEquals("previewStep");
}
Also used : MockExternalContext(org.springframework.webflow.test.MockExternalContext) QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 52 with QuestionGroupDetail

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

the class QuestionnaireValidatorTest method shouldNotThrowExceptionWhenANumericQuestionWithNoBoundsHasAnswer.

@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldNotThrowExceptionWhenANumericQuestionWithNoBoundsHasAnswer() {
    QuestionDetail questionDetail = getNumericQuestionDetail("Numeric Question", null, null);
    SectionDetail sectionWithOneQuestion = getSectionWithOneQuestion("Sec1", questionDetail, "121");
    QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client", asList(sectionWithOneQuestion));
    try {
        questionnaireValidator.validateForQuestionGroupResponses(asList(questionGroupDetail));
    } catch (ValidationException e) {
        fail("Should not have thrown the validation exception");
    }
}
Also used : 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 53 with QuestionGroupDetail

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

the class QuestionnaireValidatorTest method shouldThrowExceptionWhenAMandatoryQuestionHasNoAnswer.

@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
@Test
public void shouldThrowExceptionWhenAMandatoryQuestionHasNoAnswer() {
    QuestionGroupDetail questionGroupDetail = getQuestionGroupDetail(0, "Title", "Create", "Client");
    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 MandatoryAnswerNotFoundException);
        assertEquals("Q1", childException.getIdentifier());
    }
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) ValidationException(org.mifos.platform.validations.ValidationException) MandatoryAnswerNotFoundException(org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException) Test(org.junit.Test)

Example 54 with QuestionGroupDetail

use of org.mifos.platform.questionnaire.service.QuestionGroupDetail 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 55 with QuestionGroupDetail

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

the class QuestionGroupFormTest method shouldGetEventSourceId.

@Test
public void shouldGetEventSourceId() {
    EventSourceDto eventSourceDto = new EventSourceDto("Create", "Client", "Create Client");
    QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(123, "Title", Arrays.asList(eventSourceDto), new ArrayList<SectionDetail>(), false);
    QuestionGroupForm questionGroupForm = new QuestionGroupForm(questionGroupDetail);
    assertThat(questionGroupForm.getEventSourceIds().get(0), is("Create.Client"));
}
Also used : QuestionGroupDetail(org.mifos.platform.questionnaire.service.QuestionGroupDetail) QuestionGroupForm(org.mifos.platform.questionnaire.ui.model.QuestionGroupForm) SectionDetail(org.mifos.platform.questionnaire.service.SectionDetail) EventSourceDto(org.mifos.platform.questionnaire.service.dtos.EventSourceDto) Test(org.junit.Test)

Aggregations

QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)74 Test (org.junit.Test)43 SectionDetail (org.mifos.platform.questionnaire.service.SectionDetail)25 ArrayList (java.util.ArrayList)23 EventSourceDto (org.mifos.platform.questionnaire.service.dtos.EventSourceDto)15 QuestionGroup (org.mifos.platform.questionnaire.domain.QuestionGroup)11 SectionQuestionDetail (org.mifos.platform.questionnaire.service.SectionQuestionDetail)11 List (java.util.List)8 QuestionDetail (org.mifos.platform.questionnaire.service.QuestionDetail)8 ValidationException (org.mifos.platform.validations.ValidationException)7 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)6 QuestionGroupForm (org.mifos.platform.questionnaire.ui.model.QuestionGroupForm)6 SystemException (org.mifos.framework.exceptions.SystemException)5 Arrays.asList (java.util.Arrays.asList)4 QuestionGroupReference (org.mifos.accounts.productdefinition.business.QuestionGroupReference)4 LoanProductBuilder (org.mifos.domain.builders.LoanProductBuilder)4 EventSourceEntity (org.mifos.platform.questionnaire.domain.EventSourceEntity)4 SectionQuestion (org.mifos.platform.questionnaire.domain.SectionQuestion)4 Transactional (org.springframework.transaction.annotation.Transactional)4 HashMap (java.util.HashMap)3