use of org.mifos.platform.validations.ValidationException 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.validations.ValidationException in project head by mifos.
the class QuestionGroupControllerTest method testSaveQuestionnaireFailureForNumericResponseGreaterThanMaxBound.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testSaveQuestionnaireFailureForNumericResponseGreaterThanMaxBound() {
ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
validationException.addChildException(new BadNumericResponseException("q1", null, 100));
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.invalid.numeric.max.response")));
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionGroupControllerTest method testSaveQuestionnaireFailureForNumericResponseLessThanMinBound.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testSaveQuestionnaireFailureForNumericResponseLessThanMinBound() {
ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
validationException.addChildException(new BadNumericResponseException("q1", 10, null));
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.invalid.numeric.min.response")));
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingSections.
@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingSections() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.setSections(Collections.<SectionDto>emptyList());
try {
questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
fail("Should have thrown validationException");
} catch (ValidationException e) {
assertThat(e.getKey(), is(GENERIC_VALIDATION));
assertThat(e.hasChildExceptions(), is(true));
List<ValidationException> childExceptions = e.getChildExceptions();
assertThat(childExceptions, is(notNullValue()));
assertThat(childExceptions.size(), is(1));
assertThat(childExceptions.get(0).getKey(), is(QUESTION_GROUP_SECTION_NOT_PROVIDED));
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingQuestionOrder.
@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingQuestionOrder() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).getQuestions().get(0).setOrder(null);
try {
questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
fail("Should have thrown validationException");
} catch (ValidationException e) {
assertThat(e.getKey(), is(GENERIC_VALIDATION));
assertThat(e.hasChildExceptions(), is(true));
List<ValidationException> childExceptions = e.getChildExceptions();
assertThat(childExceptions, is(notNullValue()));
assertThat(childExceptions.size(), is(1));
assertThat(childExceptions.get(0).getKey(), is(QUESTION_ORDER_NOT_PROVIDED));
}
}
Aggregations