use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldNotValidateForValidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithSimilarChoices.
@Test
public void shouldNotValidateForValidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithSimilarChoices() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
String questionTitle = questionGroupDto.getSections().get(0).getQuestions().get(1).getText();
List<QuestionChoiceEntity> choices = asList(getChoice("Ch2"), getChoice("Ch3"), getChoice("cH1"));
when(questionDao.retrieveByText(questionTitle)).thenReturn(asList(getQuestionEntity(questionTitle, AnswerType.SINGLESELECT, choices)));
try {
questionnaireValidator.validateForDefineQuestionGroup(questionGroupDto);
} catch (ValidationException e) {
fail("Should not have thrown validationException");
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_QuestionGroupTitleExceedsMaxChars.
@Test
public void shouldValidateForInvalidQuestionGroupDto_QuestionGroupTitleExceedsMaxChars() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.setTitle("this is more than fifty characters string for question group title");
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_TITLE_TOO_BIG));
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class UploadQuestionGroupControllerTest method testUploadQuestionGroup_UploadFailureDuringValidation.
@Test
public void testUploadQuestionGroup_UploadFailureDuringValidation() {
when(requestContext.getMessageContext()).thenReturn(messageContext);
ValidationException validationException = new ValidationException(GENERIC_VALIDATION);
validationException.addChildException(new ValidationException(QUESTION_GROUP_TITLE_NOT_PROVIDED));
validationException.addChildException(new ValidationException(DUPLICATE_QUESTION_FOUND_IN_SECTION));
doThrow(validationException).when(questionnaireServiceFacade).uploadPPIQuestionGroup("INDIA");
UploadQuestionGroupForm form = new UploadQuestionGroupForm();
form.setSelectedCountry("INDIA");
String result = controller.upload(form, requestContext);
assertThat(result, is("failure"));
verify(requestContext).getMessageContext();
verify(messageContext).addMessage(argThat(new MessageMatcher(QUESTION_GROUP_TITLE_NOT_PROVIDED)));
verify(messageContext).addMessage(argThat(new MessageMatcher(DUPLICATE_QUESTION_FOUND_IN_SECTION)));
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingSectionOrder.
@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingSectionOrder() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().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(SECTION_ORDER_NOT_PROVIDED));
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_MissingQuestionsInSection.
@Test
public void shouldValidateForInvalidQuestionGroupDto_MissingQuestionsInSection() {
when(eventSourceDao.retrieveCountByEventAndSource("Create", "Client")).thenReturn(asList(1L));
QuestionGroupDto questionGroupDto = getQuestionGroupDto();
questionGroupDto.getSections().get(0).setQuestions(Collections.<QuestionDto>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(NO_QUESTIONS_FOUND_IN_SECTION));
}
}
Aggregations