use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class CreateSavingsAccountFormBeanTest method setUp.
@Before
public void setUp() {
MifosBeanValidator validator = new MifosBeanValidator();
LocalValidatorFactoryBean targetValidator = new LocalValidatorFactoryBean();
targetValidator.afterPropertiesSet();
validator.setTargetValidator(targetValidator);
formBean = new CreateSavingsAccountFormBean();
formBean.setValidator(validator);
questionnaireServiceFacade = mock(QuestionnaireServiceFacade.class);
formBean.setQuestionnaireServiceFascade(questionnaireServiceFacade);
configurationDto = new AccountingConfigurationDto();
configurationDto.setDigitsBeforeDecimal((short) 14);
configurationDto.setDigitsAfterDecimal((short) 1);
configurationServiceFacade = mock(ConfigurationServiceFacade.class);
when(configurationServiceFacade.getAccountingConfiguration()).thenReturn(configurationDto);
formBean.setConfigurationServiceFacade(configurationServiceFacade);
validationContext = new StubValidationContext();
validationException = new ValidationException("Root");
validationException.addChildException(new ValidationException("Child"));
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class ValidationExceptionMessageExtractorTest method testBadNumericResponseException.
private void testBadNumericResponseException(BadNumericResponseException e, String expectedMessage) {
ValidationException parent = new ValidationException("Key");
parent.addChildException(e);
ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor();
MessageContext context = new StubMessageContext();
extractor.extract(context, parent);
Message[] messages = context.getAllMessages();
Assert.assertEquals(1, messages.length);
Message m = messages[0];
Assert.assertEquals(expectedMessage, m.getText());
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class ValidationExceptionMessageExtractorTest method testValidationException.
@Test
public void testValidationException() {
ValidationException parent = new ValidationException("Key 1");
ValidationException child = new ValidationException("Key 2");
parent.addChildException(child);
ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor();
extractor.extract(context, parent);
verify(context).addMessage(any(MessageResolver.class));
}
use of org.mifos.platform.validations.ValidationException 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");
}
}
use of org.mifos.platform.validations.ValidationException in project head by mifos.
the class QuestionnaireValidatorForDtoTest method shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentChoices.
@Test
public void shouldValidateForInvalidQuestionGroupDto_ExistingQuestionTitle_SameQuestionType_WithDifferentChoices() {
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("Ch0"));
when(questionDao.retrieveByText(questionTitle)).thenReturn(asList(getQuestionEntity(questionTitle, AnswerType.SINGLESELECT, choices)));
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_TITILE_MATCHES_EXISTING_QUESTION));
}
}
Aggregations