use of org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException in project head by mifos.
the class QuestionnaireFlowAdapter method validateResponses.
public ActionErrors validateResponses(HttpServletRequest request, QuestionResponseCapturer form) {
List<QuestionGroupDetail> groups = form.getQuestionGroups();
QuestionnaireServiceFacade questionnaireServiceFacade = serviceLocator.getService(request);
if ((groups == null) || (questionnaireServiceFacade == null)) {
return null;
}
ActionErrors errors = new ActionErrors();
try {
questionnaireServiceFacade.validateResponses(groups);
} catch (ValidationException e) {
if (e.hasChildExceptions()) {
for (ValidationException ve : e.getChildExceptions()) {
if (ve instanceof MandatoryAnswerNotFoundException) {
errors.add(ClientConstants.ERROR_REQUIRED, new ActionMessage(ClientConstants.ERROR_REQUIRED, ve.getIdentifier()));
} else if (ve instanceof BadNumericResponseException) {
populateNumericError((BadNumericResponseException) ve, errors);
}
}
}
}
setQuestionnaireAttributesToRequest(request, form);
return errors;
}
use of org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException in project head by mifos.
the class QuestionnaireServiceFacadeTest method testValidateResponse.
@Test
public void testValidateResponse() {
List<QuestionDetail> questionDetails = asList(new QuestionDetail(12, "Question 1", QuestionType.FREETEXT, true, true));
List<SectionDetail> sectionDetails = asList(getSectionDetailWithQuestions("Sec1", questionDetails, null, true));
QuestionGroupDetail questionGroupDetail = new QuestionGroupDetail(1, "QG1", Arrays.asList(new EventSourceDto("Create", "Client", null)), sectionDetails, true);
try {
Mockito.doThrow(new MandatoryAnswerNotFoundException("Title")).when(questionnaireService).validateResponses(asList(questionGroupDetail));
questionnaireServiceFacade.validateResponses(asList(questionGroupDetail));
Assert.fail("Should not have thrown the validation exception");
} catch (ValidationException e) {
verify(questionnaireService, times(1)).validateResponses(asList(questionGroupDetail));
}
}
use of org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException 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());
}
}
use of org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException in project head by mifos.
the class QuestionGroupControllerTest method testSaveQuestionnaireFailure.
@Test
public void testSaveQuestionnaireFailure() {
ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
validationException.addChildException(new MandatoryAnswerNotFoundException("q1"));
doThrow(validationException).when(questionnaireServiceFacade).saveResponses(Mockito.<QuestionGroupDetails>any());
when(requestContext.getMessageContext()).thenReturn(messageContext);
String result = questionGroupController.saveQuestionnaire(getQuestionGroupDetails(), 1, requestContext);
assertThat(result, is("failure"));
verify(requestContext, times(1)).getMessageContext();
verify(messageContext).addMessage(argThat(new MessageMatcher("questionnaire.noresponse")));
}
use of org.mifos.platform.questionnaire.exceptions.MandatoryAnswerNotFoundException in project head by mifos.
the class ValidationExceptionMessageExtractorTest method testMandatoryAnswerNotFoundException.
@Test
public void testMandatoryAnswerNotFoundException() {
MandatoryAnswerNotFoundException e = new MandatoryAnswerNotFoundException("Title");
ValidationException parent = new ValidationException("Key");
parent.addChildException(e);
ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor();
extractor.extract(context, parent);
verify(context).addMessage(any(MessageResolver.class));
}
Aggregations