use of org.mifos.platform.questionnaire.exceptions.BadNumericResponseException 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());
}
}
use of org.mifos.platform.questionnaire.exceptions.BadNumericResponseException 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.questionnaire.exceptions.BadNumericResponseException 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.questionnaire.exceptions.BadNumericResponseException in project head by mifos.
the class QuestionGroupControllerTest method testSaveQuestionnaireFailureForNumericResponseNotWithinBounds.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Test
public void testSaveQuestionnaireFailureForNumericResponseNotWithinBounds() {
ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
validationException.addChildException(new BadNumericResponseException("q1", 10, 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.range.response")));
}
use of org.mifos.platform.questionnaire.exceptions.BadNumericResponseException in project head by mifos.
the class ValidationExceptionMessageExtractorTest method testBadNumericResponseExceptionUpperLowerBounds.
@Test
public void testBadNumericResponseExceptionUpperLowerBounds() {
BadNumericResponseException e = new BadNumericResponseException("Title", 0, 100);
testBadNumericResponseException(e, "questionnaire.invalid.numeric.range.response");
}
Aggregations